ipv6: Fix route replacement with dev-only route
authorBenjamin Poirier <bpoirier@cumulusnetworks.com>
Wed, 12 Feb 2020 01:41:06 +0000 (10:41 +0900)
committerDavid S. Miller <davem@davemloft.net>
Mon, 17 Feb 2020 02:34:31 +0000 (18:34 -0800)
commite404b8c7cfb31654c9024d497cec58a501501692
tree5a24c73695f44b92f343f993d3bee588fe8bf567
parente8023b030ce1748930e2dc76353a262fe47d4745
ipv6: Fix route replacement with dev-only route

After commit 27596472473a ("ipv6: fix ECMP route replacement") it is no
longer possible to replace an ECMP-able route by a non ECMP-able route.
For example,
ip route add 2001:db8::1/128 via fe80::1 dev dummy0
ip route replace 2001:db8::1/128 dev dummy0
does not work as expected.

Tweak the replacement logic so that point 3 in the log of the above commit
becomes:
3. If the new route is not ECMP-able, and no matching non-ECMP-able route
exists, replace matching ECMP-able route (if any) or add the new route.

We can now summarize the entire replace semantics to:
When doing a replace, prefer replacing a matching route of the same
"ECMP-able-ness" as the replace argument. If there is no such candidate,
fallback to the first route found.

Fixes: 27596472473a ("ipv6: fix ECMP route replacement")
Signed-off-by: Benjamin Poirier <bpoirier@cumulusnetworks.com>
Reviewed-by: Michal Kubecek <mkubecek@suse.cz>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv6/ip6_fib.c
tools/testing/selftests/net/fib_tests.sh