ce426f
commit 6c82a2f8d7c8e21e39237225c819f182ae438db3
ce426f
Author: Carlos O'Donell <carlos@redhat.com>
ce426f
Date:   Fri Sep 6 01:02:30 2013 -0400
ce426f
ce426f
    Coordinate IPv6 definitions for Linux and glibc
ce426f
    
ce426f
    This change synchronizes the glibc headers with the Linux kernel
ce426f
    headers and arranges to coordinate the definition of structures
ce426f
    already defined the Linux kernel UAPI headers.
ce426f
    
ce426f
    It is now safe to include glibc's netinet/in.h or Linux's linux/in6.h
ce426f
    in any order in a userspace application and you will get the same
ce426f
    ABI. The ABI is guaranteed by UAPI and glibc.
ce426f
ce426f
diff --git a/inet/netinet/in.h b/inet/netinet/in.h
ce426f
index 89e3813..05c77e2 100644
ce426f
--- a/inet/netinet/in.h
ce426f
+++ b/inet/netinet/in.h
ce426f
@@ -26,13 +26,21 @@
ce426f
 
ce426f
 __BEGIN_DECLS
ce426f
 
ce426f
+/* Internet address.  */
ce426f
+typedef uint32_t in_addr_t;
ce426f
+struct in_addr
ce426f
+  {
ce426f
+    in_addr_t s_addr;
ce426f
+  };
ce426f
+
ce426f
+/* Get system-specific definitions.  */
ce426f
+#include <bits/in.h>
ce426f
+
ce426f
 /* Standard well-defined IP protocols.  */
ce426f
 enum
ce426f
   {
ce426f
     IPPROTO_IP = 0,	   /* Dummy protocol for TCP.  */
ce426f
 #define IPPROTO_IP		IPPROTO_IP
ce426f
-    IPPROTO_HOPOPTS = 0,   /* IPv6 Hop-by-Hop options.  */
ce426f
-#define IPPROTO_HOPOPTS		IPPROTO_HOPOPTS
ce426f
     IPPROTO_ICMP = 1,	   /* Internet Control Message Protocol.  */
ce426f
 #define IPPROTO_ICMP		IPPROTO_ICMP
ce426f
     IPPROTO_IGMP = 2,	   /* Internet Group Management Protocol. */
ce426f
@@ -55,10 +63,6 @@ enum
ce426f
 #define IPPROTO_DCCP		IPPROTO_DCCP
ce426f
     IPPROTO_IPV6 = 41,     /* IPv6 header.  */
ce426f
 #define IPPROTO_IPV6		IPPROTO_IPV6
ce426f
-    IPPROTO_ROUTING = 43,  /* IPv6 routing header.  */
ce426f
-#define IPPROTO_ROUTING		IPPROTO_ROUTING
ce426f
-    IPPROTO_FRAGMENT = 44, /* IPv6 fragmentation header.  */
ce426f
-#define IPPROTO_FRAGMENT	IPPROTO_FRAGMENT
ce426f
     IPPROTO_RSVP = 46,	   /* Reservation Protocol.  */
ce426f
 #define IPPROTO_RSVP		IPPROTO_RSVP
ce426f
     IPPROTO_GRE = 47,	   /* General Routing Encapsulation.  */
ce426f
@@ -67,14 +71,10 @@ enum
ce426f
 #define IPPROTO_ESP		IPPROTO_ESP
ce426f
     IPPROTO_AH = 51,       /* authentication header.  */
ce426f
 #define IPPROTO_AH		IPPROTO_AH
ce426f
-    IPPROTO_ICMPV6 = 58,   /* ICMPv6.  */
ce426f
-#define IPPROTO_ICMPV6		IPPROTO_ICMPV6
ce426f
-    IPPROTO_NONE = 59,     /* IPv6 no next header.  */
ce426f
-#define IPPROTO_NONE		IPPROTO_NONE
ce426f
-    IPPROTO_DSTOPTS = 60,  /* IPv6 destination options.  */
ce426f
-#define IPPROTO_DSTOPTS		IPPROTO_DSTOPTS
ce426f
     IPPROTO_MTP = 92,	   /* Multicast Transport Protocol.  */
ce426f
 #define IPPROTO_MTP		IPPROTO_MTP
ce426f
+    IPPROTO_BEETPH = 94,   /* IP option pseudo header for BEET.  */
ce426f
+#define IPPROTO_BEETPH		IPPROTO_BEETPH
ce426f
     IPPROTO_ENCAP = 98,	   /* Encapsulation Header.  */
ce426f
 #define IPPROTO_ENCAP		IPPROTO_ENCAP
ce426f
     IPPROTO_PIM = 103,	   /* Protocol Independent Multicast.  */
ce426f
@@ -90,6 +90,28 @@ enum
ce426f
     IPPROTO_MAX
ce426f
   };
