ipv4: fix route update on metric change.
Subsystems (4)
Paolo Abeni
maintainerv2 cover ipv4: fix route update on metric change.
This fixes connected route update on some edge cases for ip addr metric change.
It additionally includes self tests for the covered scenarios. The new tests fail on unpatched kernels and pass on the patched one.
v1 -> v2:
- add selftests
Paolo Abeni (2):
ipv4: fix route update on metric change.
selftests: fib_tests: add more tests for metric update
net/ipv4/fib_frontend.c | 2 +- tools/testing/selftests/net/fib_tests.sh | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-)
Signature · 1 line
2.21.0
Paolo Abeni
maintainerPATCH v2 1/2 ipv4: fix route update on metric change.
Since commit af4d768ad28c ("net/ipv4: Add support for specifying metric of connected routes"), when updating an IP address with a different metric, the associated connected route is updated, too.
Still, the mentioned commit doesn't handle properly some corner cases:
$ ip addr add dev eth0 192.168.1.0/24 $ ip addr add dev eth0 192.168.2.1/32 peer 192.168.2.2 $ ip addr add dev eth0 192.168.3.1/24 $ ip addr change dev eth0 192.168.1.0/24 metric 10 $ ip addr change dev eth0 192.168.2.1/32 peer 192.168.2.2 metric 10 $ ip addr change dev eth0 192.168.3.1/24 metric 10 $ ip -4 route 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.0 192.168.2.2 dev eth0 proto kernel scope link src 192.168.2.1 192.168.3.0/24 dev eth0 proto kernel scope link src 192.168.2.1 metric 10
Only the last route is correctly updated.
The problem is the current test in fib_modify_prefix_metric():
if (!(dev->flags & IFF_UP) || ifa->ifa_flags & (IFA_F_SECONDARY | IFA_F_NOPREFIXROUTE) || ipv4_is_zeronet(prefix) || prefix == ifa->ifa_local || ifa->ifa_prefixlen == 32)
Which should be the logical 'not' of the pre-existing test in fib_add_ifaddr():
if (!ipv4_is_zeronet(prefix) && !(ifa->ifa_flags & IFA_F_SECONDARY) && (prefix != addr || ifa->ifa_prefixlen < 32))
To properly negate the original expression, we need to change the last logical 'or' to a logical 'and'.
--- net/ipv4/fib_frontend.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/fib_frontend.c +1 -1
@@ -1148,7 +1148,7 @@ void fib_modify_prefix_metric(struct in_ifaddr *ifa, u32 new_metric)if (!(dev->flags &IFF_UP ) || ifa->ifa_flags & (IFA_F_SECONDARY |IFA_F_NOPREFIXROUTE ) ||ipv4_is_zeronet (prefix) || - prefix == ifa->ifa_local || ifa->ifa_prefixlen ==32 ) + (prefix == ifa->ifa_local && ifa->ifa_prefixlen ==32 ))return ;/* add the new */
Signature · 1 line
2.21.0
Paolo Abeni
maintainerPATCH v2 2/2 selftests: fib_tests: add more tests for metric update
In reply to Paolo AbeniThis patch adds two more tests to ipv4_addr_metric_test() to explicitly cover the scenarios fixed by the previous patch.
--- tools/testing/selftests/net/fib_tests.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
tools/testing/selftests/net/fib_tests.sh +21 -0
@@ -1438,6 +1438,27 @@ ipv4_addr_metric_test() fi log_test $rc 0 "Prefix route with metric on link up" + # explicitly check for metric changes on edge scenarios + run_cmd "$IP addr flush dev dummy2" + run_cmd "$IP addr add dev dummy2 172.16.104.0/24 metric 259" + run_cmd "$IP addr change dev dummy2 172.16.104.0/24 metric 260" + rc=$? + if [ $rc -eq 0 ]; then + check_route "172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.0 metric 260" + rc=$? + fi + log_test $rc 0 "Modify metric of .0/24 address" + + run_cmd "$IP addr flush dev dummy2" + run_cmd "$IP addr add dev dummy2 172.16.104.1/32 peer 172.16.104.2 metric 260" + run_cmd "$IP addr change dev dummy2 172.16.104.1/32 peer 172.16.104.2 metric 261" + rc=$? + if [ $rc -eq 0 ]; then + check_route "172.16.104.2 dev dummy2 proto kernel scope link src 172.16.104.1 metric 261" + rc=$? + fi + log_test $rc 0 "Modify metric of address with peer route" + $IP li del dummy1 $IP li del dummy2 cleanup
Signature · 1 line
2.21.0
Re: [PATCH v2 2/2] selftests: fib_tests: add more tests for metric update
Quoted 9 lines · Paolo Abeni
This patch adds two more tests to
ipv4_addr_metric_test()to explicitly cover the scenarios fixed by the previous patch.Suggested-by David Ahern <[email protected]>Signed-off-by Paolo Abeni <[email protected]>--- tools/testing/selftests/net/fib_tests.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
Thanks for adding the tests.
David Miller
maintainerFrom: Paolo Abeni <[email protected]>
Date: Sat, 26 Oct 2019 11:53:38 +0200
Quoted 7 lines
This fixes connected route update on some edge cases for ip addr metric change.
It additionally includes self tests for the covered scenarios. The new tests fail on unpatched kernels and pass on the patched one.v1 -> v2:
- add selftests
Series applied and queued up for -stable, thanks.