Skip to contentSkip to conversation

uapi: Prevent redefinition of struct iphdr

PATCH In review A. Wilcox 4 participants 6 messages Dec 22, 2019 – Dec 30, 2019

Subsystems (3)
lore
Share & tools
lore

A. Wilcox

author
#0 lore raw

PATCH 1/1 uapi: Prevent redefinition of struct iphdr

As with struct ethhdr, the musl libc provides its own definition of the iphdr struct. This guard ensures software like net-tools builds correctly on the musl libc.

The __UAPI_DEF_IPHDR definition is in ip.h itself to prevent the issue in commit da360299b673 ("uapi/if_ether.h: move __UAPI_DEF_ETHHDR libc define") from being seen here.

---
 include/uapi/linux/ip.h | 8 ++++++++
 1 file changed, 8 insertions(+)
include/uapi/linux/ip.h +8 -0
index e42d13b55cf3..d34a0d295672 100644
@@ -83,6 +83,13 @@
 
 #define IPV4_BEET_PHMAXLEN 8
 
+/* Allow libcs to deactivate this - musl has its own copy in <netinet/ip.h> */
+
+#ifndef __UAPI_DEF_IPHDR
+#define __UAPI_DEF_IPHDR	1
+#endif
+
+#if __UAPI_DEF_IPHDR
 struct iphdr {
 #if defined(__LITTLE_ENDIAN_BITFIELD)
 	__u8	ihl:4,
@@ -104,6 +111,7 @@ struct iphdr {
 	__be32	daddr;
 	/*The options start here. */
 };
+#endif
 
 
 struct ip_auth_hdr {
Signature · 1 line
2.22.1
maintainer
#1 lore raw

From: "A. Wilcox" <[email protected]>
Date: Sun, 22 Dec 2019 00:02:27 -0600

include/uapi/linux/ip.h line 90

Quoted 9 lines
include/uapi/linux/ip.h +5 -0
@@ -83,6 +83,13 @@
 
 #define IPV4_BEET_PHMAXLEN 8
 
+/* Allow libcs to deactivate this - musl has its own copy in <netinet/ip.h> */
+
+#ifndef __UAPI_DEF_IPHDR
+#define __UAPI_DEF_IPHDR	1
+#endif

How is this a musl-only problem? I see that glibc also defines struct iphdr in netinet/ip.h, so why doesn't it also suffer from this?

I find it really strange that this, therefore, only happens for musl and we haven't had thousands of reports of this conflict with glibc over the years.

I want an explanation, and suitably appropriate adjustments to the commit message and comments of this change.

Thank you.

#2 lore raw
Quoted 7 lines · David Miller

From: "A. Wilcox" <[email protected]>
Date: Sun, 22 Dec 2019 00:02:27 -0600

Quoted 4 lines
include/uapi/linux/ip.h +0 -0
@@ -83,6 +83,13 @@
 
 #define IPV4_BEET_PHMAXLEN 8
 
Quoted 7 lines

include/uapi/linux/ip.h line 90

Quoted 5 lines
include/uapi/linux/ip.h +5 -0
+/* Allow libcs to deactivate this - musl has its own copy in <netinet/ip.h> */
+
+#ifndef __UAPI_DEF_IPHDR
+#define __UAPI_DEF_IPHDR	1
+#endif

How is this a musl-only problem?

I don't think it is, unless glibc's includes linux/ip.h to get the definition, which does not seem to be the case -- at least not on the Debian system I had handy to check on.

Quoted 2 lines

I see that glibc also defines struct iphdr
in netinet/ip.h, so why doesn't it also suffer from this?

Maybe it does.

Quoted 3 lines

I find it really strange that this, therefore, only happens for musl and we haven't had thousands of reports of this conflict with glibc over the years.

It's possible that there's software that's including just one of the headers conditional on __GLIBC__, and including both otherwise, or something like that. Arguably this should be considered unsupported usage; there are plenty of headers where that doesn't work and shouldn't be expected to.

Quoted 2 lines

I want an explanation, and suitably appropriate adjustments to the commit message and comments of this change.

Agreed. Commit messages should not imply that something is a musl-specific workaround when it's generally the right thing to do.

Rich

maintainer
#3 lore raw

From: Rich Felker <[email protected]>
Date: Wed, 25 Dec 2019 20:05:15 -0500

Quoted 10 lines · David Miller
Quoted 3 lines

I find it really strange that this, therefore, only happens for musl and we haven't had thousands of reports of this conflict with glibc over the years.

It's possible that there's software that's including just one of the headers conditional on __GLIBC__, and including both otherwise, or something like that. Arguably this should be considered unsupported usage; there are plenty of headers where that doesn't work and shouldn't be expected to.

I don't buy that, this is waaaaaay too common a header to use.

Please investigate.

#4 lore raw
Quoted 8 lines · David Miller

From: Rich Felker <[email protected]>
Date: Wed, 25 Dec 2019 20:05:15 -0500

Quoted 5 lines · David Miller
Quoted 3 lines

I find it really strange that this, therefore, only happens for musl and we haven't had thousands of reports of this conflict with glibc over the years.

Quoted 7 lines
Quoted 5 lines

It's possible that there's software that's including just one of the headers conditional on __GLIBC__, and including both otherwise, or something like that. Arguably this should be considered unsupported usage; there are plenty of headers where that doesn't work and shouldn't be expected to.

I don't buy that, this is waaaaaay too common a header to use.

In case of net-tools, only <linux/ip.h> is included, and never <netinet/ip.h> directly. Chances are in musl the indirect include tree happens to be different and conflicting, while in glibc it is not.

Quoted 3 lines

Please investigate.

Daniel

#5 lore raw
Quoted 15 lines · Daniel Kolesa
Quoted 14 lines · David Miller

From: Rich Felker <[email protected]>
Date: Wed, 25 Dec 2019 20:05:15 -0500

Quoted 10 lines · David Miller
Quoted 3 lines

I find it really strange that this, therefore, only happens for musl and we haven't had thousands of reports of this conflict with glibc over the years.

It's possible that there's software that's including just one of the headers conditional on __GLIBC__, and including both otherwise, or something like that. Arguably this should be considered unsupported usage; there are plenty of headers where that doesn't work and shouldn't be expected to.

Quoted 6 lines
Quoted 1 line

I don't buy that, this is waaaaaay too common a header to use.

In case of net-tools, only <linux/ip.h> is included, and never <netinet/ip.h> directly. Chances are in musl the indirect include tree happens to be different and conflicting, while in glibc it is not.

musl has no indirect inclusion of netinet/ip.h from standard headers, but does include it from netinet/ip_icmp.h. It seems glibc only does this conditional on __USE_MISC, which doesn't make much sense to me since this is not a standardized header with namespace rules, but normally __USE_MISC is defined anyway on glibc so I kinda doubt this is the difference.

Any other ideas?

Rich