[PATCH net-next v2 3/4] samples/bpf: Move some UAPI header inclusions after libc ones
From: Thomas Weißschuh <hidden>
Date: 2026-01-20 14:10:42
Also in:
bpf, linux-kselftest, linux-security-module, lkml, mptcp, netdev
Subsystem:
bpf [general] (safe dynamic programs and tools), the rest, xdp (express data path) · Maintainers:
Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi, Linus Torvalds, David S. Miller, Jakub Kicinski, Jesper Dangaard Brouer, John Fastabend
Interleaving inclusions of UAPI headers and libc headers is problematic. Both sets of headers define conflicting symbols. To enable their coexistence a compatibility-mechanism is in place. An upcoming change will define 'struct sockaddr' from linux/socket.h. However sys/socket.h from libc does not yet handle this case and a symbol conflict will arise. Move the inclusion of all UAPI headers after the inclusion of the glibc ones, so the compatibility mechanism from the UAPI headers is used. Signed-off-by: Thomas Weißschuh <redacted> --- samples/bpf/xdp_adjust_tail_user.c | 6 ++++-- samples/bpf/xdp_fwd_user.c | 7 ++++--- samples/bpf/xdp_router_ipv4_user.c | 6 +++--- samples/bpf/xdp_sample_user.c | 15 ++++++++------- samples/bpf/xdp_tx_iptunnel_user.c | 4 ++-- 5 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/samples/bpf/xdp_adjust_tail_user.c b/samples/bpf/xdp_adjust_tail_user.c
index e9426bd65420..32d00405debc 100644
--- a/samples/bpf/xdp_adjust_tail_user.c
+++ b/samples/bpf/xdp_adjust_tail_user.c@@ -5,8 +5,6 @@ * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. */ -#include <linux/bpf.h> -#include <linux/if_link.h> #include <assert.h> #include <errno.h> #include <signal.h>
@@ -18,9 +16,13 @@ #include <netinet/ether.h> #include <unistd.h> #include <time.h> + #include <bpf/bpf.h> #include <bpf/libbpf.h> +#include <linux/bpf.h> +#include <linux/if_link.h> + #define STATS_INTERVAL_S 2U #define MAX_PCKT_SIZE 600
diff --git a/samples/bpf/xdp_fwd_user.c b/samples/bpf/xdp_fwd_user.c
index 193b3b79b31f..ca55f3eac12a 100644
--- a/samples/bpf/xdp_fwd_user.c
+++ b/samples/bpf/xdp_fwd_user.c@@ -11,9 +11,6 @@ * General Public License for more details. */ -#include <linux/bpf.h> -#include <linux/if_link.h> -#include <linux/limits.h> #include <net/if.h> #include <errno.h> #include <stdio.h>
@@ -27,6 +24,10 @@ #include <bpf/libbpf.h> #include <bpf/bpf.h> +#include <linux/bpf.h> +#include <linux/if_link.h> +#include <linux/limits.h> + static __u32 xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST; static int do_attach(int idx, int prog_fd, int map_fd, const char *name)
diff --git a/samples/bpf/xdp_router_ipv4_user.c b/samples/bpf/xdp_router_ipv4_user.c
index 266fdd0b025d..2abc7d294251 100644
--- a/samples/bpf/xdp_router_ipv4_user.c
+++ b/samples/bpf/xdp_router_ipv4_user.c@@ -1,9 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* Copyright (C) 2017 Cavium, Inc. */ -#include <linux/bpf.h> -#include <linux/netlink.h> -#include <linux/rtnetlink.h> #include <assert.h> #include <errno.h> #include <signal.h>
@@ -25,6 +22,9 @@ #include <libgen.h> #include <getopt.h> #include <pthread.h> +#include <linux/bpf.h> +#include <linux/netlink.h> +#include <linux/rtnetlink.h> #include "xdp_sample_user.h" #include "xdp_router_ipv4.skel.h"
diff --git a/samples/bpf/xdp_sample_user.c b/samples/bpf/xdp_sample_user.c
index 158682852162..d9aec2bd372c 100644
--- a/samples/bpf/xdp_sample_user.c
+++ b/samples/bpf/xdp_sample_user.c@@ -7,13 +7,6 @@ #include <errno.h> #include <fcntl.h> #include <getopt.h> -#include <linux/ethtool.h> -#include <linux/hashtable.h> -#include <linux/if_link.h> -#include <linux/jhash.h> -#include <linux/limits.h> -#include <linux/list.h> -#include <linux/sockios.h> #include <locale.h> #include <math.h> #include <net/if.h>
@@ -32,6 +25,14 @@ #include <time.h> #include <unistd.h> +#include <linux/ethtool.h> +#include <linux/hashtable.h> +#include <linux/if_link.h> +#include <linux/jhash.h> +#include <linux/limits.h> +#include <linux/list.h> +#include <linux/sockios.h> + #include "bpf_util.h" #include "xdp_sample_user.h"
diff --git a/samples/bpf/xdp_tx_iptunnel_user.c b/samples/bpf/xdp_tx_iptunnel_user.c
index 7e4b2f7108a6..e9503036d0a0 100644
--- a/samples/bpf/xdp_tx_iptunnel_user.c
+++ b/samples/bpf/xdp_tx_iptunnel_user.c@@ -1,8 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* Copyright (c) 2016 Facebook */ -#include <linux/bpf.h> -#include <linux/if_link.h> #include <assert.h> #include <errno.h> #include <signal.h>
@@ -16,6 +14,8 @@ #include <time.h> #include <bpf/libbpf.h> #include <bpf/bpf.h> +#include <linux/bpf.h> +#include <linux/if_link.h> #include "bpf_util.h" #include "xdp_tx_iptunnel_common.h"
--
2.52.0