ce426f
 
ce426f
+/* If __USER_KERNEL_IPV6_DEFS is defined then the user has included the kernel
ce426f
+   network headers first and we should use those ABI-identical definitions
ce426f
+   instead of our own.  */
ce426f
+#ifndef __USE_KERNEL_IPV6_DEFS
ce426f
+enum
ce426f
+  {
ce426f
+    IPPROTO_HOPOPTS = 0,   /* IPv6 Hop-by-Hop options.  */
ce426f
+#define IPPROTO_HOPOPTS		IPPROTO_HOPOPTS
ce426f
+    IPPROTO_ROUTING = 43,  /* IPv6 routing header.  */
ce426f
+#define IPPROTO_ROUTING		IPPROTO_ROUTING
ce426f
+    IPPROTO_FRAGMENT = 44, /* IPv6 fragmentation header.  */
ce426f
+#define IPPROTO_FRAGMENT	IPPROTO_FRAGMENT
ce426f
+    IPPROTO_ICMPV6 = 58,   /* ICMPv6.  */
ce426f
+#define IPPROTO_ICMPV6		IPPROTO_ICMPV6
ce426f
+    IPPROTO_NONE = 59,     /* IPv6 no next header.  */
ce426f
+#define IPPROTO_NONE		IPPROTO_NONE
ce426f
+    IPPROTO_DSTOPTS = 60,  /* IPv6 destination options.  */
ce426f
+#define IPPROTO_DSTOPTS		IPPROTO_DSTOPTS
ce426f
+    IPPROTO_MH = 135,      /* IPv6 mobility header.  */
ce426f
+#define IPPROTO_MH		IPPROTO_MH
ce426f
+  };
ce426f
+#endif /* !__USE_KERNEL_IPV6_DEFS */
ce426f
 
ce426f
 /* Type to represent a port.  */
ce426f
 typedef uint16_t in_port_t;
ce426f
@@ -134,15 +156,6 @@ enum
ce426f
     IPPORT_USERRESERVED = 5000
ce426f
   };
ce426f
 
ce426f
-
ce426f
-/* Internet address.  */
ce426f
-typedef uint32_t in_addr_t;
ce426f
-struct in_addr
ce426f
-  {
ce426f
-    in_addr_t s_addr;
ce426f
-  };
ce426f
-
ce426f
-
ce426f
 /* Definitions of the bits in an Internet address integer.
ce426f
 
ce426f
    On subnets, host and network parts are found according to
ce426f
@@ -191,7 +204,7 @@ struct in_addr
ce426f
 #define INADDR_ALLRTRS_GROUP    ((in_addr_t) 0xe0000002) /* 224.0.0.2 */
ce426f
 #define INADDR_MAX_LOCAL_GROUP  ((in_addr_t) 0xe00000ff) /* 224.0.0.255 */
ce426f
 
ce426f
-
ce426f
+#ifndef __USE_KERNEL_IPV6_DEFS
ce426f
 /* IPv6 address */
ce426f
 struct in6_addr
ce426f
   {
ce426f
@@ -209,6 +222,7 @@ struct in6_addr
ce426f
 # define s6_addr32		__in6_u.__u6_addr32
ce426f
 #endif
ce426f
   };
