Skip to content

Commit c7a1ce3

Browse files
dsaherndavem330
authored andcommitted
ipv6: Change addrconf_f6i_alloc to use ip6_route_info_create
Change addrconf_f6i_alloc to generate a fib6_config and call ip6_route_info_create. addrconf_f6i_alloc is the last caller to fib6_info_alloc besides ip6_route_info_create, and there is no reason for it to do its own initialization on a fib6_info. Host routes need to be created even if the device is down, so add a new flag, fc_ignore_dev_down, to fib6_config and update fib6_nh_init to not error out if device is not up. Notes on the conversion: - ip_fib_metrics_init is the same as fib6_config has fc_mx set to NULL and fc_mx_len set to 0 - dst_nocount is handled by the RTF_ADDRCONF flag - dst_host is handled by fc_dst_len = 128 nh_gw does not get set after the conversion to ip6_route_info_create but it should not be set in addrconf_f6i_alloc since this is a host route not a gateway route. Everything else is a straight forward map between fib6_info and fib6_config. Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 67f6951 commit c7a1ce3

File tree

2 files changed

+18
-27
lines changed

2 files changed

+18
-27
lines changed

include/net/ip6_fib.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ struct fib6_config {
5050
u32 fc_protocol;
5151
u16 fc_type; /* only 8 bits are used */
5252
u16 fc_delete_all_nh : 1,
53-
__unused : 15;
53+
fc_ignore_dev_down:1,
54+
__unused : 14;
5455

5556
struct in6_addr fc_dst;
5657
struct in6_addr fc_src;

net/ipv6/route.c

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3079,7 +3079,7 @@ static struct fib6_info *ip6_route_info_create(struct fib6_config *cfg,
30793079
goto out;
30803080
}
30813081

3082-
if (!(dev->flags & IFF_UP)) {
3082+
if (!(dev->flags & IFF_UP) && !cfg->fc_ignore_dev_down) {
30833083
NL_SET_ERR_MSG(extack, "Nexthop device is not up");
30843084
err = -ENETDOWN;
30853085
goto out;
@@ -3712,36 +3712,26 @@ struct fib6_info *addrconf_f6i_alloc(struct net *net,
37123712
const struct in6_addr *addr,
37133713
bool anycast, gfp_t gfp_flags)
37143714
{
3715-
u32 tb_id;
3716-
struct net_device *dev = idev->dev;
3717-
struct fib6_info *f6i;
3718-
3719-
f6i = fib6_info_alloc(gfp_flags);
3720-
if (!f6i)
3721-
return ERR_PTR(-ENOMEM);
3715+
struct fib6_config cfg = {
3716+
.fc_table = l3mdev_fib_table(idev->dev) ? : RT6_TABLE_LOCAL,
3717+
.fc_ifindex = idev->dev->ifindex,
3718+
.fc_flags = RTF_UP | RTF_ADDRCONF | RTF_NONEXTHOP,
3719+
.fc_dst = *addr,
3720+
.fc_dst_len = 128,
3721+
.fc_protocol = RTPROT_KERNEL,
3722+
.fc_nlinfo.nl_net = net,
3723+
.fc_ignore_dev_down = true,
3724+
};
37223725

3723-
f6i->fib6_metrics = ip_fib_metrics_init(net, NULL, 0, NULL);
3724-
f6i->dst_nocount = true;
3725-
f6i->dst_host = true;
3726-
f6i->fib6_protocol = RTPROT_KERNEL;
3727-
f6i->fib6_flags = RTF_UP | RTF_NONEXTHOP;
37283726
if (anycast) {
3729-
f6i->fib6_type = RTN_ANYCAST;
3730-
f6i->fib6_flags |= RTF_ANYCAST;
3727+
cfg.fc_type = RTN_ANYCAST;
3728+
cfg.fc_flags |= RTF_ANYCAST;
37313729
} else {
3732-
f6i->fib6_type = RTN_LOCAL;
3733-
f6i->fib6_flags |= RTF_LOCAL;
3730+
cfg.fc_type = RTN_LOCAL;
3731+
cfg.fc_flags |= RTF_LOCAL;
37343732
}
37353733

3736-
f6i->fib6_nh.nh_gw = *addr;
3737-
dev_hold(dev);
3738-
f6i->fib6_nh.nh_dev = dev;
3739-
f6i->fib6_dst.addr = *addr;
3740-
f6i->fib6_dst.plen = 128;
3741-
tb_id = l3mdev_fib_table(idev->dev) ? : RT6_TABLE_LOCAL;
3742-
f6i->fib6_table = fib6_get_table(net, tb_id);
3743-
3744-
return f6i;
3734+
return ip6_route_info_create(&cfg, gfp_flags, NULL);
37453735
}
37463736

37473737
/* remove deleted ip from prefsrc entries */

0 commit comments

Comments
 (0)