Skip to contentSkip to conversation

ipv6: do not match device when remove source route

PATCH Superseded Hangbin Liu 3 participants 5 messages Aug 11, 2023 – Aug 14, 2023

Subsystems (4)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 ipv6: do not match device when remove source route

After deleting an IPv6 address on an interface and cleaning up the related preferred source entries, it is important to ensure that all routes associated with the deleted address are properly cleared. The current implementation of rt6_remove_prefsrc() only checks the preferred source addresses bound to the current device. However, there may be routes that are bound to other devices but still utilize the same preferred source address.

To address this issue, it is necessary to also delete entries that are bound to other interfaces but share the same source address with the current device. Failure to delete these entries would leave routes that are bound to the deleted address unclear. Here is an example reproducer (I have omitted unrelated routes):

+ ip link add dummy1 type dummy
+ ip link add dummy2 type dummy
+ ip link set dummy1 up
+ ip link set dummy2 up
+ ip addr add 1:2:3:4::5/64 dev dummy1
+ ip route add 7:7:7:0::1 dev dummy1 src 1:2:3:4::5
+ ip route add 7:7:7:0::2 dev dummy2 src 1:2:3:4::5
+ ip -6 route show
1:2:3:4::/64 dev dummy1 proto kernel metric 256 pref medium 7:7:7::1 dev dummy1 src 1:2:3:4::5 metric 1024 pref medium 7:7:7::2 dev dummy2 src 1:2:3:4::5 metric 1024 pref medium
+ ip addr del 1:2:3:4::5/64 dev dummy1
+ ip -6 route show
7:7:7::1 dev dummy1 metric 1024 pref medium 7:7:7::2 dev dummy2 src 1:2:3:4::5 metric 1024 pref medium

Ido notified that there is a commit 5a56a0b3a45d ("net: Don't delete routes in different VRFs") to not affect the route in different VRFs. To fix all these issues. We will:
1. Remove the !rt-nh checking to clear the IPv6 routes that are using a nexthop object. This would be consistent with IPv4.
2. Remove the rt dev checking and add an table id checking to not remove the route in different VRFs.
3. Add a check to make sure not remove the src route if the address still exists on other device(in same VRF).

After fix:
+ ip addr del 1:2:3:4::5/64 dev dummy1
+ ip -6 route show
7:7:7::1 dev dummy1 metric 1024 pref medium
7:7:7::2 dev dummy2 metric 1024 pref medium

An ipv6_del_addr test is added in fib_tests.sh. Here is the result.

IPv6 delete address route tests
Regular FIB info
TEST: Prefsrc removed from VRF when source address deleted [ OK ]
TEST: Prefsrc in default VRF not removed [ OK ]
TEST: Prefsrc removed in default VRF when source address deleted [ OK ]
TEST: Prefsrc in VRF is not removed by address delete [ OK ]
Identical FIB info with different table ID
TEST: Prefsrc removed from VRF when source address deleted [ OK ]
TEST: Prefsrc in default VRF not removed [ OK ]
TEST: Prefsrc removed in default VRF when source address deleted [ OK ]
TEST: Prefsrc in VRF is not removed by address delete [ OK ]
Table ID 0
TEST: Prefsrc removed in default VRF when source address deleted [ OK ]
Identical address on different devices
TEST: Prefsrc not removed when src address exists on other device [ OK ]

Fixes c3968a857a6b ("ipv6: RTA_PREFSRC support for ipv6 route source address selection")

---
v5: Move the addr check back to fib6_remove_prefsrc.
v4: check if the prefsrc address still exists on other device
v3: remove rt nh checking. update the ipv6_del_addr test descriptions
v2: checking table id and update fib_test.sh

---
 net/ipv6/route.c                         |   9 +-
 tools/testing/selftests/net/fib_tests.sh | 117 ++++++++++++++++++++++-
 2 files changed, 121 insertions(+), 5 deletions(-)
net/ipv6/route.c +5 -4
index 64e873f5895f..0f981cc5bed1 100644
@@ -4590,11 +4590,12 @@ static int fib6_remove_prefsrc(struct fib6_info *rt, void *arg)
 	struct net_device *dev = ((struct arg_dev_net_ip *)arg)->dev;
 	struct net *net = ((struct arg_dev_net_ip *)arg)->net;
 	struct in6_addr *addr = ((struct arg_dev_net_ip *)arg)->addr;
+	u32 tb6_id = l3mdev_fib_table(dev) ? : RT_TABLE_MAIN;
 
