All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] ipv4: fix route update on metric change.
@ 2019-10-26  9:53 Paolo Abeni
  2019-10-26  9:53 ` [PATCH v2 1/2] " Paolo Abeni
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Paolo Abeni @ 2019-10-26  9:53 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Beniamino Galvani, David S. Miller

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(-)

-- 
2.21.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] ipv4: fix route update on metric change.
  2019-10-26  9:53 [PATCH v2 0/2] ipv4: fix route update on metric change Paolo Abeni
@ 2019-10-26  9:53 ` Paolo Abeni
  2019-10-26  9:53 ` [PATCH v2 2/2] selftests: fib_tests: add more tests for metric update Paolo Abeni
  2019-10-26 18:26 ` [PATCH v2 0/2] ipv4: fix route update on metric change David Miller
  2 siblings, 0 replies; 5+ messages in thread
From: Paolo Abeni @ 2019-10-26  9:53 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Beniamino Galvani, David S. Miller

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'.

Fixes: af4d768ad28c ("net/ipv4: Add support for specifying metric of connected routes")
Reported-and-suggested-by: Beniamino Galvani <bgalvani@redhat.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: David Ahern <dsahern@gmail.com>
---
 net/ipv4/fib_frontend.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index dde77f72e03e..71c78d223dfd 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -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 */
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] selftests: fib_tests: add more tests for metric update
  2019-10-26  9:53 [PATCH v2 0/2] ipv4: fix route update on metric change Paolo Abeni
  2019-10-26  9:53 ` [PATCH v2 1/2] " Paolo Abeni
@ 2019-10-26  9:53 ` Paolo Abeni
  2019-10-26 16:38   ` David Ahern
  2019-10-26 18:26 ` [PATCH v2 0/2] ipv4: fix route update on metric change David Miller
  2 siblings, 1 reply; 5+ messages in thread
From: Paolo Abeni @ 2019-10-26  9:53 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Beniamino Galvani, David S. Miller

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 <dsahern@gmail.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
 tools/testing/selftests/net/fib_tests.sh | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh
index c4ba0ff4a53f..76c1897e6352 100755
--- a/tools/testing/selftests/net/fib_tests.sh
+++ b/tools/testing/selftests/net/fib_tests.sh
@@ -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
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 2/2] selftests: fib_tests: add more tests for metric update
  2019-10-26  9:53 ` [PATCH v2 2/2] selftests: fib_tests: add more tests for metric update Paolo Abeni
@ 2019-10-26 16:38   ` David Ahern
  0 siblings, 0 replies; 5+ messages in thread
From: David Ahern @ 2019-10-26 16:38 UTC (permalink / raw)
  To: Paolo Abeni, netdev; +Cc: Beniamino Galvani, David S. Miller

On 10/26/19 3:53 AM, Paolo Abeni wrote:
> 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 <dsahern@gmail.com>
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> ---
>  tools/testing/selftests/net/fib_tests.sh | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
> 

Reviewed-by: David Ahern <dsahern@gmail.com>

Thanks for adding the tests.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 0/2] ipv4: fix route update on metric change.
  2019-10-26  9:53 [PATCH v2 0/2] ipv4: fix route update on metric change Paolo Abeni
  2019-10-26  9:53 ` [PATCH v2 1/2] " Paolo Abeni
  2019-10-26  9:53 ` [PATCH v2 2/2] selftests: fib_tests: add more tests for metric update Paolo Abeni
@ 2019-10-26 18:26 ` David Miller
  2 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2019-10-26 18:26 UTC (permalink / raw)
  To: pabeni; +Cc: netdev, dsahern, bgalvani

From: Paolo Abeni <pabeni@redhat.com>
Date: Sat, 26 Oct 2019 11:53:38 +0200

> 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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-10-26 18:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-26  9:53 [PATCH v2 0/2] ipv4: fix route update on metric change Paolo Abeni
2019-10-26  9:53 ` [PATCH v2 1/2] " Paolo Abeni
2019-10-26  9:53 ` [PATCH v2 2/2] selftests: fib_tests: add more tests for metric update Paolo Abeni
2019-10-26 16:38   ` David Ahern
2019-10-26 18:26 ` [PATCH v2 0/2] ipv4: fix route update on metric change David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.