From d16758d2d34a1750e19e0e8ba623583b7414c291 Mon Sep 17 00:00:00 2001 From: Nick Hainke Date: Sat, 18 Apr 2026 10:03:54 +0200 Subject: [PATCH] xdp-tools: fix musl build issues Add patches to fix build failures on musl-based toolchains: 0002-xdpsock-fix-struct-ethhdr-redefinition-on-musl.patch: xdpsock.c included and alongside , triggering a struct ethhdr redefinition on musl. Replace BSD-style ether_header/ether_addr with struct ethhdr and drop the conflicting includes. 0003-build-use-gnu2x-to-avoid-stdbool.h-dependency.patch: Switch CFLAGS and BPF_CFLAGS from -std=gnu11 to -std=gnu2x. In C23, bool is a native keyword, fixing "stdbool.h: No such file or directory" errors with a clang lacking its resource directory (e.g. llvm-bpf built with LLVM_INSTALL_TOOLCHAIN_ONLY=ON on musl targets). Link: https://github.com/openwrt/openwrt/pull/22983 Signed-off-by: Nick Hainke --- package/network/utils/xdp-tools/Makefile | 2 +- ...ux-if_ether.h-in-header-to-fix-musl-.patch | 9 +- ...x-struct-ethhdr-redefinition-on-musl.patch | 66 ++++ ...-gnu2x-to-avoid-stdbool.h-dependency.patch | 339 ++++++++++++++++++ 4 files changed, 412 insertions(+), 4 deletions(-) create mode 100644 package/network/utils/xdp-tools/patches/0002-xdpsock-fix-struct-ethhdr-redefinition-on-musl.patch create mode 100644 package/network/utils/xdp-tools/patches/0003-build-use-gnu2x-to-avoid-stdbool.h-dependency.patch diff --git a/package/network/utils/xdp-tools/Makefile b/package/network/utils/xdp-tools/Makefile index fb9ea95458b..67236ea3177 100644 --- a/package/network/utils/xdp-tools/Makefile +++ b/package/network/utils/xdp-tools/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=xdp-tools -PKG_RELEASE:=1 +PKG_RELEASE:=2 PKG_VERSION:=1.6.3 PKG_HASH:=78da363ff7dcf1a586f47800f16d644022bd33f3844864061a44616fce854fd8 diff --git a/package/network/utils/xdp-tools/patches/0001-params-avoid-linux-if_ether.h-in-header-to-fix-musl-.patch b/package/network/utils/xdp-tools/patches/0001-params-avoid-linux-if_ether.h-in-header-to-fix-musl-.patch index 1fee5e974c7..f19b348a3b6 100644 --- a/package/network/utils/xdp-tools/patches/0001-params-avoid-linux-if_ether.h-in-header-to-fix-musl-.patch +++ b/package/network/utils/xdp-tools/patches/0001-params-avoid-linux-if_ether.h-in-header-to-fix-musl-.patch @@ -1,5 +1,8 @@ +From f01fbee19b56b41f1e36f15a0d9334d2dc4da3ca Mon Sep 17 00:00:00 2001 From: Nick Hainke -Subject: [PATCH] params: avoid linux/if_ether.h in header to fix musl build +Date: Sun, 19 Apr 2026 18:29:45 +0200 +Subject: [PATCH 1/3] params: avoid linux/if_ether.h in header to fix musl + build On musl-based toolchains (e.g. MIPS), including from params.h triggers a chain through net/ethernet.h -> @@ -12,8 +15,8 @@ to avoid the conflict. Signed-off-by: Nick Hainke --- - lib/util/params.h | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) + lib/util/params.h | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) --- a/lib/util/params.h +++ b/lib/util/params.h diff --git a/package/network/utils/xdp-tools/patches/0002-xdpsock-fix-struct-ethhdr-redefinition-on-musl.patch b/package/network/utils/xdp-tools/patches/0002-xdpsock-fix-struct-ethhdr-redefinition-on-musl.patch new file mode 100644 index 00000000000..486fe64083b --- /dev/null +++ b/package/network/utils/xdp-tools/patches/0002-xdpsock-fix-struct-ethhdr-redefinition-on-musl.patch @@ -0,0 +1,66 @@ +From ab5415551c7c7e2e34327446c65faf924e362ad7 Mon Sep 17 00:00:00 2001 +From: Nick Hainke +Date: Sun, 19 Apr 2026 09:46:11 +0200 +Subject: [PATCH 2/3] xdpsock: fix struct ethhdr redefinition on musl + +On musl, including or after + triggers a redefinition of 'struct ethhdr' via +the netinet/if_ether.h chain. + +Fix xdpsock.c by replacing the BSD-style struct ether_header/ether_addr +in swap_mac_addresses() with struct ethhdr (already provided by the +existing include) and dropping the conflicting + and includes. + +Fix xdpsock.h by replacing with , +which provides ETH_ALEN and struct ethhdr without the redefinition. + +Signed-off-by: Nick Hainke +--- + lib/util/xdpsock.c | 16 ++++++---------- + lib/util/xdpsock.h | 2 +- + 2 files changed, 7 insertions(+), 11 deletions(-) + +--- a/lib/util/xdpsock.c ++++ b/lib/util/xdpsock.c +@@ -15,8 +15,6 @@ + #include + #include + #include +-#include +-#include + #include + #include + #include +@@ -648,14 +646,12 @@ void xsk_ctx__destroy(struct xsk_ctx *ct + + static void swap_mac_addresses(void *data) + { +- struct ether_header *eth = (struct ether_header *)data; +- struct ether_addr *src_addr = (struct ether_addr *)ð->ether_shost; +- struct ether_addr *dst_addr = (struct ether_addr *)ð->ether_dhost; +- struct ether_addr tmp; +- +- tmp = *src_addr; +- *src_addr = *dst_addr; +- *dst_addr = tmp; ++ struct ethhdr *eth = (struct ethhdr *)data; ++ unsigned char tmp[ETH_ALEN]; ++ ++ memcpy(tmp, eth->h_source, ETH_ALEN); ++ memcpy(eth->h_source, eth->h_dest, ETH_ALEN); ++ memcpy(eth->h_dest, tmp, ETH_ALEN); + } + + static void hex_dump(void *pkt, size_t length, __u64 addr) +--- a/lib/util/xdpsock.h ++++ b/lib/util/xdpsock.h +@@ -8,7 +8,7 @@ + + #include + #include +-#include ++#include + #include + #include + #include diff --git a/package/network/utils/xdp-tools/patches/0003-build-use-gnu2x-to-avoid-stdbool.h-dependency.patch b/package/network/utils/xdp-tools/patches/0003-build-use-gnu2x-to-avoid-stdbool.h-dependency.patch new file mode 100644 index 00000000000..b07149832f4 --- /dev/null +++ b/package/network/utils/xdp-tools/patches/0003-build-use-gnu2x-to-avoid-stdbool.h-dependency.patch @@ -0,0 +1,339 @@ +From bdb036b8015f5f55092cda9b140d79673007f4ca Mon Sep 17 00:00:00 2001 +From: Nick Hainke +Date: Sat, 18 Apr 2026 18:44:34 +0200 +Subject: [PATCH 3/3] build: use gnu2x to avoid stdbool.h dependency + +Bump the C standard from gnu11 to gnu2x for both CFLAGS and BPF_CFLAGS. +In C23 (gnu2x), bool is a native keyword, so stdbool.h is no longer needed. +This fixes "stdbool.h: No such file or directory" errors when building +BPF programs with a clang that lacks its resource directory (e.g. +OpenWrt's llvm-bpf built with LLVM_INSTALL_TOOLCHAIN_ONLY=ON on musl +targets), affecting xdpdump_bpf.c, xdpdump_xdp.c and +xdp_sample_common.bpf.h. + +Signed-off-by: Nick Hainke +--- + headers/linux/err.h | 1 - + headers/linux/hashtable.h | 1 - + headers/linux/netfilter.h | 1 - + headers/xdp/xdp_sample_common.bpf.h | 1 - + lib/defines.mk | 4 ++-- + lib/libxdp/tests/test_dispatcher_versions.c | 1 - + lib/libxdp/tests/test_link_detach.c | 1 - + lib/libxdp/tests/test_xdp_devbound.c | 1 - + lib/libxdp/tests/test_xdp_frags.c | 1 - + lib/libxdp/tests/test_xsk_refcnt.c | 1 - + lib/testing/test-tool.c | 1 - + lib/util/params.c | 1 - + lib/util/params.h | 1 - + lib/util/xdp_sample.c | 1 - + lib/util/xdpsock.c | 1 - + lib/util/xdpsock.h | 1 - + lib/util/xpcapng.c | 1 - + xdp-bench/xdp_basic.c | 1 - + xdp-bench/xdp_redirect_basic.c | 1 - + xdp-bench/xdp_redirect_cpumap.c | 1 - + xdp-bench/xdp_redirect_devmap.c | 1 - + xdp-bench/xdp_socket.c | 1 - + xdp-dump/xdpdump.c | 1 - + xdp-dump/xdpdump_bpf.c | 1 - + xdp-dump/xdpdump_xdp.c | 1 - + xdp-filter/xdp-filter.c | 1 - + xdp-loader/xdp-loader.c | 1 - + xdp-monitor/xdp-monitor.c | 1 - + xdp-trafficgen/xdp-trafficgen.c | 1 - + 29 files changed, 2 insertions(+), 30 deletions(-) + +--- a/headers/linux/err.h ++++ b/headers/linux/err.h +@@ -3,7 +3,6 @@ + #ifndef __LINUX_ERR_H + #define __LINUX_ERR_H + +-#include + #include + #include + +--- a/headers/linux/hashtable.h ++++ b/headers/linux/hashtable.h +@@ -9,7 +9,6 @@ + + #include + #include +-#include + #include + #include + #include +--- a/headers/linux/netfilter.h ++++ b/headers/linux/netfilter.h +@@ -1,7 +1,6 @@ + #ifndef _LINUX_NETFILTER_H + #define _LINUX_NETFILTER_H + +-#include + #include + #include + #include +--- a/headers/xdp/xdp_sample_common.bpf.h ++++ b/headers/xdp/xdp_sample_common.bpf.h +@@ -6,7 +6,6 @@ + #include "xdp_sample.bpf.h" + + #include +-#include + #include + #include + #include +--- a/lib/defines.mk ++++ b/lib/defines.mk +@@ -42,8 +42,8 @@ endif + + DEFINES += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 + +-CFLAGS += -std=gnu11 -Wextra -Werror $(DEFINES) $(ARCH_INCLUDES) +-BPF_CFLAGS += $(DEFINES) $(filter -ffile-prefix-map=%,$(CFLAGS)) $(filter -I%,$(CFLAGS)) $(ARCH_INCLUDES) ++CFLAGS += -std=gnu2x -Wextra -Werror $(DEFINES) $(ARCH_INCLUDES) ++BPF_CFLAGS += -std=gnu2x $(DEFINES) $(filter -ffile-prefix-map=%,$(CFLAGS)) $(filter -I%,$(CFLAGS)) $(ARCH_INCLUDES) + + CONFIGMK := $(LIB_DIR)/../config.mk + LIBMK := Makefile $(CONFIGMK) $(LIB_DIR)/defines.mk $(LIB_DIR)/common.mk $(LIB_DIR)/../version.mk +--- a/lib/libxdp/tests/test_dispatcher_versions.c ++++ b/lib/libxdp/tests/test_dispatcher_versions.c +@@ -6,7 +6,6 @@ + #include + #include + #include +-#include + #include + #include + #include +--- a/lib/libxdp/tests/test_link_detach.c ++++ b/lib/libxdp/tests/test_link_detach.c +@@ -6,7 +6,6 @@ + #include + #include + #include +-#include + #include + #include + #include +--- a/lib/libxdp/tests/test_xdp_devbound.c ++++ b/lib/libxdp/tests/test_xdp_devbound.c +@@ -6,7 +6,6 @@ + #include + #include + #include +-#include + #include + #include + #include +--- a/lib/libxdp/tests/test_xdp_frags.c ++++ b/lib/libxdp/tests/test_xdp_frags.c +@@ -6,7 +6,6 @@ + #include + #include + #include +-#include + #include + #include + #include +--- a/lib/libxdp/tests/test_xsk_refcnt.c ++++ b/lib/libxdp/tests/test_xsk_refcnt.c +@@ -4,7 +4,6 @@ + #include + #include + #include +-#include + #include + #include + #include +--- a/lib/testing/test-tool.c ++++ b/lib/testing/test-tool.c +@@ -2,7 +2,6 @@ + #include + #include + #include +-#include + #include + #include + +--- a/lib/util/params.c ++++ b/lib/util/params.c +@@ -5,7 +5,6 @@ + #include + #include + #include +-#include + #include + #include + +--- a/lib/util/params.h ++++ b/lib/util/params.h +@@ -4,7 +4,6 @@ + #define __PARAMS_H + + #include +-#include + #include + #include + #include +--- a/lib/util/xdp_sample.c ++++ b/lib/util/xdp_sample.c +@@ -15,7 +15,6 @@ + #include + #include + #include +-#include + #include + #include + #include +--- a/lib/util/xdpsock.c ++++ b/lib/util/xdpsock.c +@@ -19,7 +19,6 @@ + #include + #include + #include +-#include + #include + #include + #include +--- a/lib/util/xdpsock.h ++++ b/lib/util/xdpsock.h +@@ -7,7 +7,6 @@ + #define XDPSOCK_H_ + + #include +-#include + #include + #include + #include +--- a/lib/util/xpcapng.c ++++ b/lib/util/xpcapng.c +@@ -13,7 +13,6 @@ + #include + #include + #include +-#include + #include + #include + #include +--- a/xdp-bench/xdp_basic.c ++++ b/xdp-bench/xdp_basic.c +@@ -12,7 +12,6 @@ + #include + #include + #include +-#include + #include + #include + #include +--- a/xdp-bench/xdp_redirect_basic.c ++++ b/xdp-bench/xdp_redirect_basic.c +@@ -12,7 +12,6 @@ + #include + #include + #include +-#include + #include + #include + #include +--- a/xdp-bench/xdp_redirect_cpumap.c ++++ b/xdp-bench/xdp_redirect_cpumap.c +@@ -13,7 +13,6 @@ + #include + #include + #include +-#include + #include + #include + #include +--- a/xdp-bench/xdp_redirect_devmap.c ++++ b/xdp-bench/xdp_redirect_devmap.c +@@ -12,7 +12,6 @@ + #include + #include + #include +-#include + #include + #include + #include +--- a/xdp-bench/xdp_socket.c ++++ b/xdp-bench/xdp_socket.c +@@ -2,7 +2,6 @@ + #include + #include + #include +-#include + #include + #include + #include +--- a/xdp-dump/xdpdump.c ++++ b/xdp-dump/xdpdump.c +@@ -9,7 +9,6 @@ + #include + #include + #include +-#include + #include + #include + #include +--- a/xdp-dump/xdpdump_bpf.c ++++ b/xdp-dump/xdpdump_bpf.c +@@ -3,7 +3,6 @@ + /***************************************************************************** + * Include files + *****************************************************************************/ +-#include + #include + #include + #include +--- a/xdp-dump/xdpdump_xdp.c ++++ b/xdp-dump/xdpdump_xdp.c +@@ -3,7 +3,6 @@ + /***************************************************************************** + * Include files + *****************************************************************************/ +-#include + #include + #include + #include +--- a/xdp-filter/xdp-filter.c ++++ b/xdp-filter/xdp-filter.c +@@ -4,7 +4,6 @@ + #include + #include + #include +-#include + #include + #include + #include +--- a/xdp-loader/xdp-loader.c ++++ b/xdp-loader/xdp-loader.c +@@ -4,7 +4,6 @@ + #include + #include + #include +-#include + #include + #include + +--- a/xdp-monitor/xdp-monitor.c ++++ b/xdp-monitor/xdp-monitor.c +@@ -23,7 +23,6 @@ static const char *__doc_err_only__= + #include + #include + #include +-#include + #include + #include + +--- a/xdp-trafficgen/xdp-trafficgen.c ++++ b/xdp-trafficgen/xdp-trafficgen.c +@@ -6,7 +6,6 @@ + #include + #include + #include +-#include + #include + #include + #include -- 2.47.3