* [musl][PATCH 1/2] include/netinet/if_ether.h: define __UAPI_DEF_ETHHDR early
@ 2025-09-30 2:45 Qi.Chen
2025-09-30 2:45 ` [musl][PATCH 2/2] include/netinet/if_ether.h: guard ethhdr definition to better work with other header files Qi.Chen
2025-10-14 9:13 ` [musl][PATCH 1/2] include/netinet/if_ether.h: define __UAPI_DEF_ETHHDR early Chen, Qi
0 siblings, 2 replies; 8+ messages in thread
From: Qi.Chen @ 2025-09-30 2:45 UTC (permalink / raw)
To: musl; +Cc: qi.chen
From: Chen Qi <Qi.Chen@windriver.com>
After 'struct ethhdr' is defined, we should immediately define
__UAPI_DEF_ETHHDR. Because the following lines are header inclusion
lines which might introduce header files checking __UAPI_DEF_ETHHDR.
If we don't define this macro early, we will get redefinition error.
Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
---
include/netinet/if_ether.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/include/netinet/if_ether.h b/include/netinet/if_ether.h
index 3479f511..b1646f6f 100644
--- a/include/netinet/if_ether.h
+++ b/include/netinet/if_ether.h
@@ -117,6 +117,7 @@ struct ethhdr {
uint8_t h_source[ETH_ALEN];
uint16_t h_proto;
};
+#define __UAPI_DEF_ETHHDR 0
#include <net/ethernet.h>
#include <net/if_arp.h>
@@ -144,6 +145,4 @@ do { \
(enaddr)[5] = ((uint8_t *)ipaddr)[3]; \
} while(0)
-#define __UAPI_DEF_ETHHDR 0
-
#endif
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [musl][PATCH 2/2] include/netinet/if_ether.h: guard ethhdr definition to better work with other header files
2025-09-30 2:45 [musl][PATCH 1/2] include/netinet/if_ether.h: define __UAPI_DEF_ETHHDR early Qi.Chen
@ 2025-09-30 2:45 ` Qi.Chen
2025-09-30 13:34 ` Rich Felker
2025-10-14 9:13 ` [musl][PATCH 1/2] include/netinet/if_ether.h: define __UAPI_DEF_ETHHDR early Chen, Qi
1 sibling, 1 reply; 8+ messages in thread
From: Qi.Chen @ 2025-09-30 2:45 UTC (permalink / raw)
To: musl; +Cc: qi.chen
From: Chen Qi <Qi.Chen@windriver.com>
The unconditional definition of 'struct ethhdr' has the implicit
requirement on this header file, that is, it needs to be included
before other header files defining ethhdr.
Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
---
include/netinet/if_ether.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/include/netinet/if_ether.h b/include/netinet/if_ether.h
index b1646f6f..e5a1ebd0 100644
--- a/include/netinet/if_ether.h
+++ b/include/netinet/if_ether.h
@@ -112,12 +112,14 @@
#define ETH_P_XDSA 0x00F8
#define ETH_P_MAP 0x00F9
+#ifndef __UAPI_DEF_ETHHDR
struct ethhdr {
uint8_t h_dest[ETH_ALEN];
uint8_t h_source[ETH_ALEN];
uint16_t h_proto;
};
#define __UAPI_DEF_ETHHDR 0
+#endif
#include <net/ethernet.h>
#include <net/if_arp.h>
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [musl][PATCH 2/2] include/netinet/if_ether.h: guard ethhdr definition to better work with other header files
2025-09-30 2:45 ` [musl][PATCH 2/2] include/netinet/if_ether.h: guard ethhdr definition to better work with other header files Qi.Chen
@ 2025-09-30 13:34 ` Rich Felker
2025-10-09 2:53 ` Chen, Qi
0 siblings, 1 reply; 8+ messages in thread
From: Rich Felker @ 2025-09-30 13:34 UTC (permalink / raw)
To: Qi.Chen; +Cc: musl
On Tue, Sep 30, 2025 at 10:45:38AM +0800, Qi.Chen@windriver.com wrote:
> From: Chen Qi <Qi.Chen@windriver.com>
>
> The unconditional definition of 'struct ethhdr' has the implicit
> requirement on this header file, that is, it needs to be included
> before other header files defining ethhdr.
>
> Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
> ---
> include/netinet/if_ether.h | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/include/netinet/if_ether.h b/include/netinet/if_ether.h
> index b1646f6f..e5a1ebd0 100644
> --- a/include/netinet/if_ether.h
> +++ b/include/netinet/if_ether.h
> @@ -112,12 +112,14 @@
> #define ETH_P_XDSA 0x00F8
> #define ETH_P_MAP 0x00F9
>
> +#ifndef __UAPI_DEF_ETHHDR
> struct ethhdr {
> uint8_t h_dest[ETH_ALEN];
> uint8_t h_source[ETH_ALEN];
> uint16_t h_proto;
> };
> #define __UAPI_DEF_ETHHDR 0
> +#endif
>
> #include <net/ethernet.h>
> #include <net/if_arp.h>
> --
> 2.34.1
Defining a macro multiple times with the exact same token sequence as
its definition each time is not an error.
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [musl][PATCH 2/2] include/netinet/if_ether.h: guard ethhdr definition to better work with other header files
2025-09-30 13:34 ` Rich Felker
@ 2025-10-09 2:53 ` Chen, Qi
2025-10-09 4:21 ` A. Wilcox
2025-10-14 16:53 ` Rich Felker
0 siblings, 2 replies; 8+ messages in thread
From: Chen, Qi @ 2025-10-09 2:53 UTC (permalink / raw)
To: Rich Felker; +Cc: musl@lists.openwall.com
Hi Rich,
The problem is about the re-definition of 'struct ethhdr'.
For example, a header also defines 'struct ethhdr' and __UAPI_DEF_ETHHDR, and it's included *before* our <netinet/if_ether.h>, then the unconditional definition of 'struct ethhdr' in this header will be treated as an error.
Some background info:
I was making systemd to compile with musl. I got this re-definition error. I checked the headers and thought that for different headers to work together, the definition of this 'struct ethhdr' needs to be guarded by the same macro.
Regards,
Qi
-----Original Message-----
From: Rich Felker <dalias@libc.org>
Sent: Tuesday, September 30, 2025 9:34 PM
To: Chen, Qi <Qi.Chen@windriver.com>
Cc: musl@lists.openwall.com
Subject: Re: [musl][PATCH 2/2] include/netinet/if_ether.h: guard ethhdr definition to better work with other header files
On Tue, Sep 30, 2025 at 10:45:38AM +0800, Qi.Chen@windriver.com wrote:
> From: Chen Qi <Qi.Chen@windriver.com>
>
> The unconditional definition of 'struct ethhdr' has the implicit
> requirement on this header file, that is, it needs to be included
> before other header files defining ethhdr.
>
> Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
> ---
> include/netinet/if_ether.h | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/include/netinet/if_ether.h b/include/netinet/if_ether.h
> index b1646f6f..e5a1ebd0 100644
> --- a/include/netinet/if_ether.h
> +++ b/include/netinet/if_ether.h
> @@ -112,12 +112,14 @@
> #define ETH_P_XDSA 0x00F8
> #define ETH_P_MAP 0x00F9
>
> +#ifndef __UAPI_DEF_ETHHDR
> struct ethhdr {
> uint8_t h_dest[ETH_ALEN];
> uint8_t h_source[ETH_ALEN];
> uint16_t h_proto;
> };
> #define __UAPI_DEF_ETHHDR 0
> +#endif
>
> #include <net/ethernet.h>
> #include <net/if_arp.h>
> --
> 2.34.1
Defining a macro multiple times with the exact same token sequence as its definition each time is not an error.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [musl][PATCH 2/2] include/netinet/if_ether.h: guard ethhdr definition to better work with other header files
2025-10-09 2:53 ` Chen, Qi
@ 2025-10-09 4:21 ` A. Wilcox
2025-10-14 16:53 ` Rich Felker
1 sibling, 0 replies; 8+ messages in thread
From: A. Wilcox @ 2025-10-09 4:21 UTC (permalink / raw)
To: musl; +Cc: Chen, Qi
On Oct 8, 2025, at 21:53, Chen, Qi <Qi.Chen@windriver.com> wrote:
>
> Hi Rich,
>
> The problem is about the re-definition of 'struct ethhdr'.
>
> For example, a header also defines 'struct ethhdr' and __UAPI_DEF_ETHHDR, and it's included *before* our <netinet/if_ether.h>, then the unconditional definition of 'struct ethhdr' in this header will be treated as an error.
>
> Some background info:
> I was making systemd to compile with musl. I got this re-definition error. I checked the headers and thought that for different headers to work together, the definition of this 'struct ethhdr' needs to be guarded by the same macro.
>
> Regards,
> Qi
Hi Qi,
You might consider patching systemd to have libc includes instead of using the Linux UAPI headers. We did this at WTI with this commit: https://code.atwilcox.tech/sphen/scaly/systemd/-/commit/f423321481330c5f2f9158c490162b2e62b4c8bd
Best,
-Anna
--
Anna Wilcox (she/her)
SW Engineering: C++/Rust, DevOps, POSIX, Py/Ruby
Wilcox Technologies Inc.
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [musl][PATCH 1/2] include/netinet/if_ether.h: define __UAPI_DEF_ETHHDR early
2025-09-30 2:45 [musl][PATCH 1/2] include/netinet/if_ether.h: define __UAPI_DEF_ETHHDR early Qi.Chen
2025-09-30 2:45 ` [musl][PATCH 2/2] include/netinet/if_ether.h: guard ethhdr definition to better work with other header files Qi.Chen
@ 2025-10-14 9:13 ` Chen, Qi
1 sibling, 0 replies; 8+ messages in thread
From: Chen, Qi @ 2025-10-14 9:13 UTC (permalink / raw)
To: musl@lists.openwall.com; +Cc: Chen, Qi
ping
-----Original Message-----
From: Chen, Qi <Qi.Chen@windriver.com>
Sent: Tuesday, September 30, 2025 10:46 AM
To: musl@lists.openwall.com
Cc: Chen, Qi <Qi.Chen@windriver.com>
Subject: [musl][PATCH 1/2] include/netinet/if_ether.h: define __UAPI_DEF_ETHHDR early
From: Chen Qi <Qi.Chen@windriver.com>
After 'struct ethhdr' is defined, we should immediately define __UAPI_DEF_ETHHDR. Because the following lines are header inclusion lines which might introduce header files checking __UAPI_DEF_ETHHDR.
If we don't define this macro early, we will get redefinition error.
Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
---
include/netinet/if_ether.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/include/netinet/if_ether.h b/include/netinet/if_ether.h index 3479f511..b1646f6f 100644
--- a/include/netinet/if_ether.h
+++ b/include/netinet/if_ether.h
@@ -117,6 +117,7 @@ struct ethhdr {
uint8_t h_source[ETH_ALEN];
uint16_t h_proto;
};
+#define __UAPI_DEF_ETHHDR 0
#include <net/ethernet.h>
#include <net/if_arp.h>
@@ -144,6 +145,4 @@ do { \
(enaddr)[5] = ((uint8_t *)ipaddr)[3]; \ } while(0)
-#define __UAPI_DEF_ETHHDR 0
-
#endif
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [musl][PATCH 2/2] include/netinet/if_ether.h: guard ethhdr definition to better work with other header files
2025-10-09 2:53 ` Chen, Qi
2025-10-09 4:21 ` A. Wilcox
@ 2025-10-14 16:53 ` Rich Felker
2025-10-15 3:31 ` ChenQi
1 sibling, 1 reply; 8+ messages in thread
From: Rich Felker @ 2025-10-14 16:53 UTC (permalink / raw)
To: Chen, Qi; +Cc: musl@lists.openwall.com
On Thu, Oct 09, 2025 at 02:53:13AM +0000, Chen, Qi wrote:
> Hi Rich,
>
> The problem is about the re-definition of 'struct ethhdr'.
>
> For example, a header also defines 'struct ethhdr' and
> __UAPI_DEF_ETHHDR, and it's included *before* our
> <netinet/if_ether.h>, then the unconditional definition of 'struct
> ethhdr' in this header will be treated as an error.
>
> Some background info:
> I was making systemd to compile with musl. I got this re-definition
> error. I checked the headers and thought that for different headers
> to work together, the definition of this 'struct ethhdr' needs to be
> guarded by the same macro.
It's intentional that we don't support getting definitions for the
libc types from kernel headers. They may have subtle mismatches that
could break things. For example some types in the kernel are
known-wrong, like struct msghdr, and others have members that are the
same size/representation but different type (like long long vs
int64_t).
For the most part conflicting kernel headers shouldn't be used in
userspace. In cases where they should/need to be used, they should be
used either in separate translation units or included after the libc
headers.
This is documented in the original commit which added the __UAPI
macros, 04983f2272382af92eb8f8838964ff944fbb8258.
Rich
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [musl][PATCH 2/2] include/netinet/if_ether.h: guard ethhdr definition to better work with other header files
2025-10-14 16:53 ` Rich Felker
@ 2025-10-15 3:31 ` ChenQi
0 siblings, 0 replies; 8+ messages in thread
From: ChenQi @ 2025-10-15 3:31 UTC (permalink / raw)
To: Rich Felker; +Cc: musl@lists.openwall.com
On 10/15/25 00:53, Rich Felker wrote:
> On Thu, Oct 09, 2025 at 02:53:13AM +0000, Chen, Qi wrote:
>> Hi Rich,
>>
>> The problem is about the re-definition of 'struct ethhdr'.
>>
>> For example, a header also defines 'struct ethhdr' and
>> __UAPI_DEF_ETHHDR, and it's included *before* our
>> <netinet/if_ether.h>, then the unconditional definition of 'struct
>> ethhdr' in this header will be treated as an error.
>>
>> Some background info:
>> I was making systemd to compile with musl. I got this re-definition
>> error. I checked the headers and thought that for different headers
>> to work together, the definition of this 'struct ethhdr' needs to be
>> guarded by the same macro.
> It's intentional that we don't support getting definitions for the
> libc types from kernel headers. They may have subtle mismatches that
> could break things. For example some types in the kernel are
> known-wrong, like struct msghdr, and others have members that are the
> same size/representation but different type (like long long vs
> int64_t).
>
> For the most part conflicting kernel headers shouldn't be used in
> userspace. In cases where they should/need to be used, they should be
> used either in separate translation units or included after the libc
> headers.
>
> This is documented in the original commit which added the __UAPI
> macros, 04983f2272382af92eb8f8838964ff944fbb8258.
>
> Rich
Thanks a lot for the information.
I'll drop this patch and fix things in systemd recipe in Yocto.
Regards,
Qi
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-10-15 4:06 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-30 2:45 [musl][PATCH 1/2] include/netinet/if_ether.h: define __UAPI_DEF_ETHHDR early Qi.Chen
2025-09-30 2:45 ` [musl][PATCH 2/2] include/netinet/if_ether.h: guard ethhdr definition to better work with other header files Qi.Chen
2025-09-30 13:34 ` Rich Felker
2025-10-09 2:53 ` Chen, Qi
2025-10-09 4:21 ` A. Wilcox
2025-10-14 16:53 ` Rich Felker
2025-10-15 3:31 ` ChenQi
2025-10-14 9:13 ` [musl][PATCH 1/2] include/netinet/if_ether.h: define __UAPI_DEF_ETHHDR early Chen, Qi
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).