Skip to contentSkip to conversation

net: ipv6: allow explicitly choosing optimistic addresses

PATCH Applied Erik Kline 4 participants 4 messages Feb 4, 2015 – Feb 5, 2015

Subsystems (3)
lore
Share & tools
lore

Erik Kline

author
#0 lore raw

PATCH v4 1/1 net: ipv6: allow explicitly choosing optimistic addresses

RFC 4429 ("Optimistic DAD") states that optimistic addresses should be treated as deprecated addresses. From section 2.1:

Unless noted otherwise, components of the IPv6 protocol stack should treat addresses in the Optimistic state equivalently to those in the Deprecated state, indicating that the address is available for use but should not be used if another suitable address is available.

Optimistic addresses are indeed avoided when other addresses are available (i.e. at source address selection time), but they have not heretofore been available for things like explicit bind() and sendmsg() with struct in6_pktinfo, etc.

This change makes optimistic addresses treated more like deprecated addresses than tentative ones.

---
 include/net/addrconf.h |  3 +++
 net/ipv6/addrconf.c    | 19 +++++++++++++++++--
 net/ipv6/ndisc.c       |  4 +++-
 3 files changed, 23 insertions(+), 3 deletions(-)
include/net/addrconf.h +3 -0
index d13573b..80456f7 100644
@@ -62,6 +62,9 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg);
 
 int ipv6_chk_addr(struct net *net, const struct in6_addr *addr,
 		  const struct net_device *dev, int strict);
+int ipv6_chk_addr_and_flags(struct net *net, const struct in6_addr *addr,
+			    const struct net_device *dev, int strict,
+			    u32 banned_flags);
 
 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
 int ipv6_chk_home_addr(struct net *net, const struct in6_addr *addr);
