Skip to content

Commit c0d9993

Browse files
idoschkuba-moo
authored andcommitted
ipv4: Fix incorrect route flushing when table ID 0 is used
Cited commit added the table ID to the FIB info structure, but did not properly initialize it when table ID 0 is used. This can lead to a route in the default VRF with a preferred source address not being flushed when the address is deleted. Consider the following example: # ip address add dev dummy1 192.0.2.1/28 # ip address add dev dummy1 192.0.2.17/28 # ip route add 198.51.100.0/24 via 192.0.2.2 src 192.0.2.17 metric 100 # ip route add table 0 198.51.100.0/24 via 192.0.2.2 src 192.0.2.17 metric 200 # ip route show 198.51.100.0/24 198.51.100.0/24 via 192.0.2.2 dev dummy1 src 192.0.2.17 metric 100 198.51.100.0/24 via 192.0.2.2 dev dummy1 src 192.0.2.17 metric 200 Both routes are installed in the default VRF, but they are using two different FIB info structures. One with a metric of 100 and table ID of 254 (main) and one with a metric of 200 and table ID of 0. Therefore, when the preferred source address is deleted from the default VRF, the second route is not flushed: # ip address del dev dummy1 192.0.2.17/28 # ip route show 198.51.100.0/24 198.51.100.0/24 via 192.0.2.2 dev dummy1 src 192.0.2.17 metric 200 Fix by storing a table ID of 254 instead of 0 in the route configuration structure. Add a test case that fails before the fix: # ./fib_tests.sh -t ipv4_del_addr IPv4 delete address route tests Regular FIB info TEST: Route removed from VRF when source address deleted [ OK ] TEST: Route in default VRF not removed [ OK ] TEST: Route removed in default VRF when source address deleted [ OK ] TEST: Route in VRF is not removed by address delete [ OK ] Identical FIB info with different table ID TEST: Route removed from VRF when source address deleted [ OK ] TEST: Route in default VRF not removed [ OK ] TEST: Route removed in default VRF when source address deleted [ OK ] TEST: Route in VRF is not removed by address delete [ OK ] Table ID 0 TEST: Route removed in default VRF when source address deleted [FAIL] Tests passed: 8 Tests failed: 1 And passes after: # ./fib_tests.sh -t ipv4_del_addr IPv4 delete address route tests Regular FIB info TEST: Route removed from VRF when source address deleted [ OK ] TEST: Route in default VRF not removed [ OK ] TEST: Route removed in default VRF when source address deleted [ OK ] TEST: Route in VRF is not removed by address delete [ OK ] Identical FIB info with different table ID TEST: Route removed from VRF when source address deleted [ OK ] TEST: Route in default VRF not removed [ OK ] TEST: Route removed in default VRF when source address deleted [ OK ] TEST: Route in VRF is not removed by address delete [ OK ] Table ID 0 TEST: Route removed in default VRF when source address deleted [ OK ] Tests passed: 9 Tests failed: 0 Fixes: 5a56a0b ("net: Don't delete routes in different VRFs") Reported-by: Donald Sharp <[email protected]> Signed-off-by: Ido Schimmel <[email protected]> Reviewed-by: David Ahern <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent f96a3d7 commit c0d9993

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

net/ipv4/fib_frontend.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,9 @@ static int rtm_to_fib_config(struct net *net, struct sk_buff *skb,
841841
return -EINVAL;
842842
}
843843

844+
if (!cfg->fc_table)
845+
cfg->fc_table = RT_TABLE_MAIN;
846+
844847
return 0;
845848
errout:
846849
return err;

tools/testing/selftests/net/fib_tests.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,11 +1712,13 @@ ipv4_del_addr_test()
17121712
$IP addr add dev dummy1 172.16.104.1/24
17131713
$IP addr add dev dummy1 172.16.104.11/24
17141714
$IP addr add dev dummy1 172.16.104.12/24
1715+
$IP addr add dev dummy1 172.16.104.13/24
17151716
$IP addr add dev dummy2 172.16.104.1/24
17161717
$IP addr add dev dummy2 172.16.104.11/24
17171718
$IP addr add dev dummy2 172.16.104.12/24
17181719
$IP route add 172.16.105.0/24 via 172.16.104.2 src 172.16.104.11
17191720
$IP route add 172.16.106.0/24 dev lo src 172.16.104.12
1721+
$IP route add table 0 172.16.107.0/24 via 172.16.104.2 src 172.16.104.13
17201722
$IP route add vrf red 172.16.105.0/24 via 172.16.104.2 src 172.16.104.11
17211723
$IP route add vrf red 172.16.106.0/24 dev lo src 172.16.104.12
17221724
set +e
@@ -1762,6 +1764,14 @@ ipv4_del_addr_test()
17621764
$IP ro ls vrf red | grep -q 172.16.106.0/24
17631765
log_test $? 0 "Route in VRF is not removed by address delete"
17641766

1767+
# removing address from device in default vrf should remove route from
1768+
# the default vrf even when route was inserted with a table ID of 0.
1769+
echo " Table ID 0"
1770+
1771+
$IP addr del dev dummy1 172.16.104.13/24
1772+
$IP ro ls | grep -q 172.16.107.0/24
1773+
log_test $? 1 "Route removed in default VRF when source address deleted"
1774+
17651775
$IP li del dummy1
17661776
$IP li del dummy2
17671777
cleanup

0 commit comments

Comments
 (0)