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