net/ipv6/addrconf.c +17 -2
index f7c8bbe..62900ae 100644
@@ -1519,15 +1519,30 @@ static int ipv6_count_addresses(struct inet6_dev *idev)
 int ipv6_chk_addr(struct net *net, const struct in6_addr *addr,
 		  const struct net_device *dev, int strict)
 {
+	return ipv6_chk_addr_and_flags(net, addr, dev, strict, IFA_F_TENTATIVE);
+}
+EXPORT_SYMBOL(ipv6_chk_addr);
+
+int ipv6_chk_addr_and_flags(struct net *net, const struct in6_addr *addr,
+			    const struct net_device *dev, int strict,
+			    u32 banned_flags)
+{
 	struct inet6_ifaddr *ifp;
 	unsigned int hash = inet6_addr_hash(addr);
+	u32 ifp_flags;
 
 	rcu_read_lock_bh();
 	hlist_for_each_entry_rcu(ifp, &inet6_addr_lst[hash], addr_lst) {
 		if (!net_eq(dev_net(ifp->idev->dev), net))
 			continue;
+		/* Decouple optimistic from tentative for evaluation here.
+		 * Ban optimistic addresses explicitly, when required.
+		 */
+		ifp_flags = (ifp->flags&IFA_F_OPTIMISTIC)
+			    ? (ifp->flags&~IFA_F_TENTATIVE)
+			    : ifp->flags;
 		if (ipv6_addr_equal(&ifp->addr, addr) &&
-		    !(ifp->flags&IFA_F_TENTATIVE) &&
+		    !(ifp_flags&banned_flags) &&
 		    (dev == NULL || ifp->idev->dev == dev ||
 		     !(ifp->scope&(IFA_LINK|IFA_HOST) || strict))) {
 			rcu_read_unlock_bh();
@@ -1538,7 +1553,7 @@ int ipv6_chk_addr(struct net *net, const struct in6_addr *addr,
 	rcu_read_unlock_bh();
 	return 0;
 }
-EXPORT_SYMBOL(ipv6_chk_addr);
+EXPORT_SYMBOL(ipv6_chk_addr_and_flags);
 
 static bool ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr,
 			       struct net_device *dev)
net/ipv6/ndisc.c +3 -1
index 6828667..113fc6c 100644
@@ -655,7 +655,9 @@ static void ndisc_solicit(struct neighbour *neigh, struct sk_buff *skb)
 	struct in6_addr *target = (struct in6_addr *)&neigh->primary_key;
 	int probes = atomic_read(&neigh->probes);
 
-	if (skb && ipv6_chk_addr(dev_net(dev), &ipv6_hdr(skb)->saddr, dev, 1))
+	if (skb && ipv6_chk_addr_and_flags(dev_net(dev), &ipv6_hdr(skb)->saddr,
+					   dev, 1,
+					   IFA_F_TENTATIVE|IFA_F_OPTIMISTIC))
 		saddr = &ipv6_hdr(skb)->saddr;
 	probes -= NEIGH_VAR(neigh->parms, UCAST_PROBES);
 	if (probes < 0) {
Signature · 1 line
2.2.0.rc0.207.ga3a616c
Acked-by on v4 1/1
#1 lore raw

net/ipv6/addrconf.c static int ipv6_count_addresses(struct inet6_dev *idev) · line 1540

Quoted 3 lines · Erik Kline
net/ipv6/addrconf.c +3 -0
+               /* Decouple optimistic from tentative for evaluation here.
+                * Ban optimistic addresses explicitly, when required.
+                */

I don't find this comment particularly useful, but I suppose there's no harm in having it.

net/ipv6/addrconf.c static int ipv6_count_addresses(struct inet6_dev *idev) · line 1546

Quoted 7 lines
net/ipv6/addrconf.c +4 -1
+               ifp_flags = (ifp->flags&IFA_F_OPTIMISTIC)
+                           ? (ifp->flags&~IFA_F_TENTATIVE)
+                           : ifp->flags;
                if (ipv6_addr_equal(&ifp->addr, addr) &&
-                   !(ifp->flags&IFA_F_TENTATIVE) &&
+                   !(ifp_flags&banned_flags) &&
                    (dev == NULL || ifp->idev->dev == dev ||

That looks correct now. It's also nicer than what I had proposed.

Adding the new ipv6_chk_addr_and_flags function is definitely less churn than the alternative of updating all the callers of ipv6_chk_addr (19 files) to pass in the extra argument. Not sure which is preferred, the churn or the new function.

Acked-by on v4 1/1
#2 lore raw
In reply to Erik Kline

Hi,

Quoted 14 lines · Erik Kline

RFC 4429 ("Optimistic DAD") states that optimistic addresses should be treated as deprecated addresses. From section 2.1:

Unless noted otherwise, components of the IPv6 protocol stack should treat addresses in the Optimistic state equivalently to those in the Deprecated state, indicating that the address is available for use but should not be used if another suitable address is available.

Optimistic addresses are indeed avoided when other addresses are available (i.e. at source address selection time), but they have not heretofore been available for things like explicit bind() and sendmsg() with struct in6_pktinfo, etc.

Quoted 4 lines

This change makes optimistic addresses treated more like deprecated addresses than tentative ones.

Quoted 57 lines
---
 include/net/addrconf.h |  3 +++
 net/ipv6/addrconf.c    | 19 +++++++++++++++++--
 net/ipv6/ndisc.c       |  4 +++-
 3 files changed, 23 insertions(+), 3 deletions(-)
include/net/addrconf.h +3 -0
index d13573b..80456f7 100644
@@ -62,6 +62,9 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg);
 
 int ipv6_chk_addr(struct net *net, const struct in6_addr *addr,
 		  const struct net_device *dev, int strict);
+int ipv6_chk_addr_and_flags(struct net *net, const struct in6_addr *addr,
+			    const struct net_device *dev, int strict,
+			    u32 banned_flags);
 
 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
 int ipv6_chk_home_addr(struct net *net, const struct in6_addr *addr);
net/ipv6/addrconf.c +16 -1
index f7c8bbe..62900ae 100644
@@ -1519,15 +1519,30 @@ static int ipv6_count_addresses(struct inet6_dev *idev)
 int ipv6_chk_addr(struct net *net, const struct in6_addr *addr,
 		  const struct net_device *dev, int strict)
 {
+	return ipv6_chk_addr_and_flags(net, addr, dev, strict, IFA_F_TENTATIVE);
+}
+EXPORT_SYMBOL(ipv6_chk_addr);
+
+int ipv6_chk_addr_and_flags(struct net *net, const struct in6_addr *addr,
+			    const struct net_device *dev, int strict,
+			    u32 banned_flags)
+{
 	struct inet6_ifaddr *ifp;
 	unsigned int hash = inet6_addr_hash(addr);
+	u32 ifp_flags;
 
 	rcu_read_lock_bh();
 	hlist_for_each_entry_rcu(ifp, &inet6_addr_lst[hash], addr_lst) {
 		if (!net_eq(dev_net(ifp->idev->dev), net))
 			continue;
+		/* Decouple optimistic from tentative for evaluation here.
+		 * Ban optimistic addresses explicitly, when required.
+		 */
+		ifp_flags = (ifp->flags&IFA_F_OPTIMISTIC)
+			    ? (ifp->flags&~IFA_F_TENTATIVE)
+			    : ifp->flags;
 		if (ipv6_addr_equal(&ifp->addr, addr) &&
-		    !(ifp->flags&IFA_F_TENTATIVE) &&
+		    !(ifp_flags&banned_flags) &&
 		    (dev == NULL || ifp->idev->dev == dev ||
 		     !(ifp->scope&(IFA_LINK|IFA_HOST) || strict))) {
 			rcu_read_unlock_bh();

net/ipv6/addrconf.c int ipv6_chk_addr(struct net *net, const struct in6_addr *addr, · line 1556

Quoted 5 lines
net/ipv6/addrconf.c +1 -1
@@ -1538,7 +1553,7 @@ int ipv6_chk_addr(struct net *net, const struct in6_addr *addr,
 	rcu_read_unlock_bh();
 	return 0;
 }
-EXPORT_SYMBOL(ipv6_chk_addr);
+EXPORT_SYMBOL(ipv6_chk_addr_and_flags);

Nit: I don't think the export is necessary.

Bye,
Hannes

maintainer Applied
#3 lore raw
In reply to Erik Kline

From: Erik Kline <[email protected]>
Date: Wed, 4 Feb 2015 20:01:23 +0900

Quoted 14 lines

RFC 4429 ("Optimistic DAD") states that optimistic addresses should be treated as deprecated addresses. From section 2.1:

Unless noted otherwise, components of the IPv6 protocol stack should treat addresses in the Optimistic state equivalently to those in the Deprecated state, indicating that the address is available for use but should not be used if another suitable address is available.

Optimistic addresses are indeed avoided when other addresses are available (i.e. at source address selection time), but they have not heretofore been available for things like explicit bind() and sendmsg() with struct in6_pktinfo, etc.

Quoted 4 lines

This change makes optimistic addresses treated more like deprecated addresses than tentative ones.

Applied, thanks.