Fix IPv6 peer route update
Subsystems (4)
cover Fix IPv6 peer route update
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(-)
Signature · 1 line
2.19.2
PATCH 1/3 net/ipv6: need update peer route when modify metric
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
--- net/ipv6/addrconf.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
net/ipv6/addrconf.c +16 -4
@@ -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;
Signature · 1 line
2.19.2
Re: [PATCH net 1/3] net/ipv6: need update peer route when modify metric
Quoted 18 lines · 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 mediumAfter 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
Quoted 6 lines
Fixes 8308f3ff1753 ("net/ipv6: Add support for specifying metric of connected routes")Signed-off-by Hangbin Liu <[email protected]>--- net/ipv6/addrconf.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
PATCH 2/3 net/ipv6: remove the old peer route if change it to a new one
In reply to Hangbin LiuWhen 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.
--- net/ipv6/addrconf.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
net/ipv6/addrconf.c +17 -4
@@ -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); } }
Signature · 1 line
2.19.2
Re: [PATCH net 2/3] net/ipv6: remove the old peer route if change it to a new one
Quoted 18 lines · 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 mediumAfter 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
Quoted 8 lines
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 <[email protected]>--- net/ipv6/addrconf.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
PATCH 3/3 selftests/net/fib_tests: update addr_metric_test for peer route testing
In reply to Hangbin LiuThis 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.
--- tools/testing/selftests/net/fib_tests.sh | 34 +++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-)
tools/testing/selftests/net/fib_tests.sh +31 -3
@@ -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
Signature · 1 line
2.19.2
Re: [PATCH net 3/3] selftests/net/fib_tests: update addr_metric_test for peer route testing
Quoted 11 lines · 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 <[email protected]>--- tools/testing/selftests/net/fib_tests.sh | 34 +++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-)
David Miller
maintainerFrom: Hangbin Liu <[email protected]>
Date: Tue, 3 Mar 2020 14:37:33 +0800
Quoted 9 lines
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.