ipv6: Reparent temporary address(es) if global address was deleted from userspace
Subsystems (3)
PATCH 1/1 ipv6: Reparent temporary address(es) if global address was deleted from userspace
If the kernel takes care of global and temporary addresses it can happen that the global address is deleted from userspace, e.g. by network managers in case the link goes (temporarily) down. In addition to the then orphaned temporary address(es) the next RA will create a new temporary address. Therefore we might end up with more than one non-deprecated temporary address for the same prefix for a longer period of time (>regen_advance). According to RfC 4941 sect. 3.4 this should not happen.
Fix this by reparenting orphaned temporary addresses.
--- net/ipv6/addrconf.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-)
net/ipv6/addrconf.c +31 -3
@@ -2077,14 +2077,34 @@ static void manage_tempaddrs(struct inet6_dev *idev, {u32 flags;struct inet6_ifaddr *ift; +unsigned long regen_advance;read_lock_bh (&idev->lock); + regen_advance = idev->cnf.regen_max_retry * + idev->cnf.dad_transmits * +NEIGH_VAR (idev->nd_parms,RETRANS_TIME ) /HZ ;/* update all temporary addresses in the list */ list_for_each_entry (ift, &idev->tempaddr_list, tmp_list) {int age, max_valid, max_prefered; +bool reparent; -if (ifp != ift->ifpub) -continue ; + reparent = false; +spin_lock (&ift->lock); +if (ifp != ift->ifpub) { +/* reparent if orphaned temporary address with same +* prefix is found +*/ +if (ipv6_prefix_equal (&ift->addr, &ifp->addr, + ift->prefix_len)) { +in6_ifa_hold (ifp); +in6_ifa_put (ift->ifpub); + ift->ifpub = ifp; + reparent = true; + }else { +spin_unlock (&ift->lock); +continue ; + } + }/* RFC 4941 section 3.3: * If a received option will extend the lifetime of a public
@@ -2110,7 +2130,6 @@ static void manage_tempaddrs(struct inet6_dev *idev,if (prefered_lft > max_prefered) prefered_lft = max_prefered; -spin_lock (&ift->lock); flags = ift->flags; ift->valid_lft = valid_lft; ift->prefered_lft = prefered_lft;
@@ -2119,6 +2138,15 @@ static void manage_tempaddrs(struct inet6_dev *idev, ift->flags &= ~IFA_F_DEPRECATED ;spin_unlock (&ift->lock); +/* Don't create a temporary address if we reparented one which +* is prefered more than regen_advance +*/ +if (reparent && prefered_lft > regen_advance) { + create = false; +pr_info ("%s: reparent orphaned temporary address\n" , + __func__); + } +if (!(flags&IFA_F_TENTATIVE ))ipv6_ifa_notify (0 , ift); }
Signature · 1 line
1.9.1.315.g3f09db0.dirty
Quoted 5 lines · Heiner Kallweit
If the kernel takes care of global and temporary addresses it can happen that the global address is deleted from userspace, e.g. by network managers in case the link goes (temporarily) down. In addition to the then orphaned temporary address(es) the next RA will create a new temporary address. Therefore we might end up with more than one non-deprecated temporary address for the same prefix for a longer period of time (>regen_advance). According to RfC 4941 sect. 3.4 this should not happen.
Nit: your commit description should only be ~75 chars wide max
Quoted 19 lines
Fix this by reparenting orphaned temporary addresses.
Signed-off-by Heiner Kallweit <[email protected]>--- net/ipv6/addrconf.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-)net/ipv6/addrconf.c +2
-0@@ -2077,14 +2077,34 @@ static void manage_tempaddrs(struct inet6_dev *idev, {u32 flags;struct inet6_ifaddr *ift; +unsigned long regen_advance;read_lock_bh (&idev->lock); + regen_advance = idev->cnf.regen_max_retry *
net/ipv6/addrconf.c static void manage_tempaddrs(struct inet6_dev *idev, · line 2091
Quoted 10 lines
net/ipv6/addrconf.c +4
-2+ idev->cnf.dad_transmits * +NEIGH_VAR (idev->nd_parms,RETRANS_TIME ) /HZ ;/* update all temporary addresses in the list */ list_for_each_entry (ift, &idev->tempaddr_list, tmp_list) {int age, max_valid, max_prefered; +bool reparent; -if (ifp != ift->ifpub) -continue ; + reparent = false;
You can collapse initialization where you declare the variable.
Quoted 28 lines
net/ipv6/addrconf.c +16
-1+spin_lock (&ift->lock); +if (ifp != ift->ifpub) { +/* reparent if orphaned temporary address with same +* prefix is found +*/ +if (ipv6_prefix_equal (&ift->addr, &ifp->addr, + ift->prefix_len)) { +in6_ifa_hold (ifp); +in6_ifa_put (ift->ifpub); + ift->ifpub = ifp; + reparent = true; + }else { +spin_unlock (&ift->lock); +continue ; + } + }/* RFC 4941 section 3.3: * If a received option will extend the lifetime of a public @@ -2110,7 +2130,6 @@ static void manage_tempaddrs(struct inet6_dev *idev,if (prefered_lft > max_prefered) prefered_lft = max_prefered; -spin_lock (&ift->lock); flags = ift->flags; ift->valid_lft = valid_lft; ift->prefered_lft = prefered_lft;
net/ipv6/addrconf.c static void manage_tempaddrs(struct inet6_dev *idev, · line 2142
Quoted 5 lines
net/ipv6/addrconf.c +2
-0@@ -2119,6 +2138,15 @@ static void manage_tempaddrs(struct inet6_dev *idev, ift->flags &= ~IFA_F_DEPRECATED ;spin_unlock (&ift->lock); +/* Don't create a temporary address if we reparented one which +* is prefered more than regen_advance
Nit: s/prefered/preferred/
net/ipv6/addrconf.c static void manage_tempaddrs(struct inet6_dev *idev, · line 2147
Quoted 5 lines
net/ipv6/addrconf.c +5
-0+*/ +if (reparent && prefered_lft > regen_advance) { + create = false; +pr_info ("%s: reparent orphaned temporary address\n" , + __func__);
The pr_info() should ideally be removed (or at least made pr_debug()).
Quoted 6 lines
net/ipv6/addrconf.c +2
-0+ } +if (!(flags&IFA_F_TENTATIVE ))ipv6_ifa_notify (0 , ift); }
Am 06.04.2014 22:27, schrieb Daniel Borkmann:
Quoted 77 lines · Heiner Kallweit
Quoted 5 lines
If the kernel takes care of global and temporary addresses it can happen that the global address is deleted from userspace, e.g. by network managers in case the link goes (temporarily) down. In addition to the then orphaned temporary address(es) the next RA will create a new temporary address. Therefore we might end up with more than one non-deprecated temporary address for the same prefix for a longer period of time (>regen_advance). According to RfC 4941 sect. 3.4 this should not happen.
Nit: your commit description should only be ~75 chars wide max
Quoted 19 lines
Fix this by reparenting orphaned temporary addresses.
Signed-off-by Heiner Kallweit <[email protected]>--- net/ipv6/addrconf.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-)net/ipv6/addrconf.c +2
-0@@ -2077,14 +2077,34 @@ static void manage_tempaddrs(struct inet6_dev *idev, {u32 flags;struct inet6_ifaddr *ift; +unsigned long regen_advance;read_lock_bh (&idev->lock); + regen_advance = idev->cnf.regen_max_retry *net/ipv6/addrconf.c static void manage_tempaddrs(struct inet6_dev *idev, · line 2091
Quoted 10 lines
net/ipv6/addrconf.c +4
-2+ idev->cnf.dad_transmits * +NEIGH_VAR (idev->nd_parms,RETRANS_TIME ) /HZ ;/* update all temporary addresses in the list */ list_for_each_entry (ift, &idev->tempaddr_list, tmp_list) {int age, max_valid, max_prefered; +bool reparent; -if (ifp != ift->ifpub) -continue ; + reparent = false;You can collapse initialization where you declare the variable.
Quoted 28 lines
net/ipv6/addrconf.c +16
-1+spin_lock (&ift->lock); +if (ifp != ift->ifpub) { +/* reparent if orphaned temporary address with same +* prefix is found +*/ +if (ipv6_prefix_equal (&ift->addr, &ifp->addr, + ift->prefix_len)) { +in6_ifa_hold (ifp); +in6_ifa_put (ift->ifpub); + ift->ifpub = ifp; + reparent = true; + }else { +spin_unlock (&ift->lock); +continue ; + } + }/* RFC 4941 section 3.3: * If a received option will extend the lifetime of a public @@ -2110,7 +2130,6 @@ static void manage_tempaddrs(struct inet6_dev *idev,if (prefered_lft > max_prefered) prefered_lft = max_prefered; -spin_lock (&ift->lock); flags = ift->flags; ift->valid_lft = valid_lft; ift->prefered_lft = prefered_lft;net/ipv6/addrconf.c static void manage_tempaddrs(struct inet6_dev *idev, · line 2142
Quoted 5 lines
net/ipv6/addrconf.c +2
-0@@ -2119,6 +2138,15 @@ static void manage_tempaddrs(struct inet6_dev *idev, ift->flags &= ~IFA_F_DEPRECATED ;spin_unlock (&ift->lock); +/* Don't create a temporary address if we reparented one which +* is prefered more than regen_advance Nit: s/prefered/preferred/
Quoted 15 lines
net/ipv6/addrconf.c static void manage_tempaddrs(struct inet6_dev *idev, · line 2147
Quoted 5 lines
net/ipv6/addrconf.c +5
-0+*/ +if (reparent && prefered_lft > regen_advance) { + create = false; +pr_info ("%s: reparent orphaned temporary address\n" , + __func__);The
pr_info()should ideally be removed (or at least madepr_debug()).Quoted 6 lines
net/ipv6/addrconf.c +2
-0+ } +if (!(flags&IFA_F_TENTATIVE ))ipv6_ifa_notify (0 , ift); }
Thanks for the hints, will send a revised patch.
Rgds, Heiner