-	if (!rt->nh &&
-	    ((void *)rt->fib6_nh->fib_nh_dev == dev || !dev) &&
-	    rt != net->ipv6.fib6_null_entry &&
-	    ipv6_addr_equal(addr, &rt->fib6_prefsrc.addr)) {
+	if (rt != net->ipv6.fib6_null_entry &&
+	    rt->fib6_table->tb6_id == tb6_id &&
+	    ipv6_addr_equal(addr, &rt->fib6_prefsrc.addr) &&
+	    !ipv6_chk_addr(net, addr, rt->fib6_nh->fib_nh_dev, 0)) {
 		spin_lock_bh(&rt6_exception_lock);
 		/* remove prefsrc entry */
 		rt->fib6_prefsrc.plen = 0;
tools/testing/selftests/net/fib_tests.sh +116 -1

157 lines not on this page · raw message

Signature · 1 line
2.38.1
#1 lore raw
Quoted 11 lines · Hangbin Liu
net/ipv6/route.c +1 -1
index 64e873f5895f..0f981cc5bed1 100644
@@ -4590,11 +4590,12 @@ static int fib6_remove_prefsrc(struct fib6_info *rt, void *arg)
 	struct net_device *dev = ((struct arg_dev_net_ip *)arg)->dev;
 	struct net *net = ((struct arg_dev_net_ip *)arg)->net;
 	struct in6_addr *addr = ((struct arg_dev_net_ip *)arg)->addr;
+	u32 tb6_id = l3mdev_fib_table(dev) ? : RT_TABLE_MAIN;
 
-	if (!rt->nh &&

net/ipv6/route.c static int fib6_remove_prefsrc(struct fib6_info *rt, void *arg) · line 4601

Quoted 10 lines
net/ipv6/route.c +4 -3
-	    ((void *)rt->fib6_nh->fib_nh_dev == dev || !dev) &&
-	    rt != net->ipv6.fib6_null_entry &&
-	    ipv6_addr_equal(addr, &rt->fib6_prefsrc.addr)) {
+	if (rt != net->ipv6.fib6_null_entry &&
+	    rt->fib6_table->tb6_id == tb6_id &&
+	    ipv6_addr_equal(addr, &rt->fib6_prefsrc.addr) &&
+	    !ipv6_chk_addr(net, addr, rt->fib6_nh->fib_nh_dev, 0)) {
 		spin_lock_bh(&rt6_exception_lock);
 		/* remove prefsrc entry */
 		rt->fib6_prefsrc.plen = 0;

The table check is incorrect which is what I was trying to explain here [1]. The route insertion code does not check that the preferred source is accessible from the VRF where the route is installed, but instead that it is accessible from the VRF of the first nexthop device. I'm not going to debate whether it is correct or not. I'm going to say that the logic should be consistent between the route insertion and deletion paths. That is, if I'm only able to insert a route with a preferred source address because some address exists, then when this address is removed the preferred source address should be removed from the route.

Here is an example with your patch applied:

+ ip link add name dummy1 up type dummy
+ ip link add name vrf1 up type vrf table 1111
+ ip link set dev dummy1 master vrf1
+ ip -6 route add 2001:db8:2::/64 src 2001:db8:1::1 dev dummy1
Error: Invalid source address.
+ ip address add 2001:db8:1::1/64 dev dummy1
+ ip -6 route add 2001:db8:2::/64 src 2001:db8:1::1 dev dummy1
+ ip -6 route show 2001:db8:2::/64
2001:db8:2::/64 dev dummy1 src 2001:db8:1::1 metric 1024 pref medium
+ ip address del 2001:db8:1::1/64 dev dummy1
+ ip -6 route show 2001:db8:2::/64
2001:db8:2::/64 dev dummy1 src 2001:db8:1::1 metric 1024 pref medium

Note how it is not possible to add the route to the main table because the address does not exist, but then after the address is deleted the route still exists with the preferred source address.

And this is the same example, but with the patch from [1]:

+ ip link add name dummy1 up type dummy
+ ip link add name vrf1 up type vrf table 1111
+ ip link set dev dummy1 master vrf1
+ ip -6 route add 2001:db8:2::/64 src 2001:db8:1::1 dev dummy1
Error: Invalid source address.
+ ip address add 2001:db8:1::1/64 dev dummy1
+ ip -6 route add 2001:db8:2::/64 src 2001:db8:1::1 dev dummy1
+ ip -6 route show 2001:db8:2::/64
2001:db8:2::/64 dev dummy1 src 2001:db8:1::1 metric 1024 pref medium
+ ip address del 2001:db8:1::1/64 dev dummy1
+ ip -6 route show 2001:db8:2::/64
2001:db8:2::/64 dev dummy1 metric 1024 pref medium

[1] https://lore.kernel.org/netdev/ZNSol%2F7x5oI6amEB@shredder/

#2 lore raw

Hi Ido,

Quoted 11 lines · Ido Schimmel
Quoted 10 lines · Hangbin Liu
net/ipv6/route.c +1 -0
index 64e873f5895f..0f981cc5bed1 100644
@@ -4590,11 +4590,12 @@ static int fib6_remove_prefsrc(struct fib6_info *rt, void *arg)
 	struct net_device *dev = ((struct arg_dev_net_ip *)arg)->dev;
 	struct net *net = ((struct arg_dev_net_ip *)arg)->net;
 	struct in6_addr *addr = ((struct arg_dev_net_ip *)arg)->addr;
+	u32 tb6_id = l3mdev_fib_table(dev) ? : RT_TABLE_MAIN;
 
Quoted 16 lines

net/ipv6/route.c static int fib6_remove_prefsrc(struct fib6_info *rt, void *arg) · line 4601

Quoted 11 lines
net/ipv6/route.c +4 -4
-	if (!rt->nh &&
-	    ((void *)rt->fib6_nh->fib_nh_dev == dev || !dev) &&
-	    rt != net->ipv6.fib6_null_entry &&
-	    ipv6_addr_equal(addr, &rt->fib6_prefsrc.addr)) {
+	if (rt != net->ipv6.fib6_null_entry &&
+	    rt->fib6_table->tb6_id == tb6_id &&
+	    ipv6_addr_equal(addr, &rt->fib6_prefsrc.addr) &&
+	    !ipv6_chk_addr(net, addr, rt->fib6_nh->fib_nh_dev, 0)) {
 		spin_lock_bh(&rt6_exception_lock);
 		/* remove prefsrc entry */
 		rt->fib6_prefsrc.plen = 0;

The table check is incorrect which is what I was trying to explain here [1]. The route insertion code does not check that the preferred source is accessible from the VRF where the route is installed, but instead that it is accessible from the VRF of the first nexthop device. I'm not

Sorry for my bad understanding and thanks a lot for your patient response!

Now I finally get what you mean of "In IPv6, the preferred source address is looked up in the same VRF as the first nexthop device." Which is not same with the IPv4 commit f96a3d74554d ipv4: Fix incorrect route flushing when source address is deleted

I will remove the tb id checking in next version. Another thing to confirm. We need remove the "!rt->nh" checking, right. Because I saw you kept it in you reply.

Thanks and Best regards
Hangbin

maintainer
#3 lore raw
Quoted 32 lines · Hangbin Liu

Hi Ido,

Quoted 11 lines · Ido Schimmel
Quoted 10 lines · Hangbin Liu
net/ipv6/route.c +1 -0
index 64e873f5895f..0f981cc5bed1 100644
@@ -4590,11 +4590,12 @@ static int fib6_remove_prefsrc(struct fib6_info *rt, void *arg)
 	struct net_device *dev = ((struct arg_dev_net_ip *)arg)->dev;
 	struct net *net = ((struct arg_dev_net_ip *)arg)->net;
 	struct in6_addr *addr = ((struct arg_dev_net_ip *)arg)->addr;
+	u32 tb6_id = l3mdev_fib_table(dev) ? : RT_TABLE_MAIN;
 
Quoted 16 lines

net/ipv6/route.c static int fib6_remove_prefsrc(struct fib6_info *rt, void *arg) · line 4601

Quoted 11 lines
net/ipv6/route.c +4 -4
-	if (!rt->nh &&
-	    ((void *)rt->fib6_nh->fib_nh_dev == dev || !dev) &&
-	    rt != net->ipv6.fib6_null_entry &&
-	    ipv6_addr_equal(addr, &rt->fib6_prefsrc.addr)) {
+	if (rt != net->ipv6.fib6_null_entry &&
+	    rt->fib6_table->tb6_id == tb6_id &&
+	    ipv6_addr_equal(addr, &rt->fib6_prefsrc.addr) &&
+	    !ipv6_chk_addr(net, addr, rt->fib6_nh->fib_nh_dev, 0)) {
 		spin_lock_bh(&rt6_exception_lock);
 		/* remove prefsrc entry */
 		rt->fib6_prefsrc.plen = 0;

The table check is incorrect which is what I was trying to explain here [1]. The route insertion code does not check that the preferred source is accessible from the VRF where the route is installed, but instead that it is accessible from the VRF of the first nexthop device. I'm not

Sorry for my bad understanding and thanks a lot for your patient response!

Quoted 9 lines

Now I finally get what you mean of "In IPv6, the preferred source address is looked up in the same VRF as the first nexthop device." Which is not same with the IPv4 commit f96a3d74554d ipv4: Fix incorrect route flushing when source address is deleted

I will remove the tb id checking in next version. Another thing to confirm. We need remove the "!rt->nh" checking, right. Because I saw you kept it in you reply.

Make sure Ido's test cases for the various cases are added to the test scripts. Lot of permutations here and we do not want to regress

#4 lore raw
In reply to Hangbin Liu
Quoted 3 lines · Hangbin Liu

I will remove the tb id checking in next version. Another thing to confirm. We need remove the "!rt->nh" checking, right. Because I saw you kept it in you reply.

My understanding is that when the route uses a nexthop object (i.e., rt->nh is not NULL), then rt->fib6_nh is invalid. So I think we need the check for now. Maybe it can be removed once the function learns to use nexthop_fib6_nh() for routes with a nexthop object, but that's another patch. Let's finish with the current problem first.