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