net: sync some IP headers with glibc
Subsystems (2)
PATCH 1/1 net: sync some IP headers with glibc
From: Carlos O'Donell <[email protected]>
Solution:
=========
- 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.
Details:
========
The kernel promises not to break the UAPI ABI so I don't see why we can't just have the two userspace headers coordinate?
If you include the kernel headers first you get those, and if you include the glibc headers first you get those, and the following patch arranges a coordination and synchronization between the two.
Let's handle include/uapi/linux/in6.h' from linux, and inet/netinet/in.h' from glibc and ensure they compile in any order and preserve the required ABI.
These two patches pass the following compile tests:
cat >> test1.c <<EOF
#include <netinet/in.h>
#include <linux/in6.h>
int main (void) {
return 0;
}
EOF
gcc -c test1.c
cat >> test2.c <<EOF
#include <linux/in6.h>
#include <netinet/in.h>
int main (void) {
return 0;
}
EOF
gcc -c test2.c
One wrinkle is that the kernel has a different name for one of the members in ipv6_mreq. In the kernel patch we create a macro to cover the uses of the old name, and while that's not entirely clean it's one of the best solutions (aside from an anonymous union which has other issues).
I've reviewed the code and it looks to me like the ABI is assured and everything matches on both sides.
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.
Compile tested and inspected.
---
include/uapi/linux/Kbuild +1 -0
@@ -227,6 +227,7 @@ header-y += kvm_para.h endif header-y += l2tp.h +header-y += libc-compat.h header-y += limits.h header-y += llc.h header-y += loop.h
include/uapi/linux/in.h +48 -25
79 lines not on this page · raw message
include/uapi/linux/in6.h +29 -8
@@ -22,22 +22,29 @@#define _UAPI_LINUX_IN6_H#include <linux/types.h> +#include <linux/libc-compat.h> /* * IPv6 address structure */ - +#if __UAPI_DEF_IN6_ADDRstruct in6_addr {union {__u8 u6_addr8[16 ]; +#if __UAPI_DEF_IN6_ADDR__be16 u6_addr16[8 ];__be32 u6_addr32[4 ]; +#endif } in6_u;#define s6_addr in6_u.u6_addr8 +#if __UAPI_DEF_IN6_ADDR_ALT#define s6_addr16 in6_u.u6_addr16#define s6_addr32 in6_u.u6_addr32 +#endif }; +#endif /* __UAPI_DEF_IN6_ADDR */ +#if __UAPI_DEF_SOCKADDR_IN6 struct sockaddr_in6 { unsigned short int sin6_family; /* AF_INET6 */ __be16 sin6_port; /* Transport layer port # */
@@ -45,7 +52,9 @@ struct sockaddr_in6 {struct in6_addr sin6_addr;/* IPv6 address */ __u32 sin6_scope_id;/* scope id (new in RFC2553) */ }; +#endif /* __UAPI_DEF_SOCKADDR_IN6 */ +#if __UAPI_DEF_IPV6_MREQ struct ipv6_mreq { /* IPv6 multicast address of group */ struct in6_addr ipv6mr_multiaddr;
@@ -53,6 +62,7 @@ struct ipv6_mreq {/* local IPv6 address of interface */ int ipv6mr_ifindex; }; +#endif /* __UAPI_DEF_IVP6_MREQ */ #define ipv6mr_acaddr ipv6mr_multiaddr
@@ -114,13 +124,24 @@ struct in6_flowlabel_req {/* * IPV6 extension headers */ -#define IPPROTO_HOPOPTS 0/* IPv6 hop-by-hop options */ -#define IPPROTO_ROUTING 43/* IPv6 routing header */ -#define IPPROTO_FRAGMENT 44/* IPv6 fragmentation header */ -#define IPPROTO_ICMPV6 58/* ICMPv6 */ -#define IPPROTO_NONE 59/* IPv6 no next header */ -#define IPPROTO_DSTOPTS 60/* IPv6 destination options */ -#define IPPROTO_MH 135/* IPv6 mobility header */ +#if __UAPI_DEF_IPPROTO_V6 +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 /* __UAPI_DEF_IPPROTO_V6 */ /* * IPv6 TLV options.
include/uapi/linux/libc-compat.h new file +103 -0
103 lines not on this page · raw message
PATCH 1/1 inet: avoid redefinition of some structs in kernel
From: Carlos O'Donell <[email protected]>
- 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.
---
ChangeLog +12 -0
@@ -1,3 +1,15 @@ +2013-08-13 Carlos O'Donell <[email protected]> + Cong Wang <[email protected]> + + * 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. + 2013-08-13 Andreas Schwab <[email protected]> [BZ #15749]
inet/netinet/in.h +40 -29
148 lines not on this page · raw message
sysdeps/unix/sysv/linux/bits/in.h +12 -0
@@ -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'. */
David Miller
maintainerFrom: Cong Wang <[email protected]>
Date: Tue, 13 Aug 2013 16:37:33 +0800
include/uapi/linux/in.h line 27
Quoted 8 lines
include/uapi/linux/in.h +1
-2@@ -23,31 +23,54 @@/* Standard well-defined IP protocols. */ enum { -IPPROTO_IP =0 ,/* Dummy protocol for TCP */ -IPPROTO_ICMP =1 ,/* Internet Control Message Protocol */ +IPPROTO_IP =0 ,/* Dummy protocol for TCP. */
Please don't do unrelated things like reformat comments, it makes the path much harder to audit.
include/uapi/linux/in6.h line 35
Quoted 7 lines
include/uapi/linux/in6.h +2
-1- +#if __UAPI_DEF_IN6_ADDR struct in6_addr { union { __u8 u6_addr8[16]; +#if __UAPI_DEF_IN6_ADDR __be16 u6_addr16[8];
The same CPP test twice inside of itself, the second test seems superfluous. I bet this second one was supposed to be __UAPI_DEF_IN6_ADDR_ALT instead of __UAPI_DEF_IN6_ADDR.
include/uapi/linux/in6.h struct in6_flowlabel_req { · line 129
Quoted 10 lines
include/uapi/linux/in6.h +3
-7-#define IPPROTO_HOPOPTS 0/* IPv6 hop-by-hop options */ -#define IPPROTO_ROUTING 43/* IPv6 routing header */ -#define IPPROTO_FRAGMENT 44/* IPv6 fragmentation header */ -#define IPPROTO_ICMPV6 58/* ICMPv6 */ -#define IPPROTO_NONE 59/* IPv6 no next header */ -#define IPPROTO_DSTOPTS 60/* IPv6 destination options */ -#define IPPROTO_MH 135/* IPv6 mobility header */ +#if __UAPI_DEF_IPPROTO_V6 +enum { + IPPROTO_HOPOPTS = 0, /* IPv6 hop-by-hop options */
Again, do not reformat things, it's an unrelated change and makes this patch harder to review.
Quoted 10 lines · David Miller
From: Cong Wang <[email protected]>
Date: Tue, 13 Aug 2013 16:37:33 +0800Quoted 6 lines
include/uapi/linux/in.h +0
-2@@ -23,31 +23,54 @@/* Standard well-defined IP protocols. */ enum { -IPPROTO_IP =0 ,/* Dummy protocol for TCP */ -IPPROTO_ICMP =1 ,/* Internet Control Message Protocol */
Quoted 4 lines
include/uapi/linux/in.h line 26
Quoted 1 line
include/uapi/linux/in.h +1
-0+ IPPROTO_IP = 0, /* Dummy protocol for TCP. */Please don't do unrelated things like reformat comments, it makes the path much harder to audit.
OK.
Quoted 12 lines
include/uapi/linux/in6.h line 35
Quoted 8 lines
include/uapi/linux/in6.h +2
-1- +#if __UAPI_DEF_IN6_ADDR struct in6_addr { union { __u8 u6_addr8[16]; +#if __UAPI_DEF_IN6_ADDR __be16 u6_addr16[8];The same CPP test twice inside of itself, the second test seems superfluous. I bet this second one was supposed to be
__UAPI_DEF_IN6_ADDR_ALTinstead of__UAPI_DEF_IN6_ADDR.
Indeed.
Quoted 14 lines
include/uapi/linux/in6.h struct in6_flowlabel_req { · line 129
Quoted 11 lines
include/uapi/linux/in6.h +3
-7-#define IPPROTO_HOPOPTS 0/* IPv6 hop-by-hop options */ -#define IPPROTO_ROUTING 43/* IPv6 routing header */ -#define IPPROTO_FRAGMENT 44/* IPv6 fragmentation header */ -#define IPPROTO_ICMPV6 58/* ICMPv6 */ -#define IPPROTO_NONE 59/* IPv6 no next header */ -#define IPPROTO_DSTOPTS 60/* IPv6 destination options */ -#define IPPROTO_MH 135/* IPv6 mobility header */ +#if __UAPI_DEF_IPPROTO_V6 +enum { + IPPROTO_HOPOPTS = 0, /* IPv6 hop-by-hop options */Again, do not reformat things, it's an unrelated change and makes this patch harder to review.
Ok.
I will update the patch.
Thanks!
Quoted 13 lines · David Miller
Quoted 1 line
-#define
IPPROTO_HOPOPTS0 /* IPv6 hop-by-hopoptions */
Quoted 1 line
-#define
IPPROTO_ROUTING43 /* IPv6 routingheader */
Quoted 1 line
-#define
IPPROTO_FRAGMENT44 /* IPv6 fragmentationheader */
Quoted 1 line
-#define
IPPROTO_ICMPV658 /*ICMPv6 */
Quoted 1 line
-#define
IPPROTO_NONE59 /* IPv6 no nextheader */
Quoted 1 line
-#define
IPPROTO_DSTOPTS60 /* IPv6 destinationoptions */
Quoted 1 line
-#define
IPPROTO_MH135 /* IPv6 mobility
Quoted 8 lines
header */
include/uapi/linux/in6.h struct in6_flowlabel_req {
Quoted 3 lines
include/uapi/linux/in6.h +3
-0+#if __UAPI_DEF_IPPROTO_V6 +enum { +IPPROTO_HOPOPTS =0 ,/* IPv6 hop-by-hop options */
Again, do not reformat things, it's an unrelated change and makes this patch harder to review.
Hmm, for this one, the original format is hard to keep since this patch changes macros to enum's. What this patch does here looks correct to me, for reference, below is the original code:
#define IPPROTO_HOPOPTS 0 /* IPv6 hop-by-hop options
*/
#define IPPROTO_ROUTING 43 /* IPv6 routing header
*/
#define IPPROTO_FRAGMENT 44 /* IPv6 fragmentation header
*/
#define IPPROTO_ICMPV6 58 /* ICMPv6
*/
#define IPPROTO_NONE 59 /* IPv6 no next header
*/
#define IPPROTO_DSTOPTS 60 /* IPv6 destination options
*/
#define IPPROTO_MH 135 /* IPv6 mobility header
*/
and here is the code after patch:
#if __UAPI_DEF_IPPROTO_V6
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 /* __UAPI_DEF_IPPROTO_V6 */
Or I don't get your point?
Thanks.
David Miller
maintainerFrom: Cong Wang <[email protected]>
Date: Thu, 15 Aug 2013 16:42:43 +0800
Quoted 3 lines
Hmm, for this one, the original format is hard to keep since this patch changes macros to enum's. What this patch does here looks correct to me, for reference, below is the original code:
Fair enough, please resubmit your patches.