* 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
This commit is contained in:
Andrey V. Elsukov 2014-09-11 10:27:59 +00:00
parent 7524f39b9f
commit 573791d01c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=271421
2 changed files with 14 additions and 52 deletions

View File

@ -649,7 +649,7 @@ int in6_cksum_pseudo(struct ip6_hdr *, uint32_t, uint8_t, uint16_t);
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;

View File

@ -235,62 +235,24 @@ scope6_get(struct ifnet *ifp, struct scope6_id *idlist)
* 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;
}
if (IPV6_ADDR_MC_SCOPE(addr) == 0x0f)
return (IPV6_ADDR_SCOPE_GLOBAL);
return (IPV6_ADDR_MC_SCOPE(addr));
}
/*
* 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 (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);
}
/*