ipv6: do not match device when remove source route
Subsystems (4)
PATCH v3 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
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
Ido notified that there is a commit 5a56a0b3a45d ("net: Don't delete routes in different VRFs") to not affect the route in different VRFs. So let's remove the rt dev checking and add an table id checking. Also remove the !rt-nh checking to clear the IPv6 routes that are using a nexthop object. This would be consistent with IPv4.
A ipv6_del_addr test is added for fib_tests.sh. Note that instead of removing the whole route for IPv4, IPv6 only remove the preferred source address for source routing. So in the testing use "grep -q src $src_ipv6_address" instead of "grep -q $dst_ipv6_subnet/64" when checking if the source route deleted.
Here is the fib_tests.sh ipv6_del_addr test result.
Before fix:
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 [FAIL]
TEST: Prefsrc removed in default VRF when source address deleted [ OK ]
TEST: Prefsrc in VRF is not removed by address delete [FAIL]
Identical FIB info with different table ID
TEST: Prefsrc removed from VRF when source address deleted [ OK ]
TEST: Prefsrc in default VRF not removed [FAIL]
TEST: Prefsrc removed in default VRF when source address deleted [ OK ]
TEST: Prefsrc in VRF is not removed by address delete [FAIL]
Table ID 0
TEST: Prefsrc removed in default VRF when source address deleted [ OK ]
After fix:
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 ]
---
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 | 6 +- tools/testing/selftests/net/fib_tests.sh | 93 +++++++++++++++++++++++- 2 files changed, 95 insertions(+), 4 deletions(-)
net/ipv6/route.c +3 -3
@@ -4590,10 +4590,10 @@ 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 && +if (rt != net->ipv6.fib6_null_entry && + rt->fib6_table->tb6_id == tb6_id &&ipv6_addr_equal (addr, &rt->fib6_prefsrc.addr)) {spin_lock_bh (&rt6_exception_lock);/* remove prefsrc entry */
tools/testing/selftests/net/fib_tests.sh +92 -1
111 lines not on this page · raw message
Signature · 1 line
2.38.1
Quoted 13 lines · Hangbin Liu
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):
[...]
Quoted 13 lines
Ido notified that there is a commit
5a56a0b3a45d("net: Don't delete routes in different VRFs") to not affect the route in different VRFs. So let's remove the rt dev checking and add an table id checking. Also remove the !rt-nh checking to clear the IPv6 routes that are using a nexthop object. This would be consistent with IPv4.A
ipv6_del_addrtest is added forfib_tests.sh. Note that instead of removing the whole route for IPv4, IPv6 only remove the preferred source address for source routing. So in the testing use "grep -q src $src_ipv6_address" instead of "grep -q $dst_ipv6_subnet/64" when checking if the source route deleted.Here is the
fib_tests.shipv6_del_addrtest result.
[...]
Quoted 4 lines
Reported-by Thomas Haller <[email protected]>Fixes c3968a857a6b ("ipv6: RTA_PREFSRC support for ipv6 route source address selection")Signed-off-by Hangbin Liu <[email protected]>
One nit below
[...]
Quoted 6 lines
tools/testing/selftests/net/fib_tests.sh +2
-0@@ -1869,6 +1869,96 @@ ipv4_del_addr_test() cleanup } +ipv6_del_addr_test() +{
[...]
tools/testing/selftests/net/fib_tests.sh ipv4_del_addr_test() · line 1961
Quoted 3 lines
tools/testing/selftests/net/fib_tests.sh +2
-0+} +
Double blank line
Quoted 31 lines · Ido Schimmel
Quoted 13 lines · Hangbin Liu
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):
[...]
Quoted 6 lines
Ido notified that there is a commit
5a56a0b3a45d("net: Don't delete routes in different VRFs") to not affect the route in different VRFs. So let's remove the rt dev checking and add an table id checking. Also remove the !rt-nh checking to clear the IPv6 routes that are using a nexthop object. This would be consistent with IPv4.Quoted 7 lines
A
ipv6_del_addrtest is added forfib_tests.sh. Note that instead of removing the whole route for IPv4, IPv6 only remove the preferred source address for source routing. So in the testing use "grep -q src $src_ipv6_address" instead of "grep -q $dst_ipv6_subnet/64" when checking if the source route deleted.Here is the
fib_tests.shipv6_del_addrtest result.
Quoted 8 lines
[...]
Quoted 4 lines
Reported-by Thomas Haller <[email protected]>Fixes c3968a857a6b ("ipv6: RTA_PREFSRC support for ipv6 route source address selection")Signed-off-by Hangbin Liu <[email protected]>Reviewed-by Ido Schimmel <[email protected]>
Actually, there is another problem here. IPv4 checks that the address is indeed gone (it can be assigned to more than one interface):
+ ip link add name dummy1 up type dummy
+ ip link add name dummy2 up type dummy
+ ip link add name dummy3 up type dummy
+ ip address add 192.0.2.1/24 dev dummy1
+ ip address add 192.0.2.1/24 dev dummy2
+ ip route add 198.51.100.0/24 dev dummy3 src 192.0.2.1
+ ip address del 192.0.2.1/24 dev dummy2
+ ip -4 r s
192.0.2.0/24 dev dummy1 proto kernel scope link src 192.0.2.1 198.51.100.0/24 dev dummy3 scope link src 192.0.2.1
But it doesn't happen for IPv6:
+ ip link add name dummy1 up type dummy
+ ip link add name dummy2 up type dummy
+ ip link add name dummy3 up type dummy
+ ip address add 2001:db8:1::1/64 dev dummy1
+ ip address add 2001:db8:1::1/64 dev dummy2
+ ip route add 2001:db8:2::/64 dev dummy3 src 2001:db8:1::1
+ ip address del 2001:db8:1::1/64 dev dummy2
+ ip -6 r s
2001:db8:1::/64 dev dummy1 proto kernel metric 256 pref medium 2001:db8:2::/64 dev dummy3 metric 1024 pref medium fe80::/64 dev dummy1 proto kernel metric 256 pref medium fe80::/64 dev dummy2 proto kernel metric 256 pref medium fe80::/64 dev dummy3 proto kernel metric 256 pref medium
Hi Ido,
Quoted 16 lines · Ido Schimmel
Actually, there is another problem here. IPv4 checks that the address is indeed gone (it can be assigned to more than one interface):
+ ip link add name dummy1 up type dummy
+ ip link add name dummy2 up type dummy
+ ip link add name dummy3 up type dummy
+ ip address add 192.0.2.1/24 dev dummy1
+ ip address add 192.0.2.1/24 dev dummy2
+ ip route add 198.51.100.0/24 dev dummy3 src 192.0.2.1
+ ip address del 192.0.2.1/24 dev dummy2
+ ip -4 r s
192.0.2.0/24 dev dummy1 proto kernel scope link src 192.0.2.1 198.51.100.0/24 dev dummy3 scope link src 192.0.2.1But it doesn't happen for IPv6:
Quoted 13 lines
+ ip link add name dummy1 up type dummy
+ ip link add name dummy2 up type dummy
+ ip link add name dummy3 up type dummy
+ ip address add 2001:db8:1::1/64 dev dummy1
+ ip address add 2001:db8:1::1/64 dev dummy2
+ ip route add 2001:db8:2::/64 dev dummy3 src 2001:db8:1::1
+ ip address del 2001:db8:1::1/64 dev dummy2
+ ip -6 r s
2001:db8:1::/64 dev dummy1 proto kernel metric 256 pref medium 2001:db8:2::/64 dev dummy3 metric 1024 pref medium fe80::/64 dev dummy1 proto kernel metric 256 pref medium fe80::/64 dev dummy2 proto kernel metric 256 pref medium fe80::/64 dev dummy3 proto kernel metric 256 pref medium
Hmm, what kind of usage that need to add same address on different interfaces? BTW, to fix it, how about check if the IPv6 addr still exist. e.g.
net/ipv6/route.c +4 -3
@@ -4590,10 +4590,11 @@ 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 && +if (rt != net->ipv6.fib6_null_entry && + rt->fib6_table->tb6_id == tb6_id && + !ipv6_chk_addr_and_flags (net, addr,NULL , true,0 ,IFA_F_TENTATIVE ) &&ipv6_addr_equal (addr, &rt->fib6_prefsrc.addr)) {spin_lock_bh (&rt6_exception_lock);/* remove prefsrc entry */
Thanks
Hangbin
Quoted 33 lines · Hangbin Liu
Hi Ido,
Quoted 16 lines · Ido Schimmel
Actually, there is another problem here. IPv4 checks that the address is indeed gone (it can be assigned to more than one interface):
+ ip link add name dummy1 up type dummy
+ ip link add name dummy2 up type dummy
+ ip link add name dummy3 up type dummy
+ ip address add 192.0.2.1/24 dev dummy1
+ ip address add 192.0.2.1/24 dev dummy2
+ ip route add 198.51.100.0/24 dev dummy3 src 192.0.2.1
+ ip address del 192.0.2.1/24 dev dummy2
+ ip -4 r s
192.0.2.0/24 dev dummy1 proto kernel scope link src 192.0.2.1 198.51.100.0/24 dev dummy3 scope link src 192.0.2.1But it doesn't happen for IPv6:
Quoted 13 lines
+ ip link add name dummy1 up type dummy
+ ip link add name dummy2 up type dummy
+ ip link add name dummy3 up type dummy
+ ip address add 2001:db8:1::1/64 dev dummy1
+ ip address add 2001:db8:1::1/64 dev dummy2
+ ip route add 2001:db8:2::/64 dev dummy3 src 2001:db8:1::1
+ ip address del 2001:db8:1::1/64 dev dummy2
+ ip -6 r s
2001:db8:1::/64 dev dummy1 proto kernel metric 256 pref medium 2001:db8:2::/64 dev dummy3 metric 1024 pref medium fe80::/64 dev dummy1 proto kernel metric 256 pref medium fe80::/64 dev dummy2 proto kernel metric 256 pref medium fe80::/64 dev dummy3 proto kernel metric 256 pref medium
Quoted 1 line
Hmm, what kind of usage that need to add same address on different interfaces?
I don't know, but when I checked the code and tested it I noticed that the kernel doesn't care on which interface the address is configured. Therefore, in order for deletion to be consistent with addition and with IPv4, the preferred source address shouldn't be removed from routes in the VRF table as long as the address is configured on one of the interfaces in the VRF.
Quoted 7 lines
BTW, to fix it, how about check if the IPv6 addr still exist. e.g.
net/ipv6/route.c +0
-0@@ -4590,10 +4590,11 @@ 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;
net/ipv6/route.c static int fib6_remove_prefsrc(struct fib6_info *rt, void *arg) · line 4598
Quoted 10 lines
net/ipv6/route.c +4
-3struct 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 && +if (rt != net->ipv6.fib6_null_entry && + rt->fib6_table->tb6_id == tb6_id && + !ipv6_chk_addr_and_flags (net, addr,NULL , true,0 ,IFA_F_TENTATIVE ) &&ipv6_addr_equal (addr, &rt->fib6_prefsrc.addr)) {
ipv6_chk_addr_and_flags() is more expensive than ipv6_addr_equal() so better to first check that route indeed uses the address as the preferred source address and only then check if it exists.
Maybe you can even do it in rt6_remove_prefsrc(). That would be similar to what IPv4 is doing.
Quoted 5 lines
net/ipv6/route.c +0
-0spin_lock_bh (&rt6_exception_lock);/* remove prefsrc entry */ Thanks
Hangbin
David Ahern
maintainerQuoted 8 lines · Ido Schimmel
I don't know, but when I checked the code and tested it I noticed that the kernel doesn't care on which interface the address is configured. Therefore, in order for deletion to be consistent with addition and with IPv4, the preferred source address shouldn't be removed from routes in the VRF table as long as the address is configured on one of the interfaces in the VRF.
Deleting routes associated with device 2 when an address is deleted from device 1 is going to introduce as many problems as it solves. The VRF use case is one example.
Quoted 10 lines · David Ahern
Quoted 8 lines · Ido Schimmel
I don't know, but when I checked the code and tested it I noticed that the kernel doesn't care on which interface the address is configured. Therefore, in order for deletion to be consistent with addition and with IPv4, the preferred source address shouldn't be removed from routes in the VRF table as long as the address is configured on one of the interfaces in the VRF.
Quoted 3 lines
Deleting routes associated with device 2 when an address is deleted from device 1 is going to introduce as many problems as it solves. The VRF use case is one example.
This already happens in IPv4:
# ip link add name dummy1 up type dummy # ip link add name dummy2 up type dummy # ip address add 192.0.2.1/24 dev dummy1 # ip route add 198.51.100.0/24 dev dummy2 src 192.0.2.1 # ip -4 r s 192.0.2.0/24 dev dummy1 proto kernel scope link src 192.0.2.1 198.51.100.0/24 dev dummy2 scope link src 192.0.2.1 # ip address del 192.0.2.1/24 dev dummy1 # ip -4 r s
IPv6 only removes the preferred source address from routes, but doesn't delete them. The patch doesn't change that.
Another difference from IPv4 is that IPv6 only removes the preferred source address from routes whose first nexthop device matches the device from which the address was removed:
# ip link add name dummy1 up type dummy # ip link add name dummy2 up type dummy # ip address add 2001:db8:1::1/64 dev dummy1 # ip route add 2001:db8:2::/64 dev dummy2 src 2001:db8:1::1 # ip -6 r s 2001:db8:1::/64 dev dummy1 proto kernel metric 256 pref medium 2001:db8:2::/64 dev dummy2 src 2001:db8:1::1 metric 1024 pref medium fe80::/64 dev dummy1 proto kernel metric 256 pref medium fe80::/64 dev dummy2 proto kernel metric 256 pref medium # ip address del 2001:db8:1::1/64 dev dummy1 # ip -6 r s 2001:db8:2::/64 dev dummy2 src 2001:db8:1::1 metric 1024 pref medium fe80::/64 dev dummy1 proto kernel metric 256 pref medium fe80::/64 dev dummy2 proto kernel metric 256 pref medium
And this is despite the fact that the kernel only allowed the route to be programmed because the preferred source address was present on another interface in the same L3 domain / VRF:
# ip link add name dummy1 up type dummy # ip link add name dummy2 up type dummy # ip route add 2001:db8:2::/64 dev dummy2 src 2001:db8:1::1 Error: Invalid source address.
The intent of the patch (at least with the changes I proposed) is to remove the preferred source address from routes in a VRF when the address is no longer configured on any interface in the VRF.
Note that the above is true for addresses with a global scope. The removal of a link-local address from a device should not affect other devices. This restriction also applies when a route is added:
# ip link add name dummy1 up type dummy # ip link add name dummy2 up type dummy # ip -6 address add fe80::1/64 dev dummy1 # ip -6 route add 2001:db8:2::/64 dev dummy2 src fe80::1 Error: Invalid source address. # ip -6 address add fe80::1/64 dev dummy2 # ip -6 route add 2001:db8:2::/64 dev dummy2 src fe80::1
David Ahern
maintainerQuoted 66 lines · Ido Schimmel
Quoted 10 lines · David Ahern
Quoted 8 lines · Ido Schimmel
I don't know, but when I checked the code and tested it I noticed that the kernel doesn't care on which interface the address is configured. Therefore, in order for deletion to be consistent with addition and with IPv4, the preferred source address shouldn't be removed from routes in the VRF table as long as the address is configured on one of the interfaces in the VRF.
Quoted 3 lines
Deleting routes associated with device 2 when an address is deleted from device 1 is going to introduce as many problems as it solves. The VRF use case is one example.
This already happens in IPv4:
# ip link add name dummy1 up type dummy # ip link add name dummy2 up type dummy # ip address add 192.0.2.1/24 dev dummy1 # ip route add 198.51.100.0/24 dev dummy2 src 192.0.2.1 # ip -4 r s 192.0.2.0/24 dev dummy1 proto kernel scope link src 192.0.2.1 198.51.100.0/24 dev dummy2 scope link src 192.0.2.1 # ip address del 192.0.2.1/24 dev dummy1 # ip -4 r sIPv6 only removes the preferred source address from routes, but doesn't delete them. The patch doesn't change that.
Another difference from IPv4 is that IPv6 only removes the preferred source address from routes whose first nexthop device matches the device from which the address was removed:
# ip link add name dummy1 up type dummy # ip link add name dummy2 up type dummy # ip address add 2001:db8:1::1/64 dev dummy1 # ip route add 2001:db8:2::/64 dev dummy2 src 2001:db8:1::1 # ip -6 r s 2001:db8:1::/64 dev dummy1 proto kernel metric 256 pref medium 2001:db8:2::/64 dev dummy2 src 2001:db8:1::1 metric 1024 pref medium fe80::/64 dev dummy1 proto kernel metric 256 pref medium fe80::/64 dev dummy2 proto kernel metric 256 pref medium # ip address del 2001:db8:1::1/64 dev dummy1 # ip -6 r s 2001:db8:2::/64 dev dummy2 src 2001:db8:1::1 metric 1024 pref medium fe80::/64 dev dummy1 proto kernel metric 256 pref medium fe80::/64 dev dummy2 proto kernel metric 256 pref mediumAnd this is despite the fact that the kernel only allowed the route to be programmed because the preferred source address was present on another interface in the same L3 domain / VRF:
# ip link add name dummy1 up type dummy # ip link add name dummy2 up type dummy # ip route add 2001:db8:2::/64 dev dummy2 src 2001:db8:1::1 Error: Invalid source address.The intent of the patch (at least with the changes I proposed) is to remove the preferred source address from routes in a VRF when the address is no longer configured on any interface in the VRF.
Note that the above is true for addresses with a global scope. The removal of a link-local address from a device should not affect other devices. This restriction also applies when a route is added:
Quoted 7 lines
# ip link add name dummy1 up type dummy # ip link add name dummy2 up type dummy # ip -6 address add fe80::1/64 dev dummy1 # ip -6 route add 2001:db8:2::/64 dev dummy2 src fe80::1 Error: Invalid source address. # ip -6 address add fe80::1/64 dev dummy2 # ip -6 route add 2001:db8:2::/64 dev dummy2 src fe80::1
Lot of permutations. It would be good to get these in a test script along with other variations - e.g.,
# 2 devices with the same source address
ip link add name dummy1 up type dummy
ip link add name dummy2 up type dummy
ip link add name dummy3 up type dummy
ip address add 192.0.2.1/24 dev dummy1
ip address add 192.0.2.1/24 dev dummy3
ip route add 198.51.100.0/24 dev dummy2 src 192.0.2.1 ip address del 192.0.2.1/24 dev dummy1
--> src route should stay
# VRF with single device using src address
ip li add name red up type vrf table 123
ip link add name dummy4 up type dummy vrf red ip link add name dummy5 up type dummy vrf red ip address add 192.0.2.1/24 dev dummy4
ip route add 198.51.100.0/24 dev dummy5 src 192.0.2.1 ip address del 192.0.2.1/24 dev dummy4
ip ro ls vrf red
# VRF with two devices using src address
ip li add name red up type vrf table 123
ip link add name dummy4 up vrf red type dummy
ip link add name dummy5 up vrf red type dummy
ip link add name dummy6 up vrf red type dummy
ip address add 192.0.2.1/24 dev dummy4
ip address add 192.0.2.1/24 dev dummy6
ip route add 198.51.100.0/24 dev dummy5 src 192.0.2.1 vrf red ip address del 192.0.2.1/24 dev dummy4
I can not find my notes but I recall Donald raised a ticket at Cumulus when FRR tripped over a scenario like this or a related one (something about routes and address delete). CC'ed Donald in case he recalls the details
Quoted 81 lines · David Ahern
Quoted 51 lines
This already happens in IPv4:
# ip link add name dummy1 up type dummy # ip link add name dummy2 up type dummy # ip address add 192.0.2.1/24 dev dummy1 # ip route add 198.51.100.0/24 dev dummy2 src 192.0.2.1 # ip -4 r s 192.0.2.0/24 dev dummy1 proto kernel scope link src 192.0.2.1 198.51.100.0/24 dev dummy2 scope link src 192.0.2.1 # ip address del 192.0.2.1/24 dev dummy1 # ip -4 r sIPv6 only removes the preferred source address from routes, but doesn't delete them. The patch doesn't change that.
Another difference from IPv4 is that IPv6 only removes the preferred source address from routes whose first nexthop device matches the device from which the address was removed:
# ip link add name dummy1 up type dummy # ip link add name dummy2 up type dummy # ip address add 2001:db8:1::1/64 dev dummy1 # ip route add 2001:db8:2::/64 dev dummy2 src 2001:db8:1::1 # ip -6 r s 2001:db8:1::/64 dev dummy1 proto kernel metric 256 pref medium 2001:db8:2::/64 dev dummy2 src 2001:db8:1::1 metric 1024 pref medium fe80::/64 dev dummy1 proto kernel metric 256 pref medium fe80::/64 dev dummy2 proto kernel metric 256 pref medium # ip address del 2001:db8:1::1/64 dev dummy1 # ip -6 r s 2001:db8:2::/64 dev dummy2 src 2001:db8:1::1 metric 1024 pref medium fe80::/64 dev dummy1 proto kernel metric 256 pref medium fe80::/64 dev dummy2 proto kernel metric 256 pref mediumAnd this is despite the fact that the kernel only allowed the route to be programmed because the preferred source address was present on another interface in the same L3 domain / VRF:
# ip link add name dummy1 up type dummy # ip link add name dummy2 up type dummy # ip route add 2001:db8:2::/64 dev dummy2 src 2001:db8:1::1 Error: Invalid source address.The intent of the patch (at least with the changes I proposed) is to remove the preferred source address from routes in a VRF when the address is no longer configured on any interface in the VRF.
Note that the above is true for addresses with a global scope. The removal of a link-local address from a device should not affect other devices. This restriction also applies when a route is added:
Quoted 7 lines
# ip link add name dummy1 up type dummy # ip link add name dummy2 up type dummy # ip -6 address add fe80::1/64 dev dummy1 # ip -6 route add 2001:db8:2::/64 dev dummy2 src fe80::1 Error: Invalid source address. # ip -6 address add fe80::1/64 dev dummy2 # ip -6 route add 2001:db8:2::/64 dev dummy2 src fe80::1Lot of permutations. It would be good to get these in a test script along with other variations - e.g.,
# 2 devices with the same source address
ip link add name dummy1 up type dummy
ip link add name dummy2 up type dummy
ip link add name dummy3 up type dummy
ip address add 192.0.2.1/24 dev dummy1
ip address add 192.0.2.1/24 dev dummy3
ip route add 198.51.100.0/24 dev dummy2 src 192.0.2.1 ip address del 192.0.2.1/24 dev dummy1
--> src route should stay# VRF with single device using src address
ip li add name red up type vrf table 123
ip link add name dummy4 up type dummy vrf red ip link add name dummy5 up type dummy vrf red ip address add 192.0.2.1/24 dev dummy4
ip route add 198.51.100.0/24 dev dummy5 src 192.0.2.1 ip address del 192.0.2.1/24 dev dummy4
ip ro ls vrf red
Quoted 9 lines
# VRF with two devices using src address
ip li add name red up type vrf table 123
ip link add name dummy4 up vrf red type dummy
ip link add name dummy5 up vrf red type dummy
ip link add name dummy6 up vrf red type dummy
ip address add 192.0.2.1/24 dev dummy4
ip address add 192.0.2.1/24 dev dummy6
ip route add 198.51.100.0/24 dev dummy5 src 192.0.2.1 vrf red ip address del 192.0.2.1/24 dev dummy4
I can add these to fib_tests later.
Hangbin
Quoted 10 lines · Ido Schimmel
Quoted 10 lines
BTW, to fix it, how about check if the IPv6 addr still exist. e.g.
net/ipv6/route.c +1
-0@@ -4590,10 +4590,11 @@ 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 11 lines
net/ipv6/route.c static int fib6_remove_prefsrc(struct fib6_info *rt, void *arg) · line 4598
Quoted 7 lines
net/ipv6/route.c +3
-3-if (!rt->nh && - ((void *)rt->fib6_nh->fib_nh_dev == dev || !dev) && - rt != net->ipv6.fib6_null_entry && +if (rt != net->ipv6.fib6_null_entry && + rt->fib6_table->tb6_id == tb6_id && + !ipv6_chk_addr_and_flags (net, addr,NULL , true,0 ,IFA_F_TENTATIVE ) &&ipv6_addr_equal (addr, &rt->fib6_prefsrc.addr)) {
ipv6_chk_addr_and_flags()is more expensive thanipv6_addr_equal()so better to first check that route indeed uses the address as the preferred source address and only then check if it exists.
OK.
Quoted 3 lines
Maybe you can even do it in
rt6_remove_prefsrc(). That would be similar to what IPv4 is doing.
Do you mean call ipv6_chk_addr_and_flags() in rt6_remove_prefsrc()?
Thanks
Hangbin
Quoted 23 lines · Hangbin Liu
Quoted 10 lines · Ido Schimmel
Quoted 10 lines
BTW, to fix it, how about check if the IPv6 addr still exist. e.g.
net/ipv6/route.c +1
-0@@ -4590,10 +4590,11 @@ 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 11 lines
net/ipv6/route.c static int fib6_remove_prefsrc(struct fib6_info *rt, void *arg) · line 4598
Quoted 7 lines
net/ipv6/route.c +3
-3-if (!rt->nh && - ((void *)rt->fib6_nh->fib_nh_dev == dev || !dev) && - rt != net->ipv6.fib6_null_entry && +if (rt != net->ipv6.fib6_null_entry && + rt->fib6_table->tb6_id == tb6_id && + !ipv6_chk_addr_and_flags (net, addr,NULL , true,0 ,IFA_F_TENTATIVE ) &&ipv6_addr_equal (addr, &rt->fib6_prefsrc.addr)) {
ipv6_chk_addr_and_flags()is more expensive thanipv6_addr_equal()so better to first check that route indeed uses the address as the preferred source address and only then check if it exists.
Quoted 6 lines
OK.
Quoted 3 lines
Maybe you can even do it in
rt6_remove_prefsrc(). That would be similar to what IPv4 is doing.Do you mean call
ipv6_chk_addr_and_flags()inrt6_remove_prefsrc()?
Yes.