Skip to content

Commit bb48727

Browse files
xu xinkuba-moo
authored andcommitted
net/ipv6: Fix route deleting failure when metric equals 0
Problem ========= After commit 67f6951 ("ipv6: Move setting default metric for routes"), we noticed that the logic of assigning the default value of fc_metirc changed in the ioctl process. That is, when users use ioctl(fd, SIOCADDRT, rt) with a non-zero metric to add a route, then they may fail to delete a route with passing in a metric value of 0 to the kernel by ioctl(fd, SIOCDELRT, rt). But iproute can succeed in deleting it. As a reference, when using iproute tools by netlink to delete routes with a metric parameter equals 0, like the command as follows: ip -6 route del fe80::/64 via fe81::5054:ff:fe11:3451 dev eth0 metric 0 the user can still succeed in deleting the route entry with the smallest metric. Root Reason =========== After commit 67f6951 ("ipv6: Move setting default metric for routes"), When ioctl() pass in SIOCDELRT with a zero metric, rtmsg_to_fib6_config() will set a defalut value (1024) to cfg->fc_metric in kernel, and in ip6_route_del() and the line 4074 at net/ipv3/route.c, it will check by if (cfg->fc_metric && cfg->fc_metric != rt->fib6_metric) continue; and the condition is true and skip the later procedure (deleting route) because cfg->fc_metric != rt->fib6_metric. But before that commit, cfg->fc_metric is still zero there, so the condition is false and it will do the following procedure (deleting). Solution ======== In order to keep a consistent behaviour across netlink() and ioctl(), we should allow to delete a route with a metric value of 0. So we only do the default setting of fc_metric in route adding. CC: [email protected] # 5.4+ Fixes: 67f6951 ("ipv6: Move setting default metric for routes") Co-developed-by: Fan Yu <[email protected]> Signed-off-by: Fan Yu <[email protected]> Signed-off-by: xu xin <[email protected]> Reviewed-by: David Ahern <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 988af27 commit bb48727

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

net/ipv6/route.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4445,7 +4445,7 @@ static void rtmsg_to_fib6_config(struct net *net,
44454445
.fc_table = l3mdev_fib_table_by_index(net, rtmsg->rtmsg_ifindex) ?
44464446
: RT6_TABLE_MAIN,
44474447
.fc_ifindex = rtmsg->rtmsg_ifindex,
4448-
.fc_metric = rtmsg->rtmsg_metric ? : IP6_RT_PRIO_USER,
4448+
.fc_metric = rtmsg->rtmsg_metric,
44494449
.fc_expires = rtmsg->rtmsg_info,
44504450
.fc_dst_len = rtmsg->rtmsg_dst_len,
44514451
.fc_src_len = rtmsg->rtmsg_src_len,
@@ -4475,6 +4475,9 @@ int ipv6_route_ioctl(struct net *net, unsigned int cmd, struct in6_rtmsg *rtmsg)
44754475
rtnl_lock();
44764476
switch (cmd) {
44774477
case SIOCADDRT:
4478+
/* Only do the default setting of fc_metric in route adding */
4479+
if (cfg.fc_metric == 0)
4480+
cfg.fc_metric = IP6_RT_PRIO_USER;
44784481
err = ip6_route_add(&cfg, GFP_KERNEL, NULL);
44794482
break;
44804483
case SIOCDELRT:

0 commit comments

Comments
 (0)