Skip to content
Snippets Groups Projects
Commit 9e5d7174 authored by Oleg Hahm's avatar Oleg Hahm
Browse files

ipv6: fix and improve check for global address

* embedded IPv4 addresses are considered as global
* remove check for multicast
* consolidate loopback and unspecified check
parent 465321fc
No related branches found
No related tags found
No related merge requests found
...@@ -255,20 +255,6 @@ static inline bool ng_ipv6_addr_is_loopback(const ng_ipv6_addr_t *addr) ...@@ -255,20 +255,6 @@ static inline bool ng_ipv6_addr_is_loopback(const ng_ipv6_addr_t *addr)
(byteorder_ntohll(addr->u64[1]) == 1); (byteorder_ntohll(addr->u64[1]) == 1);
} }
/**
* @brief Check if @p addr is global unicast address.
*
* @see <a href="http://tools.ietf.org/html/rfc4291#section-2.5.4">
* RFC 4291, section 2.5.4
* </a>
*
* @param[in] addr An IPv6 address.
*
* @return true, if @p addr is global unicast address,
* @return false, otherwise.
*/
bool ng_ipv6_addr_is_global_unicast(const ng_ipv6_addr_t *addr);
/** /**
* @brief Checks if @p addr is a IPv4-compatible IPv6 address. * @brief Checks if @p addr is a IPv4-compatible IPv6 address.
* *
...@@ -386,6 +372,38 @@ static inline bool ng_ipv6_addr_is_unique_local_unicast(const ng_ipv6_addr_t *ad ...@@ -386,6 +372,38 @@ static inline bool ng_ipv6_addr_is_unique_local_unicast(const ng_ipv6_addr_t *ad
return ((addr->u8[0] == 0xfc) || (addr->u8[0] == 0xfd)); return ((addr->u8[0] == 0xfc) || (addr->u8[0] == 0xfd));
} }
/**
* @brief Check if @p addr is global unicast address.
*
* @see <a href="http://tools.ietf.org/html/rfc4291#section-2.5.4">
* RFC 4291, section 2.5.4
* </a>
*
* @param[in] addr An IPv6 address.
*
* @return true, if @p addr is global unicast address,
* @return false, otherwise.
*/
static inline bool ng_ipv6_addr_is_global(const ng_ipv6_addr_t *addr)
{
/* first check for multicast with global scope */
if (ng_ipv6_addr_is_multicast(addr)) {
return ((addr->u8[1] & 0x0f) == NG_IPV6_ADDR_MCAST_SCP_GLOBAL);
}
else {
/* for unicast check if: */
/* - not unspecific or loopback */
return (!((addr->u64[0].u64 == 0) &&
((byteorder_ntohll(addr->u64[1]) & (0xfffffffffffffffe)) == 0)) &&
/* - not link-local */
(byteorder_ntohll(addr->u64[0]) != 0xfe80000000000000) &&
/* - not site-local */
((byteorder_ntohs(addr->u16[0]) & 0xffc0) !=
NG_IPV6_ADDR_SITE_LOCAL_PREFIX));
}
}
/** /**
* @brief Check if @p addr is solicited-node multicast address. * @brief Check if @p addr is solicited-node multicast address.
* *
......
...@@ -77,20 +77,6 @@ void ng_ipv6_addr_init_prefix(ng_ipv6_addr_t *out, const ng_ipv6_addr_t *prefix, ...@@ -77,20 +77,6 @@ void ng_ipv6_addr_init_prefix(ng_ipv6_addr_t *out, const ng_ipv6_addr_t *prefix,
out->u8[bytes] |= (prefix->u8[bytes] & mask); out->u8[bytes] |= (prefix->u8[bytes] & mask);
} }
} }
bool ng_ipv6_addr_is_global_unicast(const ng_ipv6_addr_t *addr)
{
return (!(ng_ipv6_addr_is_unique_local_unicast(addr)) &&
!(ng_ipv6_addr_is_unspecified(addr)) &&
!(ng_ipv6_addr_is_loopback(addr)) &&
!(ng_ipv6_addr_is_ipv4_compat(addr)) &&
!(ng_ipv6_addr_is_ipv4_mapped(addr)) &&
!(ng_ipv6_addr_is_site_local(addr)) &&
!(ng_ipv6_addr_is_link_local(addr)) &&
!(ng_ipv6_addr_is_multicast(addr)));
}
/** /**
* @} * @}
*/ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment