netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net 0/3] Fix IPv6 peer route update
@ 2020-03-03  6:37 Hangbin Liu
  2020-03-03  6:37 ` [PATCH net 1/3] net/ipv6: need update peer route when modify metric Hangbin Liu
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Hangbin Liu @ 2020-03-03  6:37 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Roopa Prabhu, David Miller, Hangbin Liu

Currently we have two issues for peer route update on IPv6.
1. When update peer route metric, we only updated the local one.
2. If peer address changed, we didn't remove the old one and add new one.

The first two patches fixed these issues and the third patch add new
tests to cover it.

With the fixes and updated test:
]# ./fib_tests.sh
IPv6 prefix route tests
    TEST: Default metric                                                [ OK ]
    TEST: User specified metric on first device                         [ OK ]
    TEST: User specified metric on second device                        [ OK ]
    TEST: Delete of address on first device                             [ OK ]
    TEST: Modify metric of address                                      [ OK ]
    TEST: Prefix route removed on link down                             [ OK ]
    TEST: Prefix route with metric on link up                           [ OK ]
    TEST: Set metric with peer route on local side                      [ OK ]
    TEST: User specified metric on local address                        [ OK ]
    TEST: Set metric with peer route on peer side                       [ OK ]
    TEST: Modify metric with peer route on local side                   [ OK ]
    TEST: Modify metric with peer route on peer side                    [ OK ]

IPv4 prefix route tests
    TEST: Default metric                                                [ OK ]
    TEST: User specified metric on first device                         [ OK ]
    TEST: User specified metric on second device                        [ OK ]
    TEST: Delete of address on first device                             [ OK ]
    TEST: Modify metric of address                                      [ OK ]
    TEST: Prefix route removed on link down                             [ OK ]
    TEST: Prefix route with metric on link up                           [ OK ]
    TEST: Modify metric of .0/24 address                                [ OK ]
    TEST: Set metric of address with peer route                         [ OK ]
    TEST: Modify metric of address with peer route                      [ OK ]

Tests passed:  22
Tests failed:   0


Hangbin Liu (3):
  net/ipv6: need update peer route when modify metric
  net/ipv6: remove the old peer route if change it to a new one
  selftests/net/fib_tests: update addr_metric_test for peer route
    testing

 net/ipv6/addrconf.c                      | 41 +++++++++++++++++++-----
 tools/testing/selftests/net/fib_tests.sh | 34 ++++++++++++++++++--
 2 files changed, 64 insertions(+), 11 deletions(-)

-- 
2.19.2


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

* [PATCH net 1/3] net/ipv6: need update peer route when modify metric
  2020-03-03  6:37 [PATCH net 0/3] Fix IPv6 peer route update Hangbin Liu
@ 2020-03-03  6:37 ` Hangbin Liu
  2020-03-03 15:58   ` David Ahern
  2020-03-03  6:37 ` [PATCH net 2/3] net/ipv6: remove the old peer route if change it to a new one Hangbin Liu
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Hangbin Liu @ 2020-03-03  6:37 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Roopa Prabhu, David Miller, Hangbin Liu

When we modify the route metric, the peer address's route need also
be updated. Before the fix:

+ ip addr add dev dummy1 2001:db8::1 peer 2001:db8::2 metric 60
+ ip -6 route show dev dummy1
2001:db8::1 proto kernel metric 60 pref medium
2001:db8::2 proto kernel metric 60 pref medium
+ ip addr change dev dummy1 2001:db8::1 peer 2001:db8::2 metric 61
+ ip -6 route show dev dummy1
2001:db8::1 proto kernel metric 61 pref medium
2001:db8::2 proto kernel metric 60 pref medium

After the fix:
+ ip addr change dev dummy1 2001:db8::1 peer 2001:db8::2 metric 61
+ ip -6 route show dev dummy1
2001:db8::1 proto kernel metric 61 pref medium
2001:db8::2 proto kernel metric 61 pref medium

