diff mbox

[GLIBC,v2] inet: avoid redefinition of some structs in kernel

Message ID 1376558891-26221-2-git-send-email-amwang@redhat.com
State Not Applicable, archived
Delegated to: David Miller
Headers show

Commit Message

Amerigo Wang Aug. 15, 2013, 9:28 a.m. UTC
From: Carlos O'Donell <carlos@redhat.com>

- Synchronize linux's `include/uapi/linux/in6.h' 
  with glibc's `inet/netinet/in.h'.
- Synchronize glibc's `inet/netinet/in.h with linux's
  `include/uapi/linux/in6.h'.
- Allow including the headers in either other.
- First header included defines the structures and macros.

Notes:
- You want netinet/in.h to include bits/in.h as early as possible,
  but it needs in_addr so define in_addr early.
- You want bits/in.h included as early as possible so you can use
  the linux specific code to define __USE_KERNEL_DEFS based on
  the _UAPI_* macro definition and use those to cull in.h.
- glibc was missing IPPROTO_MH, added here.

Reported-by: Thomas Backlund <tmb@mageia.org>
Cc: Thomas Backlund <tmb@mageia.org>
Cc: libc-alpha@sourceware.org
Cc: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Cong Wang <amwang@redhat.com>
Signed-off-by: Cong Wang <amwang@redhat.com>

2013-08-13  Carlos O'Donell  <carlos@redhat.com>
	    Cong Wang <amwang@redhat.com>

	* sysdeps/unix/sysv/linux/bits/in.h
	[_UAPI_LINUX_IN6_H]: Define __USE_KERNEL_IPV6_DEFS.
	* inet/netinet/in.h: Move in_addr definition and bits/in.h inclusion
	before __USE_KERNEL_IPV6_DEFS uses.
	* inet/netinet/in.h [!__USE_KERNEL_IPV6_DEFS]: Define IPPROTO_MH, and
	IPPROTO_BEETPH.
	[__USE_KERNEL_IPV6_DEFS]: Don't define any of IPPROTO_*, in6_addr,
	sockaddr_in6, or ipv6_mreq.

---

--
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

Comments

Carlos O'Donell Aug. 16, 2013, 3:15 p.m. UTC | #1
On 08/15/2013 05:28 AM, Cong Wang wrote:
> From: Carlos O'Donell <carlos@redhat.com>
> 
> - Synchronize linux's `include/uapi/linux/in6.h' 
>   with glibc's `inet/netinet/in.h'.
> - Synchronize glibc's `inet/netinet/in.h with linux's
>   `include/uapi/linux/in6.h'.
> - Allow including the headers in either other.
> - First header included defines the structures and macros.
> 
> Notes:
> - You want netinet/in.h to include bits/in.h as early as possible,
>   but it needs in_addr so define in_addr early.
> - You want bits/in.h included as early as possible so you can use
>   the linux specific code to define __USE_KERNEL_DEFS based on
>   the _UAPI_* macro definition and use those to cull in.h.
> - glibc was missing IPPROTO_MH, added here.

Andreas,

Would you mind reviewing this?

I'd like an objective review from another senior glibc reviewer.

The goal here is simple, support including the kernel and glibc
headers in any order and coordinate structure definitions to maintain
the ABI.

The kernel headers often have structures and definitions that are
required by specialized userspace applications, and we'd like those
applications to be easy to write and maintain. Coordinate the headers
is going to make this simpler for everyone.

Cheers,
Carlos.

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

--
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
Andreas Jaeger Aug. 16, 2013, 3:32 p.m. UTC | #2
On 08/15/2013 11:28 AM, Cong Wang wrote:
> From: Carlos O'Donell <carlos@redhat.com>
> 
> - Synchronize linux's `include/uapi/linux/in6.h' 
>   with glibc's `inet/netinet/in.h'.
> - Synchronize glibc's `inet/netinet/in.h with linux's
>   `include/uapi/linux/in6.h'.
> - Allow including the headers in either other.
> - First header included defines the structures and macros.

Let me first say that I really love where this is going and would love
to see more of this work.

Will this work with older kernels as well? Meaning: Can I compile
today's user land programs with a new glibc and Kernel 3.10? My reading
of the patch assumes it does but I would like to hear that you tested it.

The patch itself looks fine, thanks,
Andreas
Carlos O'Donell Aug. 16, 2013, 3:44 p.m. UTC | #3
On 08/16/2013 11:32 AM, Andreas Jaeger wrote:
> On 08/15/2013 11:28 AM, Cong Wang wrote:
>> From: Carlos O'Donell <carlos@redhat.com>
>>
>> - Synchronize linux's `include/uapi/linux/in6.h' 
>>   with glibc's `inet/netinet/in.h'.
>> - Synchronize glibc's `inet/netinet/in.h with linux's
>>   `include/uapi/linux/in6.h'.
>> - Allow including the headers in either other.
>> - First header included defines the structures and macros.
> 
> Let me first say that I really love where this is going and would love
> to see more of this work.

The plan would be to eventually tackle more of the conflicting headers
in a uniform way.

> Will this work with older kernels as well? Meaning: Can I compile
> today's user land programs with a new glibc and Kernel 3.10? My reading
> of the patch assumes it does but I would like to hear that you tested it.

You can indeed take a new glibc, and a new kernel, and old programs
that previously failed to compile will now work. The ABI is maintained
and the headers coordinate.

I did not test this explicitly except through the small test case
I wrote which permutes inclusion order and the use of various
structures defined in the headers.

The only quibble one could have is with Linux. In that if you 
include the Linux headers first you will get more definitions than
required by POSIX e.g. s6_addr16 and s6_add32. However as I note
in the comment this is not a violation of POSIX since POSIX says 
"at least the following member" and that holds true.
 
> The patch itself looks fine, thanks,

Thanks for reviewing.

If the kernel patches get accepted I will check these into
glibc 2.19 for Cong.

Cheers,
Carlos.

--
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
Carlos O'Donell Aug. 16, 2013, 3:47 p.m. UTC | #4
On 08/15/2013 05:28 AM, Cong Wang wrote:
> 2013-08-13  Carlos O'Donell  <carlos@redhat.com>
> 	    Cong Wang <amwang@redhat.com>
> 
> 	* sysdeps/unix/sysv/linux/bits/in.h
> 	[_UAPI_LINUX_IN6_H]: Define __USE_KERNEL_IPV6_DEFS.
> 	* inet/netinet/in.h: Move in_addr definition and bits/in.h inclusion
> 	before __USE_KERNEL_IPV6_DEFS uses.
> 	* inet/netinet/in.h [!__USE_KERNEL_IPV6_DEFS]: Define IPPROTO_MH, and
> 	IPPROTO_BEETPH.
> 	[__USE_KERNEL_IPV6_DEFS]: Don't define any of IPPROTO_*, in6_addr,
> 	sockaddr_in6, or ipv6_mreq.

Cong,

Given that this is a user visible change could you please file
a glibc bugzilla bug in sourceware[1] so we can track the commit and so
that future users can reopen the bug to discuss any defects?

Then you need to add the BZ# to the ChangeLog, and whomever
commits this for you will mark it fixed in the NEWS. We should
also write up a NEWS blurb for this since it's the first explicit
header coordination of it's kind and we should highlight that
so developers take note and help us coordinate more headers.

Cheers,
Carlos.

[1] http://sourceware.org/bugzilla/
--
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
Amerigo Wang Aug. 19, 2013, 1:20 a.m. UTC | #5
On Fri, 2013-08-16 at 11:47 -0400, Carlos O'Donell wrote:
> On 08/15/2013 05:28 AM, Cong Wang wrote:
> > 2013-08-13  Carlos O'Donell  <carlos@redhat.com>
> > 	    Cong Wang <amwang@redhat.com>
> > 
> > 	* sysdeps/unix/sysv/linux/bits/in.h
> > 	[_UAPI_LINUX_IN6_H]: Define __USE_KERNEL_IPV6_DEFS.
> > 	* inet/netinet/in.h: Move in_addr definition and bits/in.h inclusion
> > 	before __USE_KERNEL_IPV6_DEFS uses.
> > 	* inet/netinet/in.h [!__USE_KERNEL_IPV6_DEFS]: Define IPPROTO_MH, and
> > 	IPPROTO_BEETPH.
> > 	[__USE_KERNEL_IPV6_DEFS]: Don't define any of IPPROTO_*, in6_addr,
> > 	sockaddr_in6, or ipv6_mreq.
> 
> Cong,
> 
> Given that this is a user visible change could you please file
> a glibc bugzilla bug in sourceware[1] so we can track the commit and so
> that future users can reopen the bug to discuss any defects?

Done, http://sourceware.org/bugzilla/show_bug.cgi?id=15850


> 
> Then you need to add the BZ# to the ChangeLog, and whomever
> commits this for you will mark it fixed in the NEWS. We should
> also write up a NEWS blurb for this since it's the first explicit
> header coordination of it's kind and we should highlight that
> so developers take note and help us coordinate more headers.
> 

Should I resend this patch with BZ# included?

Thanks!

--
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
Carlos O'Donell Aug. 19, 2013, 6:11 p.m. UTC | #6
On 08/18/2013 09:20 PM, Cong Wang wrote:
> On Fri, 2013-08-16 at 11:47 -0400, Carlos O'Donell wrote:
>> On 08/15/2013 05:28 AM, Cong Wang wrote:
>>> 2013-08-13  Carlos O'Donell  <carlos@redhat.com>
>>> 	    Cong Wang <amwang@redhat.com>
>>>
>>> 	* sysdeps/unix/sysv/linux/bits/in.h
>>> 	[_UAPI_LINUX_IN6_H]: Define __USE_KERNEL_IPV6_DEFS.
>>> 	* inet/netinet/in.h: Move in_addr definition and bits/in.h inclusion
>>> 	before __USE_KERNEL_IPV6_DEFS uses.
>>> 	* inet/netinet/in.h [!__USE_KERNEL_IPV6_DEFS]: Define IPPROTO_MH, and
>>> 	IPPROTO_BEETPH.
>>> 	[__USE_KERNEL_IPV6_DEFS]: Don't define any of IPPROTO_*, in6_addr,
>>> 	sockaddr_in6, or ipv6_mreq.
>>
>> Cong,
>>
>> Given that this is a user visible change could you please file
>> a glibc bugzilla bug in sourceware[1] so we can track the commit and so
>> that future users can reopen the bug to discuss any defects?
> 
> Done, http://sourceware.org/bugzilla/show_bug.cgi?id=15850
 
Perfect.
 
>>
>> Then you need to add the BZ# to the ChangeLog, and whomever
>> commits this for you will mark it fixed in the NEWS. We should
>> also write up a NEWS blurb for this since it's the first explicit
>> header coordination of it's kind and we should highlight that
>> so developers take note and help us coordinate more headers.
>>
> 
> Should I resend this patch with BZ# included?

No need. But the final ChangeLog should have the BZ# in it, and the
committer will add it to the NEWS list of bugs fixed in 2.19.

Cheers,
Carlos.

--
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
Mike Frysinger Aug. 26, 2013, 5:26 a.m. UTC | #7
On Thursday 15 August 2013 05:28:11 Cong Wang wrote:
> From: Carlos O'Donell <carlos@redhat.com>
> 
> - Synchronize linux's `include/uapi/linux/in6.h'
>   with glibc's `inet/netinet/in.h'.
> - Synchronize glibc's `inet/netinet/in.h with linux's
>   `include/uapi/linux/in6.h'.
> - Allow including the headers in either other.
> - First header included defines the structures and macros.
> 
> Notes:
> - You want netinet/in.h to include bits/in.h as early as possible,
>   but it needs in_addr so define in_addr early.
> - You want bits/in.h included as early as possible so you can use
>   the linux specific code to define __USE_KERNEL_DEFS based on
>   the _UAPI_* macro definition and use those to cull in.h.
> - glibc was missing IPPROTO_MH, added here.

can we get something better documented here in a central location ?  having 
the names laid out in a git commit message and in a few leaf headers does not 
lend itself to being easily discoverable.
-mike
Carlos O'Donell Sept. 6, 2013, 4:52 a.m. UTC | #8
On 08/26/2013 01:26 AM, Mike Frysinger wrote:
> On Thursday 15 August 2013 05:28:11 Cong Wang wrote:
>> From: Carlos O'Donell <carlos@redhat.com>
>>
>> - Synchronize linux's `include/uapi/linux/in6.h'
>>   with glibc's `inet/netinet/in.h'.
>> - Synchronize glibc's `inet/netinet/in.h with linux's
>>   `include/uapi/linux/in6.h'.
>> - Allow including the headers in either other.
>> - First header included defines the structures and macros.
>>
>> Notes:
>> - You want netinet/in.h to include bits/in.h as early as possible,
>>   but it needs in_addr so define in_addr early.
>> - You want bits/in.h included as early as possible so you can use
>>   the linux specific code to define __USE_KERNEL_DEFS based on
>>   the _UAPI_* macro definition and use those to cull in.h.
>> - glibc was missing IPPROTO_MH, added here.
> 
> can we get something better documented here in a central location ?  having 
> the names laid out in a git commit message and in a few leaf headers does not 
> lend itself to being easily discoverable.

Care to suggest something?

Cheers,
Carlos.

--
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
diff mbox

Patch

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