xtables: fix compilation with musl
PATCH 1/2 xtables: fix compilation with musl
Only include <linux/if_ether.h> if glibc is used.
Fixes errors in the form of:
In file included from /home/nick/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-11.2.0_musl/include/netinet/ether.h:8,
from xtables.c:2238:
/home/nick/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-11.2.0_musl/include/netinet/if_ether.h:115:8: error: redefinition of 'struct ethhdr'
115 | struct ethhdr {
| ^~~~~~
In file included from xtables.c:48:
/home/nick/openwrt/build_dir/target-aarch64_cortex-a53_musl/linux-mediatek_mt7622/linux-5.15.38/user_headers/include/linux/if_ether.h:168:8: note: originally defined here
168 | struct ethhdr {
| ^~~~~~make[5]: *** [Makefile:471: libxtables_la-xtables.lo] Error 1
--- libxtables/xtables.c | 2 ++ 1 file changed, 2 insertions(+)
libxtables/xtables.c +2 -0
@@ -45,7 +45,9 @@#include <xtables.h> #include <limits.h> /* INT_MAX in ip_tables.h/ip6_tables.h */ +#if defined(__GLIBC__)#include <linux/if_ether.h> /* ETH_ALEN */ +#endif #include <linux/netfilter_ipv4/ip_tables.h> #include <linux/netfilter_ipv6/ip6_tables.h> #include <libiptc/libxtc.h>
Signature · 1 line
2.36.1
PATCH 2/2 xshared: fix compilation with musl
Gcc complains about missing types. Include <sys/types.h> to fix it.
Fixes errors in the form of:
In file included from xtables-legacy-multi.c:5:
xshared.h:83:56: error: unknown type name 'u_int16_t'; did you mean 'uint16_t'?
83 | set_option(unsigned int *options, unsigned int option, u_int16_t *invflg,
| ^~~~~~~~~
| uint16_tmake[6]: *** [Makefile:712: xtables_legacy_multi-xtables-legacy-multi.o] Error 1
--- iptables/xshared.h | 1 + 1 file changed, 1 insertion(+)
iptables/xshared.h +1 -0
@@ -4,6 +4,7 @@#include <limits.h> #include <stdbool.h> #include <stdint.h> +#include <sys/types.h> #include <netinet/in.h> #include <net/if.h> #include <linux/netfilter_arp/arp_tables.h>
Signature · 1 line
2.36.1
Phil Sutter
reviewerRe: [PATCH iptables 2/2] xshared: fix compilation with musl
Quoted 9 lines · Nick Hainke
Gcc complains about missing types. Include <
sys/types.h> to fix it.Fixes errors in the form of:
In file included from xtables-legacy-multi.c:5:
xshared.h:83:56: error: unknown type name 'u_int16_t'; did you mean 'uint16_t'?83 | set_option(unsigned int *options, unsigned int option, u_int16_t *invflg, | ^~~~~~~~~ | uint16_tmake[6]: *** [Makefile:712: xtables_legacy_multi-xtables-legacy-multi.o] Error 1
Does it work if you change the type to uint16_t instead? This looks like fixing for a typo in f647f61f273a1 ("xtables: Make invflags 16bit wide") which I didn't notice.
Thanks, Phil
PATCH 1/1 treewide: use uint* instead of u_int*
From: Nick Hainke <[email protected]>
Gcc complains about missing types. Two commits introduced u_int* instead of uint*. Use uint treewide.
Fixes errors in the form of:
In file included from xtables-legacy-multi.c:5:
xshared.h:83:56: error: unknown type name 'u_int16_t'; did you mean 'uint16_t'?
83 | set_option(unsigned int *options, unsigned int option, u_int16_t *invflg,
| ^~~~~~~~~
| uint16_t
make[6]: *** [Makefile:712: xtables_legacy_multi-xtables-legacy-multi.o] Error 1
specifying port ranges")
--- extensions/libxt_conntrack.c | 2 +- iptables/xshared.c | 2 +- iptables/xshared.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
extensions/libxt_conntrack.c +1 -1
@@ -778,7 +778,7 @@ matchinfo_print(const void *ip, const struct xt_entry_match *match, int numeric,static void conntrack_dump_ports (const char *prefix,const char *opt, -u_int16_t port_low,u_int16_t port_high) +uint16_t port_low,uint16_t port_high) {if (port_high ==0 || port_low == port_high)printf (" %s%s %u" , prefix, opt, port_low);
iptables/xshared.c +1 -1
@@ -1025,7 +1025,7 @@ static const int inverse_for_options[NUMBER_OF_OPT] = };void -set_option (unsigned int *options,unsigned int option,u_int16_t *invflg, +set_option (unsigned int *options,unsigned int option,uint16_t *invflg,bool invert) {if (*options & option)
iptables/xshared.h +1 -1
@@ -80,7 +80,7 @@ struct xtables_target;#define IPT_INV_ARPHRD 0x0800void -set_option (unsigned int *options,unsigned int option,u_int16_t *invflg, +set_option (unsigned int *options,unsigned int option,uint16_t *invflg,bool invert);/**
Signature · 1 line
2.36.1
Re: [PATCH] treewide: use uint* instead of u_int*
Quoted 4 lines · On Monday 2022-05-16 08:47, [email protected] wrote:
From: Nick Hainke <[email protected]>
Gcc complains about missing types. Two commits introduced u_int* instead of uint*. Use uint treewide.
I approve of this.
There are, however, a few more instances of u_int* in the source tree, they could be fixed up in the same go.
Quoted 4 lines
extensions/libxt_conntrack.c | 2 +- iptables/xshared.c | 2 +- iptables/xshared.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
PATCH 1/1 treewide: use uint* instead of u_int*
From: Nick Hainke <[email protected]>
Gcc complains about missing types. Some commits introduced u_int* instead of uint*. Use uint treewide.
Fixes errors in the form of:
In file included from xtables-legacy-multi.c:5:
xshared.h:83:56: error: unknown type name 'u_int16_t'; did you mean 'uint16_t'?
83 | set_option(unsigned int *options, unsigned int option, u_int16_t *invflg,
| ^~~~~~~~~
| uint16_t
make[6]: *** [Makefile:712: xtables_legacy_multi-xtables-legacy-multi.o] Error 1
--- extensions/libxt_conntrack.c | 2 +- include/libipq/libipq.h | 6 +++--- include/libiptc/libxtc.h | 2 +- include/linux/netfilter_arp/arpt_mangle.h | 2 +- iptables/xshared.c | 2 +- iptables/xshared.h | 2 +- libipq/ipq_create_handle.3 | 2 +- libipq/ipq_set_mode.3 | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-)
extensions/libxt_conntrack.c +1 -1
@@ -778,7 +778,7 @@ matchinfo_print(const void *ip, const struct xt_entry_match *match, int numeric,static void conntrack_dump_ports (const char *prefix,const char *opt, -u_int16_t port_low,u_int16_t port_high) +uint16_t port_low,uint16_t port_high) {if (port_high ==0 || port_low == port_high)printf (" %s%s %u" , prefix, opt, port_low);
include/libipq/libipq.h +3 -3
@@ -48,19 +48,19 @@ typedef unsigned long ipq_id_t;struct ipq_handle {int fd; -u_int8_t blocking; +uint8_t blocking;struct sockaddr_nl local;struct sockaddr_nl peer; }; -struct ipq_handle *ipq_create_handle (u_int32_t flags,u_int32_t protocol); +struct ipq_handle *ipq_create_handle (uint32_t flags,uint32_t protocol);int ipq_destroy_handle (struct ipq_handle *h);ssize_t ipq_read (const struct ipq_handle *h,unsigned char *buf,size_t len,int timeout); -int ipq_set_mode (const struct ipq_handle *h,u_int8_t mode,size_t len); +int ipq_set_mode (const struct ipq_handle *h,uint8_t mode,size_t len);ipq_packet_msg_t *ipq_get_packet (const unsigned char *buf);
include/libiptc/libxtc.h +1 -1
@@ -10,7 +10,7 @@ extern "C" {#endif #ifndef XT_MIN_ALIGN -/* xt_entry has pointers and u_int64_t's in it, so if you align to +/* xt_entry has pointers and uint64_t's in it, so if you align to it, you'll also align to any crazy matches and targets someone might write */ #define XT_MIN_ALIGN (__alignof__(struct xt_entry))
include/linux/netfilter_arp/arpt_mangle.h +1 -1
@@ -13,7 +13,7 @@ struct arpt_mangleunion {struct in_addr tgt_ip; } u_t; -u_int8_t flags; +uint8_t flags;int target; };
iptables/xshared.c +1 -1
@@ -1025,7 +1025,7 @@ static const int inverse_for_options[NUMBER_OF_OPT] = };void -set_option (unsigned int *options,unsigned int option,u_int16_t *invflg, +set_option (unsigned int *options,unsigned int option,uint16_t *invflg,bool invert) {if (*options & option)
iptables/xshared.h +1 -1
@@ -80,7 +80,7 @@ struct xtables_target;#define IPT_INV_ARPHRD 0x0800void -set_option (unsigned int *options,unsigned int option,u_int16_t *invflg, +set_option (unsigned int *options,unsigned int option,uint16_t *invflg,bool invert);/**
libipq/ipq_create_handle.3 +1 -1
@@ -24,7 +24,7 @@ ipq_create_handle, ipq_destroy_handle \(em create and destroy libipq handles. .br .B #include <libipq.h> .sp -.BI "struct ipq_handle *ipq_create_handle(u_int32_t " flags ", u_int32_t " protocol ");" +.BI "struct ipq_handle *ipq_create_handle(uint32_t " flags ", uint32_t " protocol ");" .br .BI "int ipq_destroy_handle(struct ipq_handle *" h ); .SH DESCRIPTION
libipq/ipq_set_mode.3 +1 -1
@@ -24,7 +24,7 @@ ipq_set_mode \(em set the ip_queue queuing mode .br .B #include <libipq.h> .sp -.BI "int ipq_set_mode(const struct ipq_handle *" h ", u_int8_t " mode ", size_t " range ); +.BI "int ipq_set_mode(const struct ipq_handle *" h ", uint8_t " mode ", size_t " range ); .SH DESCRIPTION The .B ipq_set_mode
Signature · 1 line
2.36.1
Phil Sutter
reviewerRe: [PATCH] treewide: use uint* instead of u_int*
On Mon, May 16, 2022 at 06:16:41PM +0200, [email protected] wrote:
[...]
Quoted 6 lines
include/libipq/libipq.h +0
-0@@ -48,19 +48,19 @@ typedef unsigned long ipq_id_t;struct ipq_handle
include/libipq/libipq.h typedef unsigned long ipq_id_t; · line 56
Quoted 10 lines
include/libipq/libipq.h +2
-2{int fd; -u_int8_t blocking; +uint8_t blocking;struct sockaddr_nl local;struct sockaddr_nl peer; }; -struct ipq_handle *ipq_create_handle (u_int32_t flags,u_int32_t protocol); +struct ipq_handle *ipq_create_handle (uint32_t flags,uint32_t protocol);
Might this break API compatibility? ABI won't change, but I suppose users would have to include stdint.h prior to this header. Are we safe if we change the include from sys/types.h to stdint.h in line 27 of that file?
[...]
include/linux/netfilter_arp/arpt_mangle.h struct arpt_mangle · line 18
Quoted 12 lines
include/linux/netfilter_arp/arpt_mangle.h +1
-1@@ -13,7 +13,7 @@ struct arpt_mangleunion {struct in_addr tgt_ip; } u_t; -u_int8_t flags; +uint8_t flags;int target; };
This is a kernel-header. The type was changed to __u8 in kernel repo, so we should use that instead.
Thanks, Phil
Re: [PATCH] treewide: use uint* instead of u_int*
Quoted 9 lines · Phil Sutter
include/libipq/libipq.h typedef unsigned long ipq_id_t; · line 51
Quoted 4 lines
+++
b/include/libipq/libipq.hinclude/libipq/libipq.h +1
-1-u_int8_t blocking; +uint8_t blocking;Might this break API compatibility? ABI won't change, but I suppose users would have to include
stdint.hprior to this header. Are we safe if we change the include fromsys/types.htostdint.hin line 27 of that file?
Always include what you use, so yeah, libipq.h should include stdint.h.
Phil Sutter
reviewerRe: [PATCH] treewide: use uint* instead of u_int*
Quoted 11 lines · Jan Engelhardt
Quoted 9 lines · Phil Sutter
include/libipq/libipq.h typedef unsigned long ipq_id_t; · line 51
Quoted 4 lines
+++
b/include/libipq/libipq.hinclude/libipq/libipq.h +1
-1-u_int8_t blocking; +uint8_t blocking;Might this break API compatibility? ABI won't change, but I suppose users would have to include
stdint.hprior to this header. Are we safe if we change the include fromsys/types.htostdint.hin line 27 of that file?
Quoted 1 line
Always include what you use, so yeah,
libipq.hshould includestdint.h.
Thanks. Patch pushed with the two changes I suggested.
Thanks, Phil
Re: [PATCH] treewide: use uint* instead of u_int*
Thanks for pushing. Sorry, for being absent.
Quoted 13 lines · Phil Sutter
Quoted 9 lines · Jan Engelhardt
Quoted 7 lines · Phil Sutter
include/libipq/libipq.h typedef unsigned long ipq_id_t; · line 51
Quoted 3 lines
+++
b/include/libipq/libipq.hinclude/libipq/libipq.h +1
-1-u_int8_t blocking; +uint8_t blocking;Might this break API compatibility? ABI won't change, but I suppose users would have to include
stdint.hprior to this header. Are we safe if we change the include fromsys/types.htostdint.hin line 27 of that file?Always include what you use, so yeah,
libipq.hshould includestdint.h.Thanks. Patch pushed with the two changes I suggested.
Thanks, Phil
Phil Sutter
reviewerHi,
Quoted 1 line · Nick Hainke
Only include <
linux/if_ether.h> if glibc is used.
This looks like a bug in musl? OTOH explicit include of linux/if_ether.h was added in commit c5d9a723b5159 ("fix build for missing ETH_ALEN definition"), despite netinet/ether.h being included in line 2248 of libxtables/xtables.c. So maybe *also* a bug in bionic?!
Cheers, Phil
Quoted 7 lines · Phil Sutter
Quoted 1 line · Nick Hainke
Only include <
linux/if_ether.h> if glibc is used.This looks like a bug in musl? OTOH explicit include of
linux/if_ether.hwas added in commitc5d9a723b5159("fix build for missingETH_ALENdefinition"), despitenetinet/ether.hbeing included in line 2248 oflibxtables/xtables.c. So maybe *also* a bug in bionic?!
You stripped the email you're replying to, and while I'm on lkml and netdev - with my personal account - I'm not (apparently) subscribed to netfilter-devel (or I'm not subscribed from work account). Either way, if my search-fu is correct you're replying to
https://marc.info/?l=netfilter-devel&m=165254651011397&w=2
+#if defined(__GLIBC__)
#include <linux/if_ether.h> /* ETH_ALEN */
+#endif
and you're presumably CC'ing me due to
which added the include in the first place...:
fix build for missing ETH_ALEN definition
(this is needed at least with bionic)
+#include <linux/if_ether.h> /* ETH_ALEN */
Based on the above, clearly adding an 'if defined GLIBC' wrapper will break bionic...
and presumably glibc doesn't care whether the #include is done one way or the other?
Obviously it could be '#if !defined MUSL' instead...
As for the fix? And whether glibc or musl or bionic are wrong or not... Utterly uncertain...
Though, I will point out #include's 2000 lines into a .c file are kind of funky.
Ultimately I find
https://android.git.corp.google.com/platform/external/iptables/+/7608e136bd495fe734ad18a6897dd4425e1a633b%5E%21/
+#ifdef __BIONIC__
+#include <linux/if_ether.h> /* ETH_ALEN */
+#endif
which is in aosp to this day... see:
https://android.git.corp.google.com/platform/external/iptables/+/refs/heads/master/libxtables/xtables.c#48
If I revert that (ie. remove the above 3 lines), then aosp compilation fails:
external/iptables/libxtables/xtables.c:2144:45: error: use of undeclared identifier 'ETH_ALEN'
static const unsigned char mac_type_unicast[ETH_ALEN] = {};
^...etc...
which suggests the "#include <netinet/ether.h>" immediately before that isn't sufficient.
I think that should include
https://cs.android.com/android/platform/superproject/+/master:bionic/libc/include/netinet/ether.h
which should #include <netinet/if_ether.h> which is
https://cs.android.com/android/platform/superproject/+/master:bionic/libc/include/netinet/if_ether.h
which should #include <linux/if_ether.h>
but... only #if defined(__USE_BSD)
is the problem perhaps the lack of __USE_BSD?
And indeed defining __USE_BSD just before the include:
+#define __USE_BSD 1
#include <netinet/ether.h>
fixes the build on aosp (with the 3 lines still removed).
But I have no idea if we should or should not #define __USE_BSD ... And who / what is actually wrong...
Phil Sutter
reviewerHi Maciej,
Quoted 4 lines · Maciej Żenczykowski
Quoted 3 lines · Phil Sutter
Quoted 1 line · Nick Hainke
Only include <
linux/if_ether.h> if glibc is used.
Quoted 8 lines
Quoted 4 lines
This looks like a bug in musl? OTOH explicit include of
linux/if_ether.hwas added in commitc5d9a723b5159("fix build for missingETH_ALENdefinition"), despitenetinet/ether.hbeing included in line 2248 oflibxtables/xtables.c. So maybe *also* a bug in bionic?!You stripped the email you're replying to, and while I'm on lkml and netdev - with my personal account - I'm not (apparently) subscribed to netfilter-devel (or I'm not subscribed from work account).
Oh, sorry for the caused inconvenience.
Quoted 7 lines
Either way, if my search-fu is correct you're replying to
https://marc.info/?l=netfilter-devel&m=165254651011397&w=2libxtables/xtables.c +2
-0+#if defined(__GLIBC__)#include <linux/if_ether.h> /* ETH_ALEN */ +#endif
Quoted 5 lines
and you're presumably CC'ing me due to
which added the include in the first place...:
That's correct. I assumed that you added the include for a reason and it's breaking Nick's use-case, the two of you want to have a word with each other. :)
Quoted 9 lines
fix build for missing
ETH_ALENdefinition
(this is needed at least with bionic)+#include <
linux/if_ether.h> /*ETH_ALEN*/Based on the above, clearly adding an 'if defined GLIBC' wrapper will break bionic...
and presumably glibc doesn't care whether the #include is done one way or the other?
With glibc, netinet/ether.h includes netinet/if_ether.h which in turn includes linux/if_ether.h where finally ETH_ALEN is defined.
In xtables.c we definitely need netinet/ether.h for ether_aton() declaration.
Quoted 1 line
Obviously it could be '#if !defined MUSL' instead...
Could ...
Quoted 4 lines
As for the fix? And whether glibc or musl or bionic are wrong or not... Utterly uncertain...
Though, I will point out #include's 2000 lines into a .c file are kind of funky.
ACK!
Review
Quoted 6 lines
Ultimately I find
https://android.git.corp.google.com/platform/external/iptables/+/7608e136bd495fe734ad18a6897dd4425e1a633b%5E%21/(quoted diff) +3
-0+#ifdef __BIONIC__ +#include <linux/if_ether.h> /* ETH_ALEN */ +#endif
While I think musl not catching the "double" include is a bug, I'd prefer the ifdef __BIONIC__ solution since it started the "but my libc needs this" game.
Nick, if the above change fixes musl builds for you, would you mind submitting it formally along with a move of the netinet/ether.h include from mid-file to top?
Thanks, Phil
Quoted 74 lines · Phil Sutter
Hi Maciej,
Quoted 4 lines · Maciej Żenczykowski
Quoted 3 lines · Phil Sutter
Quoted 1 line · Nick Hainke
Only include <
linux/if_ether.h> if glibc is used.Quoted 8 lines
Quoted 4 lines
This looks like a bug in musl? OTOH explicit include of
linux/if_ether.hwas added in commitc5d9a723b5159("fix build for missingETH_ALENdefinition"), despitenetinet/ether.hbeing included in line 2248 oflibxtables/xtables.c. So maybe *also* a bug in bionic?!You stripped the email you're replying to, and while I'm on lkml and netdev - with my personal account - I'm not (apparently) subscribed to netfilter-devel (or I'm not subscribed from work account).
Oh, sorry for the caused inconvenience.
Quoted 7 lines
Either way, if my search-fu is correct you're replying to
https://marc.info/?l=netfilter-devel&m=165254651011397&w=2libxtables/xtables.c +2
-0+#if defined(__GLIBC__)#include <linux/if_ether.h> /* ETH_ALEN */ +#endif Quoted 5 lines
and you're presumably CC'ing me due to
which added the include in the first place...:
That's correct. I assumed that you added the include for a reason and it's breaking Nick's use-case, the two of you want to have a word with each other. :)
Quoted 9 lines
fix build for missing
ETH_ALENdefinition
(this is needed at least with bionic)+#include <
linux/if_ether.h> /*ETH_ALEN*/Based on the above, clearly adding an 'if defined GLIBC' wrapper will break bionic...
and presumably glibc doesn't care whether the #include is done one way or the other?With glibc,
netinet/ether.hincludesnetinet/if_ether.hwhich in turn includeslinux/if_ether.hwhere finallyETH_ALENis defined.In
xtables.cwe definitely neednetinet/ether.hforether_aton()declaration.Quoted 1 line
Obviously it could be '#if !defined MUSL' instead...
Could ...
Quoted 4 lines
As for the fix? And whether glibc or musl or bionic are wrong or not... Utterly uncertain...
Though, I will point out #include's 2000 lines into a .c file are kind of funky.
ACK!
Review
Quoted 6 lines
Ultimately I find
https://android.git.corp.google.com/platform/external/iptables/+/7608e136bd495fe734ad18a6897dd4425e1a633b%5E%21/(quoted diff) +3
-0+#ifdef __BIONIC__ +#include <linux/if_ether.h> /* ETH_ALEN */ +#endifWhile I think musl not catching the "double" include is a bug, I'd prefer the ifdef
__BIONIC__solution since it started the "but my libc needs this" game.
Quoted 5 lines
Nick, if the above change fixes musl builds for you, would you mind submitting it formally along with a move of the
netinet/ether.hinclude from mid-file to top?Thanks, Phil
Any thoughts about the rest of my email - wrt. #define __USE_BSD
- do you know how that is supposed to work?
Phil Sutter
reviewerQuoted 75 lines · Maciej Żenczykowski
Quoted 74 lines · Phil Sutter
Hi Maciej,
Quoted 4 lines · Maciej Żenczykowski
Quoted 3 lines · Phil Sutter
Quoted 1 line · Nick Hainke
Only include <
linux/if_ether.h> if glibc is used.Quoted 8 lines
Quoted 4 lines
This looks like a bug in musl? OTOH explicit include of
linux/if_ether.hwas added in commitc5d9a723b5159("fix build for missingETH_ALENdefinition"), despitenetinet/ether.hbeing included in line 2248 oflibxtables/xtables.c. So maybe *also* a bug in bionic?!You stripped the email you're replying to, and while I'm on lkml and netdev - with my personal account - I'm not (apparently) subscribed to netfilter-devel (or I'm not subscribed from work account).
Oh, sorry for the caused inconvenience.
Quoted 7 lines
Either way, if my search-fu is correct you're replying to
https://marc.info/?l=netfilter-devel&m=165254651011397&w=2libxtables/xtables.c +2
-0+#if defined(__GLIBC__)#include <linux/if_ether.h> /* ETH_ALEN */ +#endif Quoted 5 lines
and you're presumably CC'ing me due to
which added the include in the first place...:
That's correct. I assumed that you added the include for a reason and it's breaking Nick's use-case, the two of you want to have a word with each other. :)
Quoted 9 lines
fix build for missing
ETH_ALENdefinition
(this is needed at least with bionic)+#include <
linux/if_ether.h> /*ETH_ALEN*/Based on the above, clearly adding an 'if defined GLIBC' wrapper will break bionic...
and presumably glibc doesn't care whether the #include is done one way or the other?With glibc,
netinet/ether.hincludesnetinet/if_ether.hwhich in turn includeslinux/if_ether.hwhere finallyETH_ALENis defined.In
xtables.cwe definitely neednetinet/ether.hforether_aton()declaration.Quoted 1 line
Obviously it could be '#if !defined MUSL' instead...
Could ...
Quoted 4 lines
As for the fix? And whether glibc or musl or bionic are wrong or not... Utterly uncertain...
Though, I will point out #include's 2000 lines into a .c file are kind of funky.
ACK!
Review
Quoted 6 lines
Ultimately I find
https://android.git.corp.google.com/platform/external/iptables/+/7608e136bd495fe734ad18a6897dd4425e1a633b%5E%21/(quoted diff) +3
-0+#ifdef __BIONIC__ +#include <linux/if_ether.h> /* ETH_ALEN */ +#endifWhile I think musl not catching the "double" include is a bug, I'd prefer the ifdef
__BIONIC__solution since it started the "but my libc needs this" game.
Quoted 8 lines
Quoted 5 lines
Nick, if the above change fixes musl builds for you, would you mind submitting it formally along with a move of the
netinet/ether.hinclude from mid-file to top?Thanks, Phil
Any thoughts about the rest of my email - wrt. #define
__USE_BSD
- do you know how that is supposed to work?
No, but isn't this a detail of bionic header layout?
Cheers, Phil
Quoted 81 lines · Phil Sutter
Quoted 79 lines · Maciej Żenczykowski
Quoted 78 lines · Phil Sutter
Hi Maciej,
Quoted 4 lines · Maciej Żenczykowski
Quoted 3 lines · Phil Sutter
Quoted 1 line · Nick Hainke
Only include <
linux/if_ether.h> if glibc is used.Quoted 8 lines
Quoted 4 lines
This looks like a bug in musl? OTOH explicit include of
linux/if_ether.hwas added in commitc5d9a723b5159("fix build for missingETH_ALENdefinition"), despitenetinet/ether.hbeing included in line 2248 oflibxtables/xtables.c. So maybe *also* a bug in bionic?!You stripped the email you're replying to, and while I'm on lkml and netdev - with my personal account - I'm not (apparently) subscribed to netfilter-devel (or I'm not subscribed from work account).
Oh, sorry for the caused inconvenience.
Quoted 7 lines
Either way, if my search-fu is correct you're replying to
https://marc.info/?l=netfilter-devel&m=165254651011397&w=2libxtables/xtables.c +2
-0+#if defined(__GLIBC__)#include <linux/if_ether.h> /* ETH_ALEN */ +#endif Quoted 5 lines
and you're presumably CC'ing me due to
which added the include in the first place...:
That's correct. I assumed that you added the include for a reason and it's breaking Nick's use-case, the two of you want to have a word with each other. :)
Quoted 9 lines
fix build for missing
ETH_ALENdefinition
(this is needed at least with bionic)+#include <
linux/if_ether.h> /*ETH_ALEN*/Based on the above, clearly adding an 'if defined GLIBC' wrapper will break bionic...
and presumably glibc doesn't care whether the #include is done one way or the other?With glibc,
netinet/ether.hincludesnetinet/if_ether.hwhich in turn includeslinux/if_ether.hwhere finallyETH_ALENis defined.In
xtables.cwe definitely neednetinet/ether.hforether_aton()declaration.Quoted 1 line
Obviously it could be '#if !defined MUSL' instead...
Could ...
Quoted 4 lines
As for the fix? And whether glibc or musl or bionic are wrong or not... Utterly uncertain...
Though, I will point out #include's 2000 lines into a .c file are kind of funky.
ACK!
Review
Quoted 6 lines
Ultimately I find
https://android.git.corp.google.com/platform/external/iptables/+/7608e136bd495fe734ad18a6897dd4425e1a633b%5E%21/(quoted diff) +3
-0+#ifdef __BIONIC__ +#include <linux/if_ether.h> /* ETH_ALEN */ +#endifWhile I think musl not catching the "double" include is a bug, I'd prefer the ifdef
__BIONIC__solution since it started the "but my libc needs this" game.Nick, if the above change fixes musl builds for you, would you mind submitting it formally along with a move of the
netinet/ether.hinclude from mid-file to top?
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Thanks, Phil
Any thoughts about the rest of my email - wrt. #define
__USE_BSD
- do you know how that is supposed to work?No, but isn't this a detail of bionic header layout?
Cheers, Phil
No idea... is there actually a standard's document somewhere that actually describes which header file should declare what (and under what #define conditions)?
Without it, I have absolutely no idea...
glibc also has tons of headers that require #define SOMETHING before including them in order to get them to declare certain things.
I have no idea why the #ifdef BSD guard is there in bionic... maybe it's wrong, maybe it's compatible with some other libc header files... It doesn't really feel like the sort of thing that would be added by mistake (ie. it feels very intentional)...
But changing bionic (for example to remove the #ifdef), feels scarier, because it affects all things using bionic (including android app native code I think), as opposed to just a single file in iptables...
Florian Westphal
maintainerQuoted 10 lines · Phil Sutter
Quoted 9 lines
fix build for missing
ETH_ALENdefinition
(this is needed at least with bionic)+#include <
linux/if_ether.h> /*ETH_ALEN*/Based on the above, clearly adding an 'if defined GLIBC' wrapper will break bionic...
and presumably glibc doesn't care whether the #include is done one way or the other?
Quoted 5 lines
With glibc,
netinet/ether.hincludesnetinet/if_ether.hwhich in turn includeslinux/if_ether.hwhere finallyETH_ALENis defined.In
xtables.cwe definitely neednetinet/ether.hforether_aton()declaration.
Or we hand-roll a xt_ether_aton and add XT_ETH_ALEN to avoid this include.
Probably easier to maintain than to add all these ifdefs?
Quoted 15 lines · Florian Westphal
Quoted 13 lines · Phil Sutter
Quoted 9 lines
fix build for missing
ETH_ALENdefinition
(this is needed at least with bionic)+#include <
linux/if_ether.h> /*ETH_ALEN*/Based on the above, clearly adding an 'if defined GLIBC' wrapper will break bionic...
and presumably glibc doesn't care whether the #include is done one way or the other?With glibc,
netinet/ether.hincludesnetinet/if_ether.hwhich in turn includeslinux/if_ether.hwhere finallyETH_ALENis defined.
Quoted 7 lines
Quoted 2 lines
In
xtables.cwe definitely neednetinet/ether.hforether_aton()declaration.Or we hand-roll a
xt_ether_atonand addXT_ETH_ALENto avoid this include.Probably easier to maintain than to add all these ifdefs?
or even simply replace both the #include's with
#ifndef ETH_ALEN
#define ETH_ALEN 6
#endif
Phil Sutter
reviewerQuoted 21 lines · Maciej Żenczykowski
Quoted 20 lines · Florian Westphal
Quoted 10 lines · Phil Sutter
Quoted 9 lines
fix build for missing
ETH_ALENdefinition
(this is needed at least with bionic)+#include <
linux/if_ether.h> /*ETH_ALEN*/Based on the above, clearly adding an 'if defined GLIBC' wrapper will break bionic...
and presumably glibc doesn't care whether the #include is done one way or the other?Quoted 5 lines
With glibc,
netinet/ether.hincludesnetinet/if_ether.hwhich in turn includeslinux/if_ether.hwhere finallyETH_ALENis defined.In
xtables.cwe definitely neednetinet/ether.hforether_aton()declaration.Or we hand-roll a
xt_ether_atonand addXT_ETH_ALENto avoid this include.
Quoted 6 lines
Quoted 1 line
Probably easier to maintain than to add all these ifdefs?
or even simply replace both the #include's with
#ifndefETH_ALEN
#defineETH_ALEN6
#endif
If that's sufficient for both musl and bionic, probably the easiest solution with least potential for surprises.
Cheers, Phil
Quoted 11 lines
Review
Quoted 7 lines
Ultimately I find
https://android.git.corp.google.com/platform/external/iptables/+/7608e136bd495fe734ad18a6897dd4425e1a633b%5E%21/(quoted diff) +3
-0+#ifdef __BIONIC__ +#include <linux/if_ether.h> /* ETH_ALEN */ +#endifWhile I think musl not catching the "double" include is a bug, I'd prefer the ifdef
__BIONIC__solution since it started the "but my libc needs this" game.
Quoted 3 lines
Nick, if the above change fixes musl builds for you, would you mind submitting it formally along with a move of the
netinet/ether.hinclude from mid-file to top?
I will test again. :) However, I can not open the "android.git.corp.google.com"? Can you maybe link (also for reference) to a freely available source?
Bests
Nick
Quoted 12 lines · Nick
Quoted 12 lines
Review
Quoted 8 lines
Ultimately I find
https://android.git.corp.google.com/platform/external/iptables/+/7608e136bd495fe734ad18a6897dd4425e1a633b%5E%21/(quoted diff) +3
-0+#ifdef __BIONIC__ +#include <linux/if_ether.h> /* ETH_ALEN */ +#endifWhile I think musl not catching the "double" include is a bug, I'd prefer the ifdef
__BIONIC__solution since it started the "but my libc needs this" game.
Quoted 6 lines
Quoted 3 lines
Nick, if the above change fixes musl builds for you, would you mind submitting it formally along with a move of the
netinet/ether.hinclude from mid-file to top?I will test again. :) However, I can not open the "android.git.corp.google.com"? Can you maybe link (also for reference) to a freely available source?
PATCH 1/1 xtables: fix compilation with musl
From: Nick Hainke <[email protected]>
Only include <linux/if_ether.h> if bionic is used.
Fixes errors in the form of:
In file included from /home/nick/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-11.2.0_musl/include/netinet/ether.h:8,
from xtables.c:2238:
/home/nick/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-11.2.0_musl/include/netinet/if_ether.h:115:8: error: redefinition of 'struct ethhdr'
115 | struct ethhdr {
| ^~~~~~
In file included from xtables.c:48:
/home/nick/openwrt/build_dir/target-aarch64_cortex-a53_musl/linux-mediatek_mt7622/linux-5.15.38/user_headers/include/linux/if_ether.h:168:8: note: originally defined here
168 | struct ethhdr {
| ^~~~~~make[5]: *** [Makefile:471: libxtables_la-xtables.lo] Error 1
--- libxtables/xtables.c | 2 ++ 1 file changed, 2 insertions(+)
libxtables/xtables.c +2 -0
@@ -45,7 +45,9 @@#include <xtables.h> #include <limits.h> /* INT_MAX in ip_tables.h/ip6_tables.h */ +#ifdef __BIONIC__#include <linux/if_ether.h> /* ETH_ALEN */ +#endif #include <linux/netfilter_ipv4/ip_tables.h> #include <linux/netfilter_ipv6/ip6_tables.h> #include <libiptc/libxtc.h>
Signature · 1 line
2.36.1