Fixes: 8308f3ff1753 ("net/ipv6: Add support for specifying metric of connected routes")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 net/ipv6/addrconf.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 164c71c54b5c..4fb72028ca45 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -4586,12 +4586,14 @@ inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh,
 }
 
 static int modify_prefix_route(struct inet6_ifaddr *ifp,
-			       unsigned long expires, u32 flags)
+			       unsigned long expires, u32 flags,
+			       bool modify_peer)
 {
 	struct fib6_info *f6i;
 	u32 prio;
 
-	f6i = addrconf_get_prefix_route(&ifp->addr, ifp->prefix_len,
+	f6i = addrconf_get_prefix_route(modify_peer ? &ifp->peer_addr : &ifp->addr,
+					ifp->prefix_len,
 					ifp->idev->dev, 0, RTF_DEFAULT, true);
 	if (!f6i)
 		return -ENOENT;
@@ -4602,7 +4604,8 @@ static int modify_prefix_route(struct inet6_ifaddr *ifp,
 		ip6_del_rt(dev_net(ifp->idev->dev), f6i);
 
 		/* add new one */
-		addrconf_prefix_route(&ifp->addr, ifp->prefix_len,
+		addrconf_prefix_route(modify_peer ? &ifp->peer_addr : &ifp->addr,
+				      ifp->prefix_len,
 				      ifp->rt_priority, ifp->idev->dev,
 				      expires, flags, GFP_KERNEL);
 	} else {
@@ -4678,7 +4681,7 @@ static int inet6_addr_modify(struct inet6_ifaddr *ifp, struct ifa6_config *cfg)
 		int rc = -ENOENT;
 
 		if (had_prefixroute)
-			rc = modify_prefix_route(ifp, expires, flags);
+			rc = modify_prefix_route(ifp, expires, flags, false);
 
 		/* prefix route could have been deleted; if so restore it */
 		if (rc == -ENOENT) {
@@ -4686,6 +4689,15 @@ static int inet6_addr_modify(struct inet6_ifaddr *ifp, struct ifa6_config *cfg)
 					      ifp->rt_priority, ifp->idev->dev,
 					      expires, flags, GFP_KERNEL);
 		}
+
+		if (had_prefixroute && !ipv6_addr_any(&ifp->peer_addr))
+			rc = modify_prefix_route(ifp, expires, flags, true);
+
+		if (rc == -ENOENT && !ipv6_addr_any(&ifp->peer_addr)) {
+			addrconf_prefix_route(&ifp->peer_addr, ifp->prefix_len,
+					      ifp->rt_priority, ifp->idev->dev,
+					      expires, flags, GFP_KERNEL);
+		}
 	} else if (had_prefixroute) {
 		enum cleanup_prefix_rt_t action;
 		unsigned long rt_expires;
-- 
2.19.2


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

* [PATCH net 2/3] net/ipv6: remove the old peer route if change it to a new one
  2020-03-03  6:37 [PATCH net 0/3] Fix IPv6 peer route update Hangbin Liu
  2020-03-03  6:37 ` [PATCH net 1/3] net/ipv6: need update peer route when modify metric Hangbin Liu
@ 2020-03-03  6:37 ` Hangbin Liu
  2020-03-03 15:58   ` David Ahern
  2020-03-03  6:37 ` [PATCH net 3/3] selftests/net/fib_tests: update addr_metric_test for peer route testing Hangbin Liu
  2020-03-03 22:46 ` [PATCH net 0/3] Fix IPv6 peer route update David Miller
  3 siblings, 1 reply; 8+ messages in thread
From: Hangbin Liu @ 2020-03-03  6:37 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Roopa Prabhu, David Miller, Hangbin Liu

When we modify the peer route and changed it to a new one, we should
remove the old route first. Before the fix:

+ ip addr add dev dummy1 2001:db8::1 peer 2001:db8::2
+ ip -6 route show dev dummy1
2001:db8::1 proto kernel metric 256 pref medium
2001:db8::2 proto kernel metric 256 pref medium
+ ip addr change dev dummy1 2001:db8::1 peer 2001:db8::3
+ ip -6 route show dev dummy1
2001:db8::1 proto kernel metric 256 pref medium
2001:db8::2 proto kernel metric 256 pref medium

After the fix:
+ ip addr change dev dummy1 2001:db8::1 peer 2001:db8::3
+ ip -6 route show dev dummy1
2001:db8::1 proto kernel metric 256 pref medium
2001:db8::3 proto kernel metric 256 pref medium

This patch depend on the previous patch "net/ipv6: need update peer route
when modify metric" to update new peer route after delete old one.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 net/ipv6/addrconf.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 4fb72028ca45..e6e1290ea06f 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -1226,11 +1226,13 @@ check_cleanup_prefix_route(struct inet6_ifaddr *ifp, unsigned long *expires)
 }
 
 static void
-cleanup_prefix_route(struct inet6_ifaddr *ifp, unsigned long expires, bool del_rt)
+cleanup_prefix_route(struct inet6_ifaddr *ifp, unsigned long expires,
+		     bool del_rt, bool del_peer)
 {
 	struct fib6_info *f6i;
 
-	f6i = addrconf_get_prefix_route(&ifp->addr, ifp->prefix_len,
+	f6i = addrconf_get_prefix_route(del_peer ? &ifp->peer_addr : &ifp->addr,
+					ifp->prefix_len,
 					ifp->idev->dev, 0, RTF_DEFAULT, true);
 	if (f6i) {
 		if (del_rt)
@@ -1293,7 +1295,7 @@ static void ipv6_del_addr(struct inet6_ifaddr *ifp)
 
 	if (action != CLEANUP_PREFIX_RT_NOP) {
 		cleanup_prefix_route(ifp, expires,
-			action == CLEANUP_PREFIX_RT_DEL);
+			action == CLEANUP_PREFIX_RT_DEL, false);
 	}
 
 	/* clean up prefsrc entries */
@@ -4627,6 +4629,7 @@ static int inet6_addr_modify(struct inet6_ifaddr *ifp, struct ifa6_config *cfg)
 	unsigned long timeout;
 	bool was_managetempaddr;
 	bool had_prefixroute;
+	bool new_peer = false;
 
 	ASSERT_RTNL();
 
@@ -4658,6 +4661,13 @@ static int inet6_addr_modify(struct inet6_ifaddr *ifp, struct ifa6_config *cfg)
 		cfg->preferred_lft = timeout;
 	}
 
+	if (cfg->peer_pfx &&
+	    memcmp(&ifp->peer_addr, cfg->peer_pfx, sizeof(struct in6_addr))) {
+		if (!ipv6_addr_any(&ifp->peer_addr))
+			cleanup_prefix_route(ifp, expires, true, true);
+		new_peer = true;
+	}
+
 	spin_lock_bh(&ifp->lock);
 	was_managetempaddr = ifp->flags & IFA_F_MANAGETEMPADDR;
 	had_prefixroute = ifp->flags & IFA_F_PERMANENT &&
@@ -4673,6 +4683,9 @@ static int inet6_addr_modify(struct inet6_ifaddr *ifp, struct ifa6_config *cfg)
 	if (cfg->rt_priority && cfg->rt_priority != ifp->rt_priority)
 		ifp->rt_priority = cfg->rt_priority;
 
+	if (new_peer)
+		ifp->peer_addr = *cfg->peer_pfx;
+
 	spin_unlock_bh(&ifp->lock);
 	if (!(ifp->flags&IFA_F_TENTATIVE))
 		ipv6_ifa_notify(0, ifp);
@@ -4708,7 +4721,7 @@ static int inet6_addr_modify(struct inet6_ifaddr *ifp, struct ifa6_config *cfg)
 
 		if (action != CLEANUP_PREFIX_RT_NOP) {
 			cleanup_prefix_route(ifp, rt_expires,
-				action == CLEANUP_PREFIX_RT_DEL);
+				action == CLEANUP_PREFIX_RT_DEL, false);
 		}
 	}
 
-- 
2.19.2


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

* [PATCH net 3/3] selftests/net/fib_tests: update addr_metric_test for peer route testing
  2020-03-03  6:37 [PATCH net 0/3] Fix IPv6 peer route update Hangbin Liu
  2020-03-03  6:37 ` [PATCH net 1/3] net/ipv6: need update peer route when modify metric Hangbin Liu
  2020-03-03  6:37 ` [PATCH net 2/3] net/ipv6: remove the old peer route if change it to a new one Hangbin Liu
@ 2020-03-03  6:37 ` Hangbin Liu
  2020-03-03 15:58   ` David Ahern
  2020-03-03 22:46 ` [PATCH net 0/3] Fix IPv6 peer route update David Miller
  3 siblings, 1 reply; 8+ messages in thread
From: Hangbin Liu @ 2020-03-03  6:37 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Roopa Prabhu, David Miller, Hangbin Liu

This patch update {ipv4, ipv6}_addr_metric_test with
1. Set metric of address with peer route and see if the route added
correctly.
2. Modify metric and peer address for peer route and see if the route
changed correctly.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 tools/testing/selftests/net/fib_tests.sh | 34 +++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh
index 60273f1bc7d9..b7616704b55e 100755
--- a/tools/testing/selftests/net/fib_tests.sh
+++ b/tools/testing/selftests/net/fib_tests.sh
@@ -1041,6 +1041,27 @@ ipv6_addr_metric_test()
 	fi
 	log_test $rc 0 "Prefix route with metric on link up"
 
+	# verify peer metric added correctly
+	set -e
+	run_cmd "$IP -6 addr flush dev dummy2"
+	run_cmd "$IP -6 addr add dev dummy2 2001:db8:104::1 peer 2001:db8:104::2 metric 260"
+	set +e
+
+	check_route6 "2001:db8:104::1 dev dummy2 proto kernel metric 260"
+	log_test $? 0 "Set metric with peer route on local side"
+	log_test $? 0 "User specified metric on local address"
+	check_route6 "2001:db8:104::2 dev dummy2 proto kernel metric 260"
+	log_test $? 0 "Set metric with peer route on peer side"
+
+	set -e
+	run_cmd "$IP -6 addr change dev dummy2 2001:db8:104::1 peer 2001:db8:104::3 metric 261"
+	set +e
+
+	check_route6 "2001:db8:104::1 dev dummy2 proto kernel metric 261"
+	log_test $? 0 "Modify metric and peer address on local side"
+	check_route6 "2001:db8:104::3 dev dummy2 proto kernel metric 261"
+	log_test $? 0 "Modify metric and peer address on peer side"
+
 	$IP li del dummy1
 	$IP li del dummy2
 	cleanup
@@ -1457,13 +1478,20 @@ ipv4_addr_metric_test()
 
 	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"
+		check_route "172.16.104.2 dev dummy2 proto kernel scope link src 172.16.104.1 metric 260"
+		rc=$?
+	fi
+	log_test $rc 0 "Set metric of address with peer route"
+
+	run_cmd "$IP addr change dev dummy2 172.16.104.1/32 peer 172.16.104.3 metric 261"
+	rc=$?
+	if [ $rc -eq 0 ]; then
+		check_route "172.16.104.3 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"
+	log_test $rc 0 "Modify metric and peer address for peer route"
 
 	$IP li del dummy1
 	$IP li del dummy2
-- 
2.19.2


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

* Re: [PATCH net 1/3] net/ipv6: need update peer route when modify metric
  2020-03-03  6:37 ` [PATCH net 1/3] net/ipv6: need update peer route when modify metric Hangbin Liu
@ 2020-03-03 15:58   ` David Ahern
  0 siblings, 0 replies; 8+ messages in thread
From: David Ahern @ 2020-03-03 15:58 UTC (permalink / raw)
  To: Hangbin Liu, netdev; +Cc: Roopa Prabhu, David Miller

On 3/2/20 11:37 PM, Hangbin Liu wrote:
> When we modify the route metric, the peer address's route need also
> be updated. Before the fix:
> 
> + ip addr add dev dummy1 2001:db8::1 peer 2001:db8::2 metric 60
> + ip -6 route show dev dummy1
> 2001:db8::1 proto kernel metric 60 pref medium
> 2001:db8::2 proto kernel metric 60 pref medium
> + ip addr change dev dummy1 2001:db8::1 peer 2001:db8::2 metric 61
> + ip -6 route show dev dummy1
> 2001:db8::1 proto kernel metric 61 pref medium
> 2001:db8::2 proto kernel metric 60 pref medium
> 
> After the fix:
> + ip addr change dev dummy1 2001:db8::1 peer 2001:db8::2 metric 61
> + ip -6 route show dev dummy1
> 2001:db8::1 proto kernel metric 61 pref medium
> 2001:db8::2 proto kernel metric 61 pref medium
> 
> Fixes: 8308f3ff1753 ("net/ipv6: Add support for specifying metric of connected routes")
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> ---
>  net/ipv6/addrconf.c | 20 ++++++++++++++++----
>  1 file changed, 16 insertions(+), 4 deletions(-)
> 

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



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

* Re: [PATCH net 2/3] net/ipv6: remove the old peer route if change it to a new one
  2020-03-03  6:37 ` [PATCH net 2/3] net/ipv6: remove the old peer route if change it to a new one Hangbin Liu
@ 2020-03-03 15:58   ` David Ahern
  0 siblings, 0 replies; 8+ messages in thread
From: David Ahern @ 2020-03-03 15:58 UTC (permalink / raw)
  To: Hangbin Liu, netdev; +Cc: Roopa Prabhu, David Miller

On 3/2/20 11:37 PM, Hangbin Liu wrote:
> When we modify the peer route and changed it to a new one, we should
> remove the old route first. Before the fix:
> 
> + ip addr add dev dummy1 2001:db8::1 peer 2001:db8::2
> + ip -6 route show dev dummy1
> 2001:db8::1 proto kernel metric 256 pref medium
> 2001:db8::2 proto kernel metric 256 pref medium
> + ip addr change dev dummy1 2001:db8::1 peer 2001:db8::3
> + ip -6 route show dev dummy1
> 2001:db8::1 proto kernel metric 256 pref medium
> 2001:db8::2 proto kernel metric 256 pref medium
> 
> After the fix:
> + ip addr change dev dummy1 2001:db8::1 peer 2001:db8::3
> + ip -6 route show dev dummy1
> 2001:db8::1 proto kernel metric 256 pref medium
> 2001:db8::3 proto kernel metric 256 pref medium
> 
> This patch depend on the previous patch "net/ipv6: need update peer route
> when modify metric" to update new peer route after delete old one.
> 
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> ---
>  net/ipv6/addrconf.c | 21 +++++++++++++++++----
>  1 file changed, 17 insertions(+), 4 deletions(-)
> 

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



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

* Re: [PATCH net 3/3] selftests/net/fib_tests: update addr_metric_test for peer route testing
  2020-03-03  6:37 ` [PATCH net 3/3] selftests/net/fib_tests: update addr_metric_test for peer route testing Hangbin Liu
@ 2020-03-03 15:58   ` David Ahern
  0 siblings, 0 replies; 8+ messages in thread
From: David Ahern @ 2020-03-03 15:58 UTC (permalink / raw)
  To: Hangbin Liu, netdev; +Cc: Roopa Prabhu, David Miller

On 3/2/20 11:37 PM, Hangbin Liu wrote:
> This patch update {ipv4, ipv6}_addr_metric_test with
> 1. Set metric of address with peer route and see if the route added
> correctly.
> 2. Modify metric and peer address for peer route and see if the route
> changed correctly.
> 
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> ---
>  tools/testing/selftests/net/fib_tests.sh | 34 +++++++++++++++++++++---
>  1 file changed, 31 insertions(+), 3 deletions(-)
> 

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



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

* Re: [PATCH net 0/3] Fix IPv6 peer route update
  2020-03-03  6:37 [PATCH net 0/3] Fix IPv6 peer route update Hangbin Liu
                   ` (2 preceding siblings ...)
  2020-03-03  6:37 ` [PATCH net 3/3] selftests/net/fib_tests: update addr_metric_test for peer route testing Hangbin Liu
@ 2020-03-03 22:46 ` David Miller
  3 siblings, 0 replies; 8+ messages in thread
From: David Miller @ 2020-03-03 22:46 UTC (permalink / raw)
  To: liuhangbin; +Cc: netdev, dsahern, roopa

From: Hangbin Liu <liuhangbin@gmail.com>
Date: Tue,  3 Mar 2020 14:37:33 +0800

> Currently we have two issues for peer route update on IPv6.
> 1. When update peer route metric, we only updated the local one.
> 2. If peer address changed, we didn't remove the old one and add new one.
> 
> The first two patches fixed these issues and the third patch add new
> tests to cover it.
> 
> With the fixes and updated test:
> ]# ./fib_tests.sh
 ...

Series applied and queued up for -stable, thanks.

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

end of thread, other threads:[~2020-03-03 22:46 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-03  6:37 [PATCH net 0/3] Fix IPv6 peer route update Hangbin Liu
2020-03-03  6:37 ` [PATCH net 1/3] net/ipv6: need update peer route when modify metric Hangbin Liu
2020-03-03 15:58   ` David Ahern
2020-03-03  6:37 ` [PATCH net 2/3] net/ipv6: remove the old peer route if change it to a new one Hangbin Liu
2020-03-03 15:58   ` David Ahern
2020-03-03  6:37 ` [PATCH net 3/3] selftests/net/fib_tests: update addr_metric_test for peer route testing Hangbin Liu
2020-03-03 15:58   ` David Ahern
2020-03-03 22:46 ` [PATCH net 0/3] Fix IPv6 peer route update David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).