ce426f
+#endif /* !__USE_KERNEL_IPV6_DEFS */
ce426f
 
ce426f
 extern const struct in6_addr in6addr_any;        /* :: */
ce426f
 extern const struct in6_addr in6addr_loopback;   /* ::1 */
ce426f
@@ -233,6 +247,7 @@ struct sockaddr_in
ce426f
 			   sizeof (struct in_addr)];
ce426f
   };
ce426f
 
ce426f
+#ifndef __USE_KERNEL_IPV6_DEFS
ce426f
 /* Ditto, for IPv6.  */
ce426f
 struct sockaddr_in6
ce426f
   {
ce426f
@@ -242,7 +257,7 @@ struct sockaddr_in6
ce426f
     struct in6_addr sin6_addr;	/* IPv6 address */
ce426f
     uint32_t sin6_scope_id;	/* IPv6 scope-id */
ce426f
   };
ce426f
-
ce426f
+#endif /* !__USE_KERNEL_IPV6_DEFS */
ce426f
 
ce426f
 #if defined __USE_MISC || defined __USE_GNU
ce426f
 /* IPv4 multicast request.  */
ce426f
@@ -268,7 +283,7 @@ struct ip_mreq_source
ce426f
   };
ce426f
 #endif
ce426f
 
ce426f
-
ce426f
+#ifndef __USE_KERNEL_IPV6_DEFS
ce426f
 /* Likewise, for IPv6.  */
ce426f
 struct ipv6_mreq
ce426f
   {
ce426f
@@ -278,7 +293,7 @@ struct ipv6_mreq
ce426f
     /* local interface */
ce426f
     unsigned int ipv6mr_interface;
ce426f
   };
ce426f
-
ce426f
+#endif /* !__USE_KERNEL_IPV6_DEFS */
ce426f
 
ce426f
 #if defined __USE_MISC || defined __USE_GNU
ce426f
 /* Multicast group request.  */
ce426f
@@ -349,10 +364,6 @@ struct group_filter
ce426f
 				      * sizeof (struct sockaddr_storage)))
ce426f
 #endif
ce426f
 
ce426f
-
ce426f
-/* Get system-specific definitions.  */
ce426f
-#include <bits/in.h>
ce426f
-
ce426f
 /* Functions to convert between host and network byte order.
ce426f
 
ce426f
    Please note that these functions normally take `unsigned long int' or
ce426f
diff --git a/sysdeps/unix/sysv/linux/bits/in.h b/sysdeps/unix/sysv/linux/bits/in.h
ce426f
index e959b33..d763ce9 100644
ce426f
--- a/sysdeps/unix/sysv/linux/bits/in.h
ce426f
+++ b/sysdeps/unix/sysv/linux/bits/in.h
ce426f
@@ -21,6 +21,18 @@
ce426f
 # error "Never use <bits/in.h> directly; include <netinet/in.h> instead."
ce426f
 #endif
ce426f
 
ce426f
+/* If the application has already included linux/in6.h from a linux-based
ce426f
+   kernel then we will not define the IPv6 IPPROTO_* defines, in6_addr (nor the
ce426f
+   defines), sockaddr_in6, or ipv6_mreq.  The ABI used by the linux-kernel and
ce426f
+   glibc match exactly.  Neither the linux kernel nor glibc should break this
ce426f
+   ABI without coordination.  */
ce426f
+#ifdef _UAPI_LINUX_IN6_H
ce426f
+/* This is not quite the same API since the kernel always defines s6_addr16 and
ce426f
+   s6_addr32. This is not a violation of POSIX since POSIX says "at least the
ce426f
+   following member" and that holds true.  */
ce426f
+# define __USE_KERNEL_IPV6_DEFS
ce426f
+#endif
ce426f
+
ce426f
 /* Options for use with `getsockopt' and `setsockopt' at the IP level.
ce426f
    The first word in the comment at the right is the data type used;
ce426f
    "bool" means a boolean value stored in an `int'.  */