diff options
| author | Nick Hainke | 2026-04-18 08:03:54 +0000 |
|---|---|---|
| committer | Nick Hainke | 2026-04-20 14:43:23 +0000 |
| commit | 37326a2aa34b9a74d633295e66a941469ccc60a5 (patch) | |
| tree | fccadf128388d8d9c271175d2bf5b109718e8ad3 | |
| parent | 282309648b83f6eeb359d3d9b353c6cb0ca740fe (diff) | |
| download | openwrt-37326a2aa34b9a74d633295e66a941469ccc60a5.tar.gz | |
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 <net/ethernet.h> and <netinet/ether.h> alongside
<linux/if_ether.h>, 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
(cherry picked from commit d16758d2d34a1750e19e0e8ba623583b7414c291)
Link: https://github.com/openwrt/openwrt/pull/23015
Signed-off-by: Nick Hainke <vincent@systemli.org>
4 files changed, 412 insertions, 4 deletions
diff --git a/package/network/utils/xdp-tools/Makefile b/package/network/utils/xdp-tools/Makefile index fb9ea95458..67236ea317 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 1fee5e974c..f19b348a3b 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 <vincent@systemli.org> -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 <linux/if_ether.h> from params.h triggers a chain through net/ethernet.h -> @@ -12,8 +15,8 @@ to avoid the conflict. Signed-off-by: Nick Hainke <vincent@systemli.org> --- - 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 0000000000..486fe64083 --- /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 <vincent@systemli.org> +Date: Sun, 19 Apr 2026 09:46:11 +0200 +Subject: [PATCH 2/3] xdpsock: fix struct ethhdr redefinition on musl + +On musl, including <net/ethernet.h> or <netinet/ether.h> after +<linux/if_ether.h> 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 <linux/if_ether.h> include) and dropping the conflicting +<net/ethernet.h> and <netinet/ether.h> includes. + +Fix xdpsock.h by replacing <netinet/ether.h> with <linux/if_ether.h>, +which provides ETH_ALEN and struct ethhdr without the redefinition. + +Signed-off-by: Nick Hainke <vincent@systemli.org> +--- + 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 <linux/udp.h> + #include <locale.h> + #include <arpa/inet.h> +-#include <net/ethernet.h> +-#include <netinet/ether.h> + #include <net/if.h> + #include <poll.h> + #include <pthread.h> +@@ -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 <linux/if_xdp.h> + #include <stdbool.h> +-#include <netinet/ether.h> ++#include <linux/if_ether.h> + #include <time.h> + #include <sched.h> + #include <xdp/libxdp.h> 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 0000000000..b07149832f --- /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 <vincent@systemli.org> +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 <vincent@systemli.org> +--- + 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 <stdbool.h> + #include <linux/types.h> + #include <asm/errno.h> + +--- a/headers/linux/hashtable.h ++++ b/headers/linux/hashtable.h +@@ -9,7 +9,6 @@ + + #include <math.h> + #include <stdint.h> +-#include <stdbool.h> + #include <linux/hlist.h> + #include <linux/types.h> + #include <linux/kernel.h> +--- a/headers/linux/netfilter.h ++++ b/headers/linux/netfilter.h +@@ -1,7 +1,6 @@ + #ifndef _LINUX_NETFILTER_H + #define _LINUX_NETFILTER_H + +-#include <stdbool.h> + #include <linux/types.h> + #include <bpf/bpf_helpers.h> + #include <xdp/parsing_helpers.h> +--- 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 <bpf/vmlinux.h> +-#include <stdbool.h> + #include <bpf/bpf_tracing.h> + #include <bpf/bpf_core_read.h> + #include <bpf/bpf_helpers.h> +--- 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 <linux/err.h> + #include <net/if.h> + #include <pthread.h> +-#include <stdbool.h> + #include <stdlib.h> + #include <string.h> + #include <sys/resource.h> +--- a/lib/libxdp/tests/test_link_detach.c ++++ b/lib/libxdp/tests/test_link_detach.c +@@ -6,7 +6,6 @@ + #include <linux/err.h> + #include <net/if.h> + #include <pthread.h> +-#include <stdbool.h> + #include <stdlib.h> + #include <string.h> + #include <sys/resource.h> +--- a/lib/libxdp/tests/test_xdp_devbound.c ++++ b/lib/libxdp/tests/test_xdp_devbound.c +@@ -6,7 +6,6 @@ + #include <linux/err.h> + #include <net/if.h> + #include <pthread.h> +-#include <stdbool.h> + #include <stdlib.h> + #include <string.h> + #include <sys/resource.h> +--- a/lib/libxdp/tests/test_xdp_frags.c ++++ b/lib/libxdp/tests/test_xdp_frags.c +@@ -6,7 +6,6 @@ + #include <linux/err.h> + #include <net/if.h> + #include <pthread.h> +-#include <stdbool.h> + #include <stdlib.h> + #include <string.h> + #include <sys/resource.h> +--- a/lib/libxdp/tests/test_xsk_refcnt.c ++++ b/lib/libxdp/tests/test_xsk_refcnt.c +@@ -4,7 +4,6 @@ + #include <linux/err.h> + #include <net/if.h> + #include <pthread.h> +-#include <stdbool.h> + #include <stdlib.h> + #include <string.h> + #include <sys/resource.h> +--- a/lib/testing/test-tool.c ++++ b/lib/testing/test-tool.c +@@ -2,7 +2,6 @@ + #include <stdlib.h> + #include <string.h> + #include <errno.h> +-#include <stdbool.h> + #include <unistd.h> + #include <fcntl.h> + +--- a/lib/util/params.c ++++ b/lib/util/params.c +@@ -5,7 +5,6 @@ + #include <stdlib.h> + #include <stdio.h> + #include <string.h> +-#include <stdbool.h> + #include <getopt.h> + #include <errno.h> + +--- a/lib/util/params.h ++++ b/lib/util/params.h +@@ -4,7 +4,6 @@ + #define __PARAMS_H + + #include <getopt.h> +-#include <stdbool.h> + #include <stdlib.h> + #include <linux/in.h> + #include <linux/in6.h> +--- a/lib/util/xdp_sample.c ++++ b/lib/util/xdp_sample.c +@@ -15,7 +15,6 @@ + #include <string.h> + #include <unistd.h> + #include <bpf/bpf.h> +-#include <stdbool.h> + #include <inttypes.h> + #include <sys/mman.h> + #include <arpa/inet.h> +--- a/lib/util/xdpsock.c ++++ b/lib/util/xdpsock.c +@@ -19,7 +19,6 @@ + #include <poll.h> + #include <pthread.h> + #include <signal.h> +-#include <stdbool.h> + #include <stdio.h> + #include <stdlib.h> + #include <string.h> +--- a/lib/util/xdpsock.h ++++ b/lib/util/xdpsock.h +@@ -7,7 +7,6 @@ + #define XDPSOCK_H_ + + #include <linux/if_xdp.h> +-#include <stdbool.h> + #include <linux/if_ether.h> + #include <time.h> + #include <sched.h> +--- a/lib/util/xpcapng.c ++++ b/lib/util/xpcapng.c +@@ -13,7 +13,6 @@ + #include <errno.h> + #include <fcntl.h> + #include <inttypes.h> +-#include <stdbool.h> + #include <stdio.h> + #include <stdlib.h> + #include <string.h> +--- a/xdp-bench/xdp_basic.c ++++ b/xdp-bench/xdp_basic.c +@@ -12,7 +12,6 @@ + #include <string.h> + #include <unistd.h> + #include <bpf/bpf.h> +-#include <stdbool.h> + #include <linux/bpf.h> + #include <bpf/libbpf.h> + #include <sys/resource.h> +--- a/xdp-bench/xdp_redirect_basic.c ++++ b/xdp-bench/xdp_redirect_basic.c +@@ -12,7 +12,6 @@ + #include <string.h> + #include <unistd.h> + #include <bpf/bpf.h> +-#include <stdbool.h> + #include <linux/bpf.h> + #include <bpf/libbpf.h> + #include <sys/resource.h> +--- a/xdp-bench/xdp_redirect_cpumap.c ++++ b/xdp-bench/xdp_redirect_cpumap.c +@@ -13,7 +13,6 @@ + #include <string.h> + #include <unistd.h> + #include <bpf/bpf.h> +-#include <stdbool.h> + #include <arpa/inet.h> + #include <bpf/libbpf.h> + #include <sys/sysinfo.h> +--- a/xdp-bench/xdp_redirect_devmap.c ++++ b/xdp-bench/xdp_redirect_devmap.c +@@ -12,7 +12,6 @@ + #include <string.h> + #include <unistd.h> + #include <bpf/bpf.h> +-#include <stdbool.h> + #include <linux/bpf.h> + #include <bpf/libbpf.h> + #include <xdp/libxdp.h> +--- a/xdp-bench/xdp_socket.c ++++ b/xdp-bench/xdp_socket.c +@@ -2,7 +2,6 @@ + #include <string.h> + #include <unistd.h> + #include <bpf/bpf.h> +-#include <stdbool.h> + #include <linux/bpf.h> + #include <pthread.h> + #include <bpf/libbpf.h> +--- a/xdp-dump/xdpdump.c ++++ b/xdp-dump/xdpdump.c +@@ -9,7 +9,6 @@ + #include <inttypes.h> + #include <limits.h> + #include <signal.h> +-#include <stdbool.h> + #include <stdio.h> + #include <stdlib.h> + #include <string.h> +--- a/xdp-dump/xdpdump_bpf.c ++++ b/xdp-dump/xdpdump_bpf.c +@@ -3,7 +3,6 @@ + /***************************************************************************** + * Include files + *****************************************************************************/ +-#include <stdbool.h> + #include <linux/bpf.h> + #include <bpf/bpf_helpers.h> + #include <bpf/bpf_trace_helpers.h> +--- a/xdp-dump/xdpdump_xdp.c ++++ b/xdp-dump/xdpdump_xdp.c +@@ -3,7 +3,6 @@ + /***************************************************************************** + * Include files + *****************************************************************************/ +-#include <stdbool.h> + #include <linux/bpf.h> + #include <bpf/bpf_helpers.h> + #include <bpf/bpf_trace_helpers.h> +--- a/xdp-filter/xdp-filter.c ++++ b/xdp-filter/xdp-filter.c +@@ -4,7 +4,6 @@ + #include <stdlib.h> + #include <string.h> + #include <errno.h> +-#include <stdbool.h> + #include <unistd.h> + #include <fcntl.h> + #include <inttypes.h> +--- a/xdp-loader/xdp-loader.c ++++ b/xdp-loader/xdp-loader.c +@@ -4,7 +4,6 @@ + #include <stdlib.h> + #include <string.h> + #include <errno.h> +-#include <stdbool.h> + #include <unistd.h> + #include <fcntl.h> + +--- a/xdp-monitor/xdp-monitor.c ++++ b/xdp-monitor/xdp-monitor.c +@@ -23,7 +23,6 @@ static const char *__doc_err_only__= + #include <string.h> + #include <unistd.h> + #include <bpf/bpf.h> +-#include <stdbool.h> + #include <bpf/libbpf.h> + #include <sys/resource.h> + +--- a/xdp-trafficgen/xdp-trafficgen.c ++++ b/xdp-trafficgen/xdp-trafficgen.c +@@ -6,7 +6,6 @@ + #include <string.h> + #include <signal.h> + #include <errno.h> +-#include <stdbool.h> + #include <unistd.h> + #include <fcntl.h> + #include <pthread.h> |