Re: [PATCH] xtables: Fix compilation error with musl-libc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2024-08-20, at 13:28:22 +0200, Pablo Neira Ayuso wrote:
> On Mon, Aug 19, 2024 at 07:24:06PM +0200, Pablo Neira Ayuso wrote:
> > On Tue, Jul 09, 2024 at 01:05:45PM +0000, Joshua Lant wrote:
> > > Error compiling with musl-libc:
> > > The commit hash 810f8568f44f5863c2350a39f4f5c8d60f762958 introduces the
> > > netinet/ether.h header into xtables.h, which causes an error due to the
> > > redefinition of the ethhdr struct, defined in linux/if_ether.h and
> > > netinet/ether.h.
> > > 
> > > This is is a known issue with musl-libc, with kernel headers providing
> > > guards against this happening when glibc is used:
> > > https://wiki.musl-libc.org/faq (Q: Why am I getting “error: redefinition
> > > of struct ethhdr/tcphdr/etc”?)
> > > 
> > > The only value used from netinet/ether.h is ETH_ALEN, which is already set
> > > manually in libxtables/xtables.c. Move this definition to the header and
> > > eliminate the inclusion of netinet/if_ether.h.
> > 
> > Any chance that musl headers are being used so this can be autodetected?
> > Then, no option to pass -D__UAPI_DEF_ETHHDR=0 is required.
> 
> To clarify, what I mean is if it is possible to autodetect that musl
> headers are used, then add this definition.
> 
> I'd prefer no new --option as you propose is required to handle this.

There are a couple of approaches that I see.

1. Test whether netinet/if_ether.h sets `__UAPI_DEF_ETHHDR` to zero (in
which case we are building with musl):

  saved_CPPFLAGS=${CPPFLAGS}
  CPPFLAGS=${regular_CPPFLAGS}
  AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
  #include <netinet/if_ether.h>
  #if defined(__UAPI_DEF_ETHHDR) && __UAPI_DEF_ETHHDR == 0
  #else
  #error No __UAPI_DEF_ETHHDR
  #endif
  ]])], [AC_DEFINE([__UAPI_DEF_ETHHDR], [0], [Prevent multiple definitions of `struct ethhdr`])])
  CPPFLAGS=${saved_CPPFLAGS}

2. Just check `${host_os}`:

  AS_IF([test "${host_os}" = "linux-musl"],
        [AC_DEFINE([__UAPI_DEF_ETHHDR], [0], [Prevent multiple definitions of `struct ethhdr`])])

J.

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux