Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 11 Sep 2014 10:27:59 +0000 (UTC)
From:      "Andrey V. Elsukov" <ae@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r271421 - head/sys/netinet6
Message-ID:  <201409111027.s8BARxdj046785@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ae
Date: Thu Sep 11 10:27:59 2014
New Revision: 271421
URL: http://svnweb.freebsd.org/changeset/base/271421

Log:
  * constify argument of in6_addrscope();
  * use IN6_IS_ADDR_XXX() macro instead of hardcoded values;
  * for multicast addresses just return scope value, the only exception
    is addresses with 0x0F scope value (RFC 4291 p2.7.0);
  
  Obtained from:	Yandex LLC
  Sponsored by:	Yandex LLC

Modified:
  head/sys/netinet6/in6.h
  head/sys/netinet6/scope6.c

Modified: head/sys/netinet6/in6.h
==============================================================================
--- head/sys/netinet6/in6.h	Thu Sep 11 07:16:15 2014	(r271420)
+++ head/sys/netinet6/in6.h	Thu Sep 11 10:27:59 2014	(r271421)
@@ -649,7 +649,7 @@ int	in6_cksum_pseudo(struct ip6_hdr *, u
 int	in6_cksum(struct mbuf *, u_int8_t, u_int32_t, u_int32_t);
 int	in6_localaddr(struct in6_addr *);
 int	in6_localip(struct in6_addr *);
-int	in6_addrscope(struct in6_addr *);
+int	in6_addrscope(const struct in6_addr *);
 struct	in6_ifaddr *in6_ifawithifp(struct ifnet *, struct in6_addr *);
 extern void in6_if_up(struct ifnet *);
 struct sockaddr;

Modified: head/sys/netinet6/scope6.c
==============================================================================
--- head/sys/netinet6/scope6.c	Thu Sep 11 07:16:15 2014	(r271420)
+++ head/sys/netinet6/scope6.c	Thu Sep 11 10:27:59 2014	(r271421)
@@ -235,62 +235,24 @@ scope6_get(struct ifnet *ifp, struct sco
  * Get a scope of the address. Node-local, link-local, site-local or global.
  */
 int
-in6_addrscope(struct in6_addr *addr)
+in6_addrscope(const struct in6_addr *addr)
 {
-	int scope;
-
-	if (addr->s6_addr[0] == 0xfe) {
-		scope = addr->s6_addr[1] & 0xc0;
-
-		switch (scope) {
-		case 0x80:
-			return IPV6_ADDR_SCOPE_LINKLOCAL;
-			break;
-		case 0xc0:
-			return IPV6_ADDR_SCOPE_SITELOCAL;
-			break;
-		default:
-			return IPV6_ADDR_SCOPE_GLOBAL; /* just in case */
-			break;
-		}
-	}
-
-
-	if (addr->s6_addr[0] == 0xff) {
-		scope = addr->s6_addr[1] & 0x0f;
 
+	if (IN6_IS_ADDR_MULTICAST(addr)) {
 		/*
-		 * due to other scope such as reserved,
-		 * return scope doesn't work.
+		 * Addresses with reserved value F must be treated as
+		 * global multicast addresses.
 		 */
-		switch (scope) {
-		case IPV6_ADDR_SCOPE_INTFACELOCAL:
-			return IPV6_ADDR_SCOPE_INTFACELOCAL;
-			break;
-		case IPV6_ADDR_SCOPE_LINKLOCAL:
-			return IPV6_ADDR_SCOPE_LINKLOCAL;
-			break;
-		case IPV6_ADDR_SCOPE_SITELOCAL:
-			return IPV6_ADDR_SCOPE_SITELOCAL;
-			break;
-		default:
-			return IPV6_ADDR_SCOPE_GLOBAL;
-			break;
-		}
-	}
-
-	/*
-	 * Regard loopback and unspecified addresses as global, since
-	 * they have no ambiguity.
-	 */
-	if (bcmp(&in6addr_loopback, addr, sizeof(*addr) - 1) == 0) {
-		if (addr->s6_addr[15] == 1) /* loopback */
-			return IPV6_ADDR_SCOPE_LINKLOCAL;
-		if (addr->s6_addr[15] == 0) /* unspecified */
-			return IPV6_ADDR_SCOPE_GLOBAL; /* XXX: correct? */
-	}
-
-	return IPV6_ADDR_SCOPE_GLOBAL;
+		if (IPV6_ADDR_MC_SCOPE(addr) == 0x0f)
+			return (IPV6_ADDR_SCOPE_GLOBAL);
+		return (IPV6_ADDR_MC_SCOPE(addr));
+	}
+	if (IN6_IS_ADDR_LINKLOCAL(addr) ||
+	    IN6_IS_ADDR_LOOPBACK(addr))
+		return (IPV6_ADDR_SCOPE_LINKLOCAL);
+	if (IN6_IS_ADDR_SITELOCAL(addr))
+		return (IPV6_ADDR_SCOPE_SITELOCAL);
+	return (IPV6_ADDR_SCOPE_GLOBAL);
 }
 
 /*



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201409111027.s8BARxdj046785>