Skip to content

Commit 0ae8133

Browse files
David Aherndavem330
authored andcommitted
net: ipv6: Allow shorthand delete of all nexthops in multipath route
IPv4 allows multipath routes to be deleted using just the prefix and length. For example: $ ip ro ls vrf red unreachable default metric 8192 1.1.1.0/24 nexthop via 10.100.1.254 dev eth1 weight 1 nexthop via 10.11.200.2 dev eth11.200 weight 1 10.11.200.0/24 dev eth11.200 proto kernel scope link src 10.11.200.3 10.100.1.0/24 dev eth1 proto kernel scope link src 10.100.1.3 $ ip ro del 1.1.1.0/24 vrf red $ ip ro ls vrf red unreachable default metric 8192 10.11.200.0/24 dev eth11.200 proto kernel scope link src 10.11.200.3 10.100.1.0/24 dev eth1 proto kernel scope link src 10.100.1.3 The same notation does not work with IPv6 because of how multipath routes are implemented for IPv6. For IPv6 only the first nexthop of a multipath route is deleted if the request contains only a prefix and length. This leads to unnecessary complexity in userspace dealing with IPv6 multipath routes. This patch allows all nexthops to be deleted without specifying each one in the delete request. Internally, this is done by walking the sibling list of the route matching the specifications given (prefix, length, metric, protocol, etc). $ ip -6 ro ls vrf red 2001:db8:1::/120 dev eth1 proto kernel metric 256 pref medium 2001:db8:2::/120 dev eth2 proto kernel metric 256 pref medium 2001:db8:200::/120 via 2001:db8:1::2 dev eth1 metric 1024 pref medium 2001:db8:200::/120 via 2001:db8:2::2 dev eth2 metric 1024 pref medium ... $ ip -6 ro del vrf red 2001:db8:200::/120 $ ip -6 ro ls vrf red 2001:db8:1::/120 dev eth1 proto kernel metric 256 pref medium 2001:db8:2::/120 dev eth2 proto kernel metric 256 pref medium ... Because IPv6 allows individual nexthops to be deleted without deleting the entire route, the ip6_route_multipath_del and non-multipath code path (ip6_route_del) have to be discriminated so that all nexthops are only deleted for the latter case. This is done by making the existing fc_type in fib6_config a u16 and then adding a new u16 field with fc_delete_all_nh as the first bit. Suggested-by: Dinesh Dutt <[email protected]> Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4d6308a commit 0ae8133

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

include/net/ip6_fib.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ struct fib6_config {
3737
int fc_ifindex;
3838
u32 fc_flags;
3939
u32 fc_protocol;
40-
u32 fc_type; /* only 8 bits are used */
40+
u16 fc_type; /* only 8 bits are used */
41+
u16 fc_delete_all_nh : 1,
42+
__unused : 15;
4143

4244
struct in6_addr fc_dst;
4345
struct in6_addr fc_src;

net/ipv6/route.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,6 +2143,34 @@ int ip6_del_rt(struct rt6_info *rt)
21432143
return __ip6_del_rt(rt, &info);
21442144
}
21452145

2146+
static int __ip6_del_rt_siblings(struct rt6_info *rt, struct fib6_config *cfg)
2147+
{
2148+
struct nl_info *info = &cfg->fc_nlinfo;
2149+
struct fib6_table *table;
2150+
int err;
2151+
2152+
table = rt->rt6i_table;
2153+
write_lock_bh(&table->tb6_lock);
2154+
2155+
if (rt->rt6i_nsiblings && cfg->fc_delete_all_nh) {
2156+
struct rt6_info *sibling, *next_sibling;
2157+
2158+
list_for_each_entry_safe(sibling, next_sibling,
2159+
&rt->rt6i_siblings,
2160+
rt6i_siblings) {
2161+
err = fib6_del(sibling, info);
2162+
if (err)
2163+
goto out;
2164+
}
2165+
}
2166+
2167+
err = fib6_del(rt, info);
2168+
out:
2169+
write_unlock_bh(&table->tb6_lock);
2170+
ip6_rt_put(rt);
2171+
return err;
2172+
}
2173+
21462174
static int ip6_route_del(struct fib6_config *cfg)
21472175
{
21482176
struct fib6_table *table;
@@ -2179,7 +2207,11 @@ static int ip6_route_del(struct fib6_config *cfg)
21792207
dst_hold(&rt->dst);
21802208
read_unlock_bh(&table->tb6_lock);
21812209

2182-
return __ip6_del_rt(rt, &cfg->fc_nlinfo);
2210+
/* if gateway was specified only delete the one hop */
2211+
if (cfg->fc_flags & RTF_GATEWAY)
2212+
return __ip6_del_rt(rt, &cfg->fc_nlinfo);
2213+
2214+
return __ip6_del_rt_siblings(rt, cfg);
21832215
}
21842216
}
21852217
read_unlock_bh(&table->tb6_lock);
@@ -3142,8 +3174,10 @@ static int inet6_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh)
31423174

31433175
if (cfg.fc_mp)
31443176
return ip6_route_multipath_del(&cfg);
3145-
else
3177+
else {
3178+
cfg.fc_delete_all_nh = 1;
31463179
return ip6_route_del(&cfg);
3180+
}
31473181
}
31483182

31493183
static int inet6_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh)

0 commit comments

Comments
 (0)