Patchwork [RFC,1/2] ipv6: introdcue __ipv6_addr_needs_scope_id and ipv6_iface_scope_id helper functions

login
register
mail settings
Submitter Hannes Frederic Sowa
Date Feb. 11, 2013, 11:13 a.m.
Message ID <20130211111303.GA23991@order.stressinduktion.org>
Download mbox | patch
Permalink /patch/219572/
State RFC
Delegated to: David Miller
Headers show

Comments

Hannes Frederic Sowa - Feb. 11, 2013, 11:13 a.m.
This strictly a RFC only (I also left out my signed-off). This patch
introduces helper functions to set and check for the need of scope ids.

Suggested-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Cc: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
---
 include/net/ipv6.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)
YOSHIFUJI Hideaki / 吉藤英明 - Feb. 11, 2013, 1:36 p.m.
Hannes Frederic Sowa wrote:
> This strictly a RFC only (I also left out my signed-off). This patch
> introduces helper functions to set and check for the need of scope ids.
> 
> Suggested-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
> Cc: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
> ---
>  include/net/ipv6.h | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/include/net/ipv6.h b/include/net/ipv6.h
> index 851d541..1f61dc9 100644
> --- a/include/net/ipv6.h
> +++ b/include/net/ipv6.h
> @@ -319,6 +319,19 @@ static inline int ipv6_addr_src_scope(const struct in6_addr *addr)
>  	return __ipv6_addr_src_scope(__ipv6_addr_type(addr));
>  }
>  
> +static inline bool __ipv6_addr_needs_scope_id(int type)
> +{
> +	return type != IPV6_ADDR_ANY &&
> +	       !(type & IPV6_ADDR_LOOPBACK && type & IPV6_ADDR_UNICAST) &&
> +	       __ipv6_addr_src_scope(type) <= IPV6_ADDR_SCOPE_LINKLOCAL;
> +}
> +
> +static inline __u32 ipv6_iface_scope_id(const struct in6_addr *addr,
> +					unsigned int iface)
> +{
> +	return __ipv6_addr_needs_scope_id(__ipv6_addr_type(addr)) ? iface : 0;
> +}
> +
>  static inline int ipv6_addr_cmp(const struct in6_addr *a1, const struct in6_addr *a2)
>  {
>  	return memcmp(a1, a2, sizeof(struct in6_addr));
> 

Yes, something like that.    

--yoshfuji
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/include/net/ipv6.h b/include/net/ipv6.h
index 851d541..1f61dc9 100644
--- a/include/net/ipv6.h
+++ b/include/net/ipv6.h
@@ -319,6 +319,19 @@  static inline int ipv6_addr_src_scope(const struct in6_addr *addr)
 	return __ipv6_addr_src_scope(__ipv6_addr_type(addr));
 }
 
+static inline bool __ipv6_addr_needs_scope_id(int type)
+{
+	return type != IPV6_ADDR_ANY &&
+	       !(type & IPV6_ADDR_LOOPBACK && type & IPV6_ADDR_UNICAST) &&
+	       __ipv6_addr_src_scope(type) <= IPV6_ADDR_SCOPE_LINKLOCAL;
+}
+
+static inline __u32 ipv6_iface_scope_id(const struct in6_addr *addr,
+					unsigned int iface)
+{
+	return __ipv6_addr_needs_scope_id(__ipv6_addr_type(addr)) ? iface : 0;
+}
+
 static inline int ipv6_addr_cmp(const struct in6_addr *a1, const struct in6_addr *a2)
 {
 	return memcmp(a1, a2, sizeof(struct in6_addr));