From: Alyssa Ross <hi@alyssa.is>
To: Phil Sutter <phil@nwl.cc>, Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org, Joshua Lant <joshualant@googlemail.com>
Subject: Re: [PATCH nftables] include: fix for musl with iptables v1.8.11
Date: Sat, 21 Dec 2024 16:34:55 +0100 [thread overview]
Message-ID: <87v7vd59sw.fsf@alyssa.is> (raw)
In-Reply-To: <Z2VkJrkSLRmY9lAE@orbyte.nwl.cc>
[-- Attachment #1: Type: text/plain, Size: 3364 bytes --]
Phil Sutter <phil@nwl.cc> writes:
> On Fri, Dec 20, 2024 at 01:07:56PM +0100, Alyssa Ross wrote:
>> On Fri, Dec 20, 2024 at 12:50:42PM +0100, Phil Sutter wrote:
>> > Hi Alyssa,
>> >
>> > On Fri, Dec 20, 2024 at 12:10:02AM +0100, Alyssa Ross wrote:
>> > > Since iptables commit 810f8568 (libxtables: xtoptions: Implement
>> > > XTTYPE_ETHERMACMASK), nftables failed to build for musl libc:
>> > >
>> > > In file included from /nix/store/bvffdqfhyxvx66bqlqqdmjmkyklkafv6-musl-1.2.5-dev/include/netinet/et…
>> > > from /nix/store/kz6fymqpgbrj6330s6wv4idcf9pwsqs4-iptables-1.8.10-de…
>> > > from src/xt.c:30:
>> > > /nix/store/bvffdqfhyxvx66bqlqqdmjmkyklkafv6-musl-1.2.5-dev/include/netinet/if_ether.h:115:8: error: redefinition of 'struct ethhdr'
>> > > 115 | struct ethhdr {
>> > > | ^~~~~~
>> > > In file included from ./include/linux/netfilter_bridge.h:8,
>> > > from ./include/linux/netfilter_bridge/ebtables.h:1,
>> > > from src/xt.c:27:
>> > > /nix/store/bvffdqfhyxvx66bqlqqdmjmkyklkafv6-musl-1.2.5-dev/include/linux/if_ether.h:173:8: note: originally defined here
>> > > 173 | struct ethhdr {
>> > > | ^~~~~~
>> > >
>> > > The fix is to use libc's version of if_ether.h before any kernel
>> > > headers, which takes care of conflicts with the kernel's struct ethhdr
>> > > definition by defining __UAPI_DEF_ETHHDR, which will tell the kernel's
>> > > header not to define its own version.
>> >
>> > What I don't like about this is how musl tries to force projects to not
>> > include linux/if_ether.h directly. From the project's view, this is a
>> > workaround not a fix.
>>
>> My understanding is that it's a general principle of using any libc on
>> Linux that if there's both a libc and kernel header for the same thing,
>> the libc header should be used. libc headers will of course include
>> other libc headers in preference to kernel headers, so if you also
>> include the kernel headers you're likely to end up with conflicts.
>> Whether conflicts occur in any particular case depends on how a
>> particular libc chooses to expose a particular kernel API. I could be
>> misremembering, but I believe the same thing can happen with Glibc —
>> some headers under sys/ cause conflicts with their corresponding kernel
>> headers if both are included. While this case is musl specific, I
>> think the principle applies to all libcs.
>
> While this may be true for the vast majority of user space programs,
> netfilter tools and libraries are a bit special in how close they
> interface with the kernel. Not all netfilter-related kernel API is
> exposed by glibc, for instance. Including (some) kernel headers is
> therefore unavoidable, and (as your patch shows) order of inclusion
> becomes subtly relevant in ways which won't show when compile-testing
> against glibc only.
Yeah — really it needs to be ensured in review that libc headers are
included before kernel headers, and libc headers are preferred over
kernel headers where both are available. It's not too much to keep in
mind, but it does need to be taught/learned because the issues it causes
won't always be caught during testing in any particular environment.
The same holds for lots of things in C, though.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 227 bytes --]
next prev parent reply other threads:[~2024-12-21 15:35 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-19 23:10 [PATCH nftables] include: fix for musl with iptables v1.8.11 Alyssa Ross
2024-12-20 11:50 ` Phil Sutter
2024-12-20 12:07 ` Alyssa Ross
2024-12-20 12:33 ` Phil Sutter
2024-12-21 15:34 ` Alyssa Ross [this message]
2025-01-08 23:34 ` Pablo Neira Ayuso
2025-01-08 23:49 ` Phil Sutter
2025-01-09 0:03 ` Pablo Neira Ayuso
2025-01-09 10:02 ` Phil Sutter
2026-02-11 13:49 ` Florian Westphal
2026-02-11 18:59 ` Phil Sutter
2026-02-11 19:09 ` Florian Westphal
2026-02-11 20:19 ` Phil Sutter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87v7vd59sw.fsf@alyssa.is \
--to=hi@alyssa.is \
--cc=joshualant@googlemail.com \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
--cc=phil@nwl.cc \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.