]> sourceware.org Git - glibc.git/commitdiff
inet: Add common IPv6 packet header macros
authorDan Luedtke <danrl@google.com>
Wed, 4 Dec 2024 19:50:22 +0000 (11:50 -0800)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Mon, 13 Jan 2025 13:54:38 +0000 (10:54 -0300)
Adds commonly used IPv6 packet header macros similar to what is available
on NetBSD and FreeBSD in sys/netinet/ip6.h and Android in
libc/include/netinet/ip6.h

Usage example IPV6_VERSION_MASK and IPV6_VERSION:

    if ((ip6->ip6_vfc & IPV6_VERSION_MASK) == IPV6_VERSION)
        return true;

Usage example IPV6_FLOWINFO_MASK:

    ip6->ip6_flow = (flow & IPV6_FLOWINFO_MASK);

The relevant standard is RFC2460 (Internet Protocol, Version 6
Specification). It defines the Internet Protocol version (IPV6_VERSION)
and reduced the size of the flow label field from 24 to 20 bits
(IPV6_FLOWLABEL_MASK). The traffic class and flow label fields together
make up the flow information (IPV6_FLOWINFO_MASK).

Tested on x86_64 GNU/Linux

Signed-off-by: Dan Luedtke <danrl@google.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
inet/netinet/ip6.h

index 3caac7a46dfb0dbe555976a6d35aaf01fe71078b..1edb2e4009100d9f96be0a27bfa5c988664e8f11 100644 (file)
@@ -46,6 +46,17 @@ struct ip6_hdr
 #define ip6_hlim  ip6_ctlun.ip6_un1.ip6_un1_hlim
 #define ip6_hops  ip6_ctlun.ip6_un1.ip6_un1_hlim
 
+#define IPV6_VERSION       0x60
+#define IPV6_VERSION_MASK  0xf0
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define IPV6_FLOWINFO_MASK   0x0fffffff  /* flow info (28 bits) */
+#define IPV6_FLOWLABEL_MASK  0x000fffff  /* flow label (20 bits) */
+#else   /* __BYTE_ORDER == __LITTLE_ENDIAN */
+#define IPV6_FLOWINFO_MASK   0xffffff0f  /* flow info (28 bits) */
+#define IPV6_FLOWLABEL_MASK  0xffff0f00  /* flow label (20 bits) */
+#endif
+
 /* Generic extension header.  */
 struct ip6_ext
   {
This page took 0.041302 seconds and 5 git commands to generate.