IPv6: keep permanent addresses on admin down
Subsystems (3)
PATCH 1/2 IPv6: keep permanent addresses on admin down
Permanent IPV6 addresses should not be removed when the link is set to admin down, only when device is removed.
When link is lost permanent addresses should be marked as tentative so that when link comes back they are subject to duplicate address detection (if DAD was enabled for that address).
Other routing systems keep manually configured IPv6 addresses when link is set down.
---
The logic here is getting long and twisted, doing some work to use RCU here and refactor.
net/ipv6/addrconf.c +25 -12
@@ -2646,7 +2646,8 @@ static int addrconf_ifdown(struct net_dewrite_lock_bh (&addrconf_hash_lock);while ((ifa = *bifa) !=NULL ) { -if (ifa->idev == idev) { +if (ifa->idev == idev && + (how || !(ifa->flags&IFA_F_PERMANENT ))) { *bifa = ifa->lst_next; ifa->lst_next =NULL ;addrconf_del_timer (ifa);
@@ -2686,18 +2687,30 @@ static int addrconf_ifdown(struct net_dewrite_lock_bh (&idev->lock); }#endif -while ((ifa = idev->addr_list) !=NULL ) { - idev->addr_list = ifa->if_next; - ifa->if_next =NULL ; - ifa->dead =1 ; -addrconf_del_timer (ifa); -write_unlock_bh (&idev->lock); - -__ipv6_ifa_notify (RTM_DELADDR , ifa); -atomic_notifier_call_chain (&inet6addr_chain,NETDEV_DOWN , ifa); -in6_ifa_put (ifa); + bifa = &idev->addr_list; +while ((ifa = *bifa) !=NULL ) { +if (how ==0 && (ifa->flags&IFA_F_PERMANENT )) { +/* Retain permanent address on admin down */ + bifa = &ifa->if_next; + +/* Restart DAD if needed when link comes back up */ +if ( !((dev->flags&(IFF_NOARP |IFF_LOOPBACK )) || + idev->cnf.accept_dad <=0 || + (ifa->flags &IFA_F_NODAD ))) + ifa->flags |=IFA_F_TENTATIVE ; + }else { + *bifa = ifa->if_next; + ifa->if_next =NULL ; + + ifa->dead =1 ; +write_unlock_bh (&idev->lock); + +__ipv6_ifa_notify (RTM_DELADDR , ifa); +atomic_notifier_call_chain (&inet6addr_chain,NETDEV_DOWN , ifa); +in6_ifa_put (ifa); -write_lock_bh (&idev->lock); +write_lock_bh (&idev->lock); + } }write_unlock_bh (&idev->lock);
PATCH 2/2 IPv6: remove trivial nested _bh suffix
Don't need to disable bottom half it is already down in the previous lock. Move some blank lines to group locking in same context.
net/ipv6/addrconf.c +11 -10
@@ -2802,14 +2802,14 @@ static void addrconf_dad_start(struct inread_lock_bh (&idev->lock);if (ifp->dead) goto out; -spin_lock_bh (&ifp->lock); +spin_lock (&ifp->lock);if (dev->flags&(IFF_NOARP |IFF_LOOPBACK ) || idev->cnf.accept_dad <1 || !(ifp->flags&IFA_F_TENTATIVE ) || ifp->flags &IFA_F_NODAD ) { ifp->flags &= ~(IFA_F_TENTATIVE |IFA_F_OPTIMISTIC |IFA_F_DADFAILED ); -spin_unlock_bh (&ifp->lock); +spin_unlock (&ifp->lock);read_unlock_bh (&idev->lock);addrconf_dad_completed (ifp);
@@ -2817,7 +2817,7 @@ static void addrconf_dad_start(struct in }if (!(idev->if_flags &IF_READY )) { -spin_unlock_bh (&ifp->lock); +spin_unlock (&ifp->lock);read_unlock_bh (&idev->lock);/* * If the device is not ready:
@@ -2837,7 +2837,7 @@ static void addrconf_dad_start(struct inip6_ins_rt (ifp->rt);addrconf_dad_kick (ifp); -spin_unlock_bh (&ifp->lock); +spin_unlock (&ifp->lock); out:read_unlock_bh (&idev->lock); }
@@ -2853,14 +2853,15 @@ static void addrconf_dad_timer(unsignedread_unlock_bh (&idev->lock); goto out; } -spin_lock_bh (&ifp->lock); + +spin_lock (&ifp->lock);if (ifp->probes ==0 ) {/* * DAD was successful */ ifp->flags &= ~(IFA_F_TENTATIVE |IFA_F_OPTIMISTIC |IFA_F_DADFAILED ); -spin_unlock_bh (&ifp->lock); +spin_unlock (&ifp->lock);read_unlock_bh (&idev->lock);addrconf_dad_completed (ifp);
@@ -2870,7 +2871,7 @@ static void addrconf_dad_timer(unsigned ifp->probes--;addrconf_mod_timer (ifp,AC_DAD , ifp->idev->nd_parms->retrans_time); -spin_unlock_bh (&ifp->lock); +spin_unlock (&ifp->lock);read_unlock_bh (&idev->lock);/* send a neighbour solicitation for our addr */
@@ -2918,12 +2919,12 @@ static void addrconf_dad_run(struct inetread_lock_bh (&idev->lock);for (ifp = idev->addr_list; ifp; ifp = ifp->if_next) { -spin_lock_bh (&ifp->lock); +spin_lock (&ifp->lock);if (!(ifp->flags &IFA_F_TENTATIVE )) { -spin_unlock_bh (&ifp->lock); +spin_unlock (&ifp->lock);continue ; } -spin_unlock_bh (&ifp->lock); +spin_unlock (&ifp->lock);addrconf_dad_kick (ifp); }read_unlock_bh (&idev->lock);
Re: [PATCH 2/2] IPv6: remove trivial nested _bh suffix
From: Stephen Hemminger <[email protected]>
Date: Mon, 8 Feb 2010 21:48:52 -0800
Quoted 5 lines
Don't need to disable bottom half it is already down in the previous lock. Move some blank lines to group locking in same context.
Signed-off-by Stephen Hemminger <[email protected]>
Applied to net-next-2.6
Quoted 29 lines · Stephen Hemminger
net/ipv6/addrconf.c +15
-10@@ -2686,18 +2687,30 @@ static int addrconf_ifdown(struct net_de write_lock_bh(&idev->lock); }#endif -while ((ifa = idev->addr_list) !=NULL ) { - idev->addr_list = ifa->if_next; - ifa->if_next =NULL ; - ifa->dead =1 ; -addrconf_del_timer (ifa); -write_unlock_bh (&idev->lock); - -__ipv6_ifa_notify (RTM_DELADDR , ifa); -atomic_notifier_call_chain (&inet6addr_chain,NETDEV_DOWN , ifa); -in6_ifa_put (ifa); + bifa = &idev->addr_list; +while ((ifa = *bifa) !=NULL ) { +if (how ==0 && (ifa->flags&IFA_F_PERMANENT )) { +/* Retain permanent address on admin down */ + bifa = &ifa->if_next; + +/* Restart DAD if needed when link comes back up */ +if ( !((dev->flags&(IFF_NOARP |IFF_LOOPBACK )) || + idev->cnf.accept_dad <=0 || + (ifa->flags &IFA_F_NODAD ))) + ifa->flags |=IFA_F_TENTATIVE ; + }else { + *bifa = ifa->if_next; + ifa->if_next =NULL ; +
net/ipv6/addrconf.c static int addrconf_ifdown(struct net_de · line 2713
Quoted 10 lines
net/ipv6/addrconf.c +8
-1+ ifa->dead =1 ; +write_unlock_bh (&idev->lock); + +__ipv6_ifa_notify (RTM_DELADDR , ifa); +atomic_notifier_call_chain (&inet6addr_chain,NETDEV_DOWN , ifa); +in6_ifa_put (ifa); -write_lock_bh (&idev->lock); +write_lock_bh (&idev->lock); + }
What about addrconf_del_timer()? It didn't seem to make it to this else{} from the original.
-Brian
Quoted 37 lines · On Tue, 09 Feb 2010 09:40:11 -0500 Brian Haley <[email protected]> wrote:
Quoted 36 lines · Stephen Hemminger
net/ipv6/addrconf.c +21
-10@@ -2686,18 +2687,30 @@ static int addrconf_ifdown(struct net_dewrite_lock_bh (&idev->lock); }#endif -while ((ifa = idev->addr_list) !=NULL ) { - idev->addr_list = ifa->if_next; - ifa->if_next =NULL ; - ifa->dead =1 ; -addrconf_del_timer (ifa); -write_unlock_bh (&idev->lock); - -__ipv6_ifa_notify (RTM_DELADDR , ifa); -atomic_notifier_call_chain (&inet6addr_chain,NETDEV_DOWN , ifa); -in6_ifa_put (ifa); + bifa = &idev->addr_list; +while ((ifa = *bifa) !=NULL ) { +if (how ==0 && (ifa->flags&IFA_F_PERMANENT )) { +/* Retain permanent address on admin down */ + bifa = &ifa->if_next; + +/* Restart DAD if needed when link comes back up */ +if ( !((dev->flags&(IFF_NOARP |IFF_LOOPBACK )) || + idev->cnf.accept_dad <=0 || + (ifa->flags &IFA_F_NODAD ))) + ifa->flags |=IFA_F_TENTATIVE ; + }else { + *bifa = ifa->if_next; + ifa->if_next =NULL ; + + ifa->dead =1 ; +write_unlock_bh (&idev->lock); + +__ipv6_ifa_notify (RTM_DELADDR , ifa); +atomic_notifier_call_chain (&inet6addr_chain,NETDEV_DOWN , ifa); +in6_ifa_put (ifa);
Quoted 8 lines
net/ipv6/addrconf.c static int addrconf_ifdown(struct net_de · line 2713
Quoted 3 lines
net/ipv6/addrconf.c +2
-1-write_lock_bh (&idev->lock); +write_lock_bh (&idev->lock); + }What about
addrconf_del_timer()? It didn't seem to make it to this else{} from the original.-Brian
addrconf_del_timer is already being done earlier in same code no need to do it twice.
From: Stephen Hemminger <[email protected]>
Date: Mon, 8 Feb 2010 21:48:05 -0800
Quoted 11 lines
Permanent IPV6 addresses should not be removed when the link is set to admin down, only when device is removed.
When link is lost permanent addresses should be marked as tentative so that when link comes back they are subject to duplicate address detection (if DAD was enabled for that address).
Other routing systems keep manually configured IPv6 addresses when link is set down.
Signed-off-by Stephen Hemminger <[email protected]>
Applied to net-next-2.6