net: uapi: Provide an UAPI definition of 'struct sockaddr'
Subsystems (11)
v2 cover net: uapi: Provide an UAPI definition of 'struct sockaddr'
Various UAPI headers reference 'struct sockaddr'. Currently the definition of this struct is pulled in from the libc header sys/socket.h. This is problematic as it introduces a dependency on a full userspace toolchain.
Add a definition of 'struct sockaddr' to the UAPI headers. Before that, reorder some problematic header inclusions in the selftests.
---
Changes in v2:
- Fix compilation failures in BPF samples and selftests
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Thomas Weißschuh (4):
selftests: net: Move some UAPI header inclusions after libc ones selftests/landlock: Move some UAPI header inclusions after libc ones samples/bpf: Move some UAPI header inclusions after libc ones
net: uapi: Provide an UAPI definition of 'struct sockaddr'
include/linux/socket.h | 10 ---------- include/uapi/linux/if.h | 4 ---- include/uapi/linux/libc-compat.h | 12 ++++++++++++ include/uapi/linux/socket.h | 14 ++++++++++++++ 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 ++-- tools/testing/selftests/landlock/audit.h | 7 ++++--- tools/testing/selftests/net/af_unix/diag_uid.c | 9 +++++---- tools/testing/selftests/net/busy_poller.c | 3 ++- tools/testing/selftests/net/mptcp/mptcp_diag.c | 11 ++++++----- tools/testing/selftests/net/nettest.c | 4 ++-- tools/testing/selftests/net/tcp_ao/icmps-discard.c | 6 +++--- tools/testing/selftests/net/tcp_ao/lib/netlink.c | 9 +++++---- tools/testing/selftests/net/tun.c | 5 +++-- 17 files changed, 77 insertions(+), 55 deletions(-)
---
base-commit: 24d479d26b25bce5faea3ddd9fa8f3a6c3129ea7
change-id: 20251222-uapi-sockaddr-cf10e7624729
Best regards,
Signature · 1 line
Thomas Weißschuh <[email protected]>
PATCH v2 1/4 selftests: net: Move some UAPI header inclusions after libc ones
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.
Furthermore libc-compat.h evaluates the state of the libc inclusions only once, at the point it is included first. If another problematic header from libc is included later, symbol conflicts arise. This will trigger other duplicate definitions when linux/libc-compat.h is added to linux/socket.h
Move the inclusion of UAPI headers after the inclusion of the glibc ones, so the libc-compat.h continues to work correctly.
--- tools/testing/selftests/net/af_unix/diag_uid.c | 9 +++++---- tools/testing/selftests/net/busy_poller.c | 3 ++- tools/testing/selftests/net/mptcp/mptcp_diag.c | 11 ++++++----- tools/testing/selftests/net/nettest.c | 4 ++-- tools/testing/selftests/net/tcp_ao/icmps-discard.c | 6 +++--- tools/testing/selftests/net/tcp_ao/lib/netlink.c | 9 +++++---- tools/testing/selftests/net/tun.c | 5 +++-- 7 files changed, 26 insertions(+), 21 deletions(-)
tools/testing/selftests/net/af_unix/diag_uid.c +5 -4
@@ -5,15 +5,16 @@#include <sched.h> #include <unistd.h> -#include <linux/netlink.h> -#include <linux/rtnetlink.h> -#include <linux/sock_diag.h> -#include <linux/unix_diag.h> #include <sys/socket.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/un.h> +#include <linux/netlink.h> +#include <linux/rtnetlink.h> +#include <linux/sock_diag.h> +#include <linux/unix_diag.h> +#include "kselftest_harness.h" FIXTURE (diag_uid)
tools/testing/selftests/net/busy_poller.c +2 -1
@@ -9,7 +9,6 @@#include <stdio.h> #include <string.h> #include <unistd.h> -#include <ynl.h> #include <arpa/inet.h> #include <netinet/in.h>
@@ -19,6 +18,8 @@#include <sys/socket.h> #include <sys/types.h> +#include <ynl.h> +#include <linux/genetlink.h> #include <linux/netlink.h>
tools/testing/selftests/net/mptcp/mptcp_diag.c +6 -5
@@ -1,11 +1,6 @@// SPDX-License-Identifier: GPL-2.0 /* Copyright (c) 2025, Kylin Software */ -#include <linux/sock_diag.h> -#include <linux/rtnetlink.h> -#include <linux/inet_diag.h> -#include <linux/netlink.h> -#include <linux/compiler.h> #include <sys/socket.h> #include <netinet/in.h> #include <linux/tcp.h>
@@ -17,6 +12,12 @@#include <errno.h> #include <stdio.h> +#include <linux/sock_diag.h> +#include <linux/rtnetlink.h> +#include <linux/inet_diag.h> +#include <linux/netlink.h> +#include <linux/compiler.h> +#ifndef IPPROTO_MPTCP #define IPPROTO_MPTCP 262#endif
tools/testing/selftests/net/nettest.c +2 -2
@@ -10,8 +10,6 @@#include <sys/ioctl.h> #include <sys/socket.h> #include <sys/wait.h> -#include <linux/tcp.h> -#include <linux/udp.h> #include <arpa/inet.h> #include <net/if.h> #include <netinet/in.h>
@@ -30,6 +28,8 @@#include <errno.h> #include <getopt.h> +#include <linux/tcp.h> +#include <linux/udp.h> #include <linux/xfrm.h> #include <linux/ipsec.h> #include <linux/pfkeyv2.h>
tools/testing/selftests/net/tcp_ao/icmps-discard.c +3 -3
@@ -16,12 +16,12 @@* Author: Dmitry Safonov <[email protected]> */ #include <inttypes.h> -#include <linux/icmp.h> -#include <linux/icmpv6.h> -#include <linux/ipv6.h> #include <netinet/in.h> #include <netinet/ip.h> #include <sys/socket.h> +#include <linux/icmp.h> +#include <linux/icmpv6.h> +#include <linux/ipv6.h> #include "aolib.h" #include "../../../../include/linux/compiler.h"
tools/testing/selftests/net/tcp_ao/lib/netlink.c +5 -4
@@ -1,14 +1,15 @@// SPDX-License-Identifier: GPL-2.0 /* Original from tools/testing/selftests/net/ipsec.c */ -#include <linux/netlink.h> -#include <linux/random.h> -#include <linux/rtnetlink.h> -#include <linux/veth.h> #include <net/if.h> #include <stdint.h> #include <string.h> #include <sys/socket.h> +#include <linux/netlink.h> +#include <linux/random.h> +#include <linux/rtnetlink.h> +#include <linux/veth.h> +#include "aolib.h" #define MAX_PAYLOAD 2048
tools/testing/selftests/net/tun.c +3 -2
@@ -8,12 +8,13 @@#include <stdlib.h> #include <string.h> #include <unistd.h> +#include <sys/ioctl.h> +#include <sys/socket.h> +#include <linux/if.h> #include <linux/if_tun.h> #include <linux/netlink.h> #include <linux/rtnetlink.h> -#include <sys/ioctl.h> -#include <sys/socket.h> #include "kselftest_harness.h"
Signature · 1 line
2.52.0
kernel test robot
build botRe: [PATCH net-next v2 1/4] selftests: net: Move some UAPI header inclusions after libc ones
kernel test robot noticed the following build errors:
Hi Thomas,
kernel test robot noticed the following build errors:
[auto build test ERROR on 24d479d26b25bce5faea3ddd9fa8f3a6c3129ea7]
url: https://github.com/intel-lab-lkp/linux/commits/Thomas-Wei-schuh/selftests-net-Move-some-UAPI-header-inclusions-after-libc-ones/20260121-032048 base: 24d479d26b25bce5faea3ddd9fa8f3a6c3129ea7 patch link: https://lore.kernel.org/r/20260120-uapi-sockaddr-v2-1-63c319111cf6%40linutronix.de patch subject: [PATCH net-next v2 1/4] selftests: net: Move some UAPI header inclusions after libc ones config: powerpc64-allnoconfig-bpf (https://download.01.org/0day-ci/archive/20260122/[email protected]/config) compiler: powerpc64-linux-gcc (GCC) 15.1.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260122/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/
All errors (new ones prefixed by >>):
>> lib/netlink.c:3:10: fatal error: net/if.h: No such file or directory
3 | #include <net/if.h>
| ^~~~~~~~~~compilation terminated.
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Matthieu Baerts
maintainerRe: [PATCH net-next v2 1/4] selftests: net: Move some UAPI header inclusions after libc ones
In reply to Thomas WeißschuhHi Thomas,
Quoted 8 lines · Thomas Weißschuh
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. Howeversys/socket.hfrom libc does not yet handle this case and a symbol conflict will arise.
Quoted 8 lines
Furthermore
libc-compat.hevaluates the state of the libc inclusions only once, at the point it is included first. If another problematic header from libc is included later, symbol conflicts arise. This will trigger other duplicate definitions whenlinux/libc-compat.his added tolinux/socket.hMove the inclusion of UAPI headers after the inclusion of the glibc ones, so the
libc-compat.hcontinues to work correctly.
Thank you for looking at this!
Here is my (late, sorry) review for the modifications related to MPTCP:
Quoted 6 lines
tools/testing/selftests/net/mptcp/mptcp_diag.c +0
-0@@ -1,11 +1,6 @@// SPDX-License-Identifier: GPL-2.0
tools/testing/selftests/net/mptcp/mptcp_diag.c line 6
Quoted 10 lines
tools/testing/selftests/net/mptcp/mptcp_diag.c +0
-5/* Copyright (c) 2025, Kylin Software */ -#include <linux/sock_diag.h> -#include <linux/rtnetlink.h> -#include <linux/inet_diag.h> -#include <linux/netlink.h> -#include <linux/compiler.h> #include <sys/socket.h> #include <netinet/in.h> #include <linux/tcp.h>
There is a remaining one (linux/tcp.h) here that you might want to move below too.
tools/testing/selftests/net/mptcp/mptcp_diag.c line 19
Quoted 9 lines
tools/testing/selftests/net/mptcp/mptcp_diag.c +5
-0@@ -17,6 +12,12 @@#include <errno.h> #include <stdio.h> +#include <linux/sock_diag.h> +#include <linux/rtnetlink.h> +#include <linux/inet_diag.h> +#include <linux/netlink.h> +#include <linux/compiler.h>
Note that I just noticed this is the only file from this directory where the "includes" are not sorted by type and alphabetical order, see pm_nl_ctl.c as an example. A bit of a detail, but if you plan to send a v2, do you mind doing that too here while at it, please?
If not, I can look at that later, but better to avoid doing that in parallel.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Re: [PATCH net-next v2 1/4] selftests: net: Move some UAPI header inclusions after libc ones
(trimmed the recipient list)
Hi Matt,
Quoted 29 lines · Matthieu Baerts
Quoted 8 lines · Thomas Weißschuh
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. Howeversys/socket.hfrom libc does not yet handle this case and a symbol conflict will arise.Quoted 8 lines
Furthermore
libc-compat.hevaluates the state of the libc inclusions only once, at the point it is included first. If another problematic header from libc is included later, symbol conflicts arise. This will trigger other duplicate definitions whenlinux/libc-compat.his added tolinux/socket.hMove the inclusion of UAPI headers after the inclusion of the glibc ones, so the
libc-compat.hcontinues to work correctly.Thank you for looking at this!
Here is my (late, sorry) review for the modifications related to MPTCP:
Quoted 8 lines
tools/testing/selftests/net/mptcp/mptcp_diag.c +0
-0@@ -1,11 +1,6 @@// SPDX-License-Identifier: GPL-2.0 /* Copyright (c) 2025, Kylin Software */
Quoted 11 lines
tools/testing/selftests/net/mptcp/mptcp_diag.c line 6
Quoted 8 lines
tools/testing/selftests/net/mptcp/mptcp_diag.c +0
-5-#include <linux/sock_diag.h> -#include <linux/rtnetlink.h> -#include <linux/inet_diag.h> -#include <linux/netlink.h> -#include <linux/compiler.h> #include <sys/socket.h> #include <netinet/in.h> #include <linux/tcp.h> There is a remaining one (
linux/tcp.h) here that you might want to move below too.
Good point.
Quoted 4 lines
Quoted 4 lines
tools/testing/selftests/net/mptcp/mptcp_diag.c +0
-0@@ -17,6 +12,12 @@#include <errno.h> #include <stdio.h>
Quoted 10 lines
tools/testing/selftests/net/mptcp/mptcp_diag.c line 19
Quoted 5 lines
tools/testing/selftests/net/mptcp/mptcp_diag.c +5
-0+#include <linux/sock_diag.h> +#include <linux/rtnetlink.h> +#include <linux/inet_diag.h> +#include <linux/netlink.h> +#include <linux/compiler.h> Note that I just noticed this is the only file from this directory where the "includes" are not sorted by type and alphabetical order, see
pm_nl_ctl.cas an example. A bit of a detail, but if you plan to send a v2, do you mind doing that too here while at it, please?
I'll send a v3 during the next cycle.
Quoted 2 lines
If not, I can look at that later, but better to avoid doing that in parallel.
If you want to fix this up already during this cycle, that would also be most welcome.
Thomas
Matthieu Baerts
maintainerRe: [PATCH net-next v2 1/4] selftests: net: Move some UAPI header inclusions after libc ones
Hi Thomas,
On 30/01/2026 11:22, Thomas Weißschuh wrote:
(...)
Quoted 6 lines
Quoted 4 lines
Note that I just noticed this is the only file from this directory where the "includes" are not sorted by type and alphabetical order, see
pm_nl_ctl.cas an example. A bit of a detail, but if you plan to send a v2, do you mind doing that too here while at it, please?I'll send a v3 during the next cycle.
Thanks!
Quoted 5 lines
Quoted 2 lines
If not, I can look at that later, but better to avoid doing that in parallel.
If you want to fix this up already during this cycle, that would also be most welcome.
Sure, I can do that.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
PATCH v2 2/4 selftests/landlock: Move some UAPI header inclusions after libc ones
In reply to Thomas WeißschuhInterleaving 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.
--- tools/testing/selftests/landlock/audit.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
tools/testing/selftests/landlock/audit.h +4 -3
@@ -7,9 +7,6 @@#define _GNU_SOURCE#include <errno.h> -#include <linux/audit.h> -#include <linux/limits.h> -#include <linux/netlink.h> #include <regex.h> #include <stdbool.h> #include <stdint.h>
@@ -20,6 +17,10 @@#include <sys/time.h> #include <unistd.h> +#include <linux/audit.h> +#include <linux/limits.h> +#include <linux/netlink.h> +#include "kselftest.h" #ifndef ARRAY_SIZE
Signature · 1 line
2.52.0
Re: [PATCH net-next v2 2/4] selftests/landlock: Move some UAPI header inclusions after libc ones
Quoted 4 lines · Thomas Weißschuh
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.
Quoted 8 lines
An upcoming change will define 'struct sockaddr' from
linux/socket.h. Howeversys/socket.hfrom 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 <[email protected]>
Thanks!
Quoted 34 lines
--- tools/testing/selftests/landlock/audit.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)tools/testing/selftests/landlock/audit.h +4
-3@@ -7,9 +7,6 @@#define _GNU_SOURCE#include <errno.h> -#include <linux/audit.h> -#include <linux/limits.h> -#include <linux/netlink.h> #include <regex.h> #include <stdbool.h> #include <stdint.h> @@ -20,6 +17,10 @@#include <sys/time.h> #include <unistd.h> +#include <linux/audit.h> +#include <linux/limits.h> +#include <linux/netlink.h> +#include "kselftest.h" #ifndef ARRAY_SIZE Signature · 2 lines
-- 2.52.0
PATCH v2 3/4 samples/bpf: Move some UAPI header inclusions after libc ones
In reply to Thomas WeißschuhInterleaving 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.
--- 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(-)
samples/bpf/xdp_adjust_tail_user.c +4 -2
@@ -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
samples/bpf/xdp_fwd_user.c +4 -3
@@ -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)
samples/bpf/xdp_router_ipv4_user.c +3 -3
@@ -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"
samples/bpf/xdp_sample_user.c +8 -7
@@ -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"
samples/bpf/xdp_tx_iptunnel_user.c +2 -2
@@ -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"
Signature · 1 line
2.52.0
PATCH v2 4/4 net: uapi: Provide an UAPI definition of 'struct sockaddr'
In reply to Thomas WeißschuhVarious UAPI headers reference 'struct sockaddr'. Currently the definition of this struct is pulled in from the libc header sys/socket.h. This is problematic as it introduces a dependency on a full userspace toolchain.
Instead expose a custom but compatible definition of 'struct sockaddr' in the UAPI headers. It is guarded by the libc compatibility infrastructure to avoid potential conflicts.
The compatibility symbol won't be supported by glibc right away, but right now __UAPI_DEF_IF_IFNAMSIZ is not supported either, so including the libc headers before the UAPI headers is broken anyways.
--- include/linux/socket.h | 10 ---------- include/uapi/linux/if.h | 4 ---- include/uapi/linux/libc-compat.h | 12 ++++++++++++ include/uapi/linux/socket.h | 14 ++++++++++++++ 4 files changed, 26 insertions(+), 14 deletions(-)
include/linux/socket.h +0 -10
@@ -28,16 +28,6 @@ extern void socket_seq_show(struct seq_file *seq);typedef __kernel_sa_family_t sa_family_t ; -/* -* 1003.1g requires sa_family_t and that sa_data is char. -*/ - -/* Deprecated for in-kernel use. Use struct sockaddr_unsized instead. */ -struct sockaddr { -sa_family_t sa_family;/* address family, AF_xxx */ -char sa_data[14 ];/* 14 bytes of protocol address */ -}; -/** * struct sockaddr_unsized - Unspecified size sockaddr for callbacks * @sa_family: Address family (AF_UNIX, AF_INET, AF_INET6, etc.)
include/uapi/linux/if.h +0 -4
@@ -25,10 +25,6 @@#include <linux/socket.h> /* for "struct sockaddr" et al */ #include <linux/compiler.h> /* for "__user" et al */ -#ifndef __KERNEL__ -#include <sys/socket.h> /* for struct sockaddr. */ -#endif -#if __UAPI_DEF_IF_IFNAMSIZ#define IFNAMSIZ 16#endif /* __UAPI_DEF_IF_IFNAMSIZ */
include/uapi/linux/libc-compat.h +12 -0
@@ -140,6 +140,13 @@#endif /* _NETINET_IN_H */ +/* Definitions for socket.h */ +#if defined(_SYS_SOCKET_H) +#define __UAPI_DEF_SOCKADDR 0 +#else +#define __UAPI_DEF_SOCKADDR 1 +#endif +/* Definitions for xattr.h */ #if defined(_SYS_XATTR_H)#define __UAPI_DEF_XATTR 0
@@ -221,6 +228,11 @@#define __UAPI_DEF_IP6_MTUINFO 1#endif +/* Definitions for socket.h */ +#ifndef __UAPI_DEF_SOCKADDR +#define __UAPI_DEF_SOCKADDR 1 +#endif +/* Definitions for xattr.h */ #ifndef __UAPI_DEF_XATTR#define __UAPI_DEF_XATTR 1
include/uapi/linux/socket.h +14 -0
@@ -2,6 +2,8 @@#ifndef _UAPI_LINUX_SOCKET_H#define _UAPI_LINUX_SOCKET_H +#include <linux/libc-compat.h> /* for compatibility with glibc */ +/* * Desired design of maximum size and alignment (see RFC2553) */
@@ -26,6 +28,18 @@ struct __kernel_sockaddr_storage { }; }; +/* +* 1003.1g requires sa_family_t and that sa_data is char. +*/ + +/* Deprecated for in-kernel use. Use struct sockaddr_unsized instead. */ +#if __UAPI_DEF_SOCKADDR +struct sockaddr { +__kernel_sa_family_t sa_family;/* address family, AF_xxx */ +char sa_data[14 ];/* 14 bytes of protocol address */ +}; +#endif /* __UAPI_DEF_SOCKADDR */ +#define SOCK_SNDBUF_LOCK 1#define SOCK_RCVBUF_LOCK 2
Signature · 1 line
2.52.0
Hi Thomas,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal (except selftest_mptcp_join): Success! ✅
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Success! ✅
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Unstable: 1 failed test(s): bpftest_test_progs-cpuv4_mptcp 🔴
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/21175122829
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/81d99f1609e4
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1044679
If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-normalFor more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
Jakub Kicinski
maintainerQuoted 18 lines · On Tue, 20 Jan 2026 15:10:30 +0100 Thomas Weißschuh wrote:
Various UAPI headers reference 'struct sockaddr'. Currently the definition of this struct is pulled in from the libc header
sys/socket.h. This is problematic as it introduces a dependency on a full userspace toolchain.Add a definition of 'struct sockaddr' to the UAPI headers. Before that, reorder some problematic header inclusions in the selftests.
include/linux/socket.h | 10 ---------- include/uapi/linux/if.h | 4 ---- include/uapi/linux/libc-compat.h | 12 ++++++++++++ include/uapi/linux/socket.h | 14 ++++++++++++++ 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 ++-- tools/testing/selftests/landlock/audit.h | 7 ++++---
Quoted 8 lines
tools/testing/selftests/net/af_unix/diag_uid.c | 9 +++++---- tools/testing/selftests/net/busy_poller.c | 3 ++- tools/testing/selftests/net/mptcp/mptcp_diag.c | 11 ++++++----- tools/testing/selftests/net/nettest.c | 4 ++-- tools/testing/selftests/net/tcp_ao/icmps-discard.c | 6 +++--- tools/testing/selftests/net/tcp_ao/lib/netlink.c | 9 +++++---- tools/testing/selftests/net/tun.c | 5 +++-- 17 files changed, 77 insertions(+), 55 deletions(-)
Are all those selftests / samples getting broken by this patch set?
I understand that we should avoid libc dependencies in uAPI but at least speaking for networking - building selftests without libc is.. not a practical proposition?
Quoted 28 lines · Jakub Kicinski
Quoted 18 lines · On Tue, 20 Jan 2026 15:10:30 +0100 Thomas Weißschuh wrote:
Various UAPI headers reference 'struct sockaddr'. Currently the definition of this struct is pulled in from the libc header
sys/socket.h. This is problematic as it introduces a dependency on a full userspace toolchain.Add a definition of 'struct sockaddr' to the UAPI headers. Before that, reorder some problematic header inclusions in the selftests.
include/linux/socket.h | 10 ---------- include/uapi/linux/if.h | 4 ---- include/uapi/linux/libc-compat.h | 12 ++++++++++++ include/uapi/linux/socket.h | 14 ++++++++++++++ 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 ++-- tools/testing/selftests/landlock/audit.h | 7 ++++---Quoted 8 lines
tools/testing/selftests/net/af_unix/diag_uid.c | 9 +++++---- tools/testing/selftests/net/busy_poller.c | 3 ++- tools/testing/selftests/net/mptcp/mptcp_diag.c | 11 ++++++----- tools/testing/selftests/net/nettest.c | 4 ++-- tools/testing/selftests/net/tcp_ao/icmps-discard.c | 6 +++--- tools/testing/selftests/net/tcp_ao/lib/netlink.c | 9 +++++---- tools/testing/selftests/net/tun.c | 5 +++-- 17 files changed, 77 insertions(+), 55 deletions(-)
Quoted 1 line
Are all those selftests / samples getting broken by this patch set?
Yes.
Some of them get broken by the new 'struct sockaddr', but some others are already broken just by the new transitive inclusion of libc-compat.h. So any header starting to use the compatibility machinery may trigger breakage in code including UAPI headers before libc header, even for completely new type definitions which themselves would not conflict with libc.
Quoted 3 lines
I understand that we should avoid libc dependencies in uAPI but at least speaking for networking - building selftests without libc is.. not a practical proposition?
I am not sure I understand. Some sort of libc will always be necessary. And as the selftests are intended to exercise the low-level kernel APIs, even those not supported by libc, the UAPI headers will also be necessary.
There is nolibc (tools/include/nolibc/) which is using the UAPI headers in most cases, and aims to be compatible. And can be and already is used for selftests, but it will be too limited for all of the networking selftests. (Disclaimer: I am maintaining nolibc)
My goal is *not* to make the different headers less compatible on purpose. But by removing the existing dependencies we can now enforce the checks in CONFIG_UAPI_HEADER_TEST to prevent any new ones from creeping in. Therefore preventing compatiblity issues in any new UAPI.
Thomas
Jakub Kicinski
maintainerQuoted 9 lines · On Fri, 30 Jan 2026 11:34:15 +0100 Thomas Weißschuh wrote:
Quoted 1 line
Are all those selftests / samples getting broken by this patch set?
Yes.
Some of them get broken by the new 'struct sockaddr', but some others are already broken just by the new transitive inclusion of
libc-compat.h. So any header starting to use the compatibility machinery may trigger breakage in code including UAPI headers before libc header, even for completely new type definitions which themselves would not conflict with libc.
Let's split the uAPI header changes from any selftest changes. If you're saying the the selftests no longer build after the uAPI header changes then of course we can't apply the patches.
Jan 30, 2026 17:17:46 Jakub Kicinski <[email protected]>:
Quoted 11 lines · On Fri, 30 Jan 2026 11:34:15 +0100 Thomas Weißschuh wrote:
Quoted 9 lines
Quoted 1 line
Are all those selftests / samples getting broken by this patch set?
Yes.
Some of them get broken by the new 'struct sockaddr', but some others are already broken just by the new transitive inclusion of
libc-compat.h. So any header starting to use the compatibility machinery may trigger breakage in code including UAPI headers before libc header, even for completely new type definitions which themselves would not conflict with libc.
Quoted 3 lines
Let's split the uAPI header changes from any selftest changes. If you're saying the the selftests no longer build after the uAPI header changes then of course we can't apply the patches.
Yes, the selftests don't build anymore after the uAPI changes.
"can't apply" as in
* "can't apply separately"
* "are unacceptable in general"
* "are too late for this cycle"
?
None of this is urgent.
We can do the selftests in one cycle and the uAPI in another one. Feel free to pick up the patches as you see fit.
(The mptcp changes already go through their tree, so need to be dropped here) I can also resubmit the patches differently if preferred.
Thomas
Jakub Kicinski
maintainerQuoted 13 lines · On Sat, 31 Jan 2026 11:26:32 +0100 Thomas Weißschuh wrote:
Jan 30, 2026 17:17:46 Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Fri, 30 Jan 2026 11:34:15 +0100 Thomas Weißschuh wrote:
Quoted 5 lines
Some of them get broken by the new 'struct sockaddr', but some others are already broken just by the new transitive inclusion of
libc-compat.h. So any header starting to use the compatibility machinery may trigger breakage in code including UAPI headers before libc header, even for completely new type definitions which themselves would not conflict with libc.Let's split the uAPI header changes from any selftest changes. If you're saying the the selftests no longer build after the uAPI header changes then of course we can't apply the patches.
Quoted 5 lines
Yes, the selftests don't build anymore after the uAPI changes.
"can't apply" as in
* "can't apply separately"
* "are unacceptable in general"
this one
Quoted 8 lines
* "are too late for this cycle"
?None of this is urgent.
We can do the selftests in one cycle and the uAPI in another one. Feel free to pick up the patches as you see fit.
(The mptcp changes already go through their tree, so need to be dropped here) I can also resubmit the patches differently if preferred.
The selftests are just a canary in the coalmine. If we break a bunch of selftests chances are we'll also break compilation of real applications for people. Subjective, but I don't see a sufficient upside here to do that.
FWIW the typelimits change broke compilation of ethtool, we'll see if anyone "outside kernel community itself" complains.
Quoted 31 lines · Jakub Kicinski
Quoted 13 lines · On Sat, 31 Jan 2026 11:26:32 +0100 Thomas Weißschuh wrote:
Jan 30, 2026 17:17:46 Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Fri, 30 Jan 2026 11:34:15 +0100 Thomas Weißschuh wrote:
Quoted 5 lines
Some of them get broken by the new 'struct sockaddr', but some others are already broken just by the new transitive inclusion of
libc-compat.h. So any header starting to use the compatibility machinery may trigger breakage in code including UAPI headers before libc header, even for completely new type definitions which themselves would not conflict with libc.Let's split the uAPI header changes from any selftest changes. If you're saying the the selftests no longer build after the uAPI header changes then of course we can't apply the patches.
Quoted 5 lines
Yes, the selftests don't build anymore after the uAPI changes.
"can't apply" as in
* "can't apply separately"
* "are unacceptable in general"this one
Quoted 8 lines
* "are too late for this cycle"
?None of this is urgent.
We can do the selftests in one cycle and the uAPI in another one. Feel free to pick up the patches as you see fit.
(The mptcp changes already go through their tree, so need to be dropped here) I can also resubmit the patches differently if preferred.
Quoted 4 lines
The selftests are just a canary in the coalmine. If we break a bunch of selftests chances are we'll also break compilation of real applications for people. Subjective, but I don't see a sufficient upside here to do that.
Okay. We'll have around this inconsistency then.
Quoted 2 lines
FWIW the typelimits change broke compilation of ethtool, we'll see if anyone "outside kernel community itself" complains.
Can you point me to that breakage? I was unable to find it.
Thomas
Jakub Kicinski
maintainerQuoted 4 lines · On Tue, 3 Feb 2026 12:42:22 +0100 Thomas Weißschuh wrote:
Quoted 2 lines
FWIW the typelimits change broke compilation of ethtool, we'll see if anyone "outside kernel community itself" complains.
Can you point me to that breakage? I was unable to find it.
Not reported on the ML, and it's kinda annoying to repro because the uAPI header sync script isn't committed :/ You have to check this out
https://git.kernel.org/pub/scm/network/ethtool/ethtool.git/
and run a script like this to sync headers from the kernel (then build):
#!/bin/bash -e
sn="${0##*/}"
export ARCH="x86_64"
if [ ! -d "$LINUX_GIT" ]; then
echo "${sn}: LINUX_GIT not set" >&2
exit 1fi
pushd "$LINUX_GIT"
if [ -n "$1" ]; then
git checkout "$1"
fi
desc=$(git describe --exact-match 2>/dev/null \
|| git show -s --abbrev=12 --pretty='commit %h')kobj=$(mktemp -d)
make -j16 O="$kobj" allmodconfig
make -j16 O="$kobj" prepare
make -j16 O="$kobj" INSTALL_HDR_PATH="${kobj}/hdr" headers_install popd
pushd uapi
find . -type f -name '*.h' -exec cp -v "${kobj}/hdr/include/{}" {} \; popd
rm -rf "$kobj"
git add uapi
git commit -s -F - <<EOT
update UAPI header copies
Update to kernel ${desc}.
EOT
Quoted 28 lines · Jakub Kicinski
Quoted 4 lines · On Tue, 3 Feb 2026 12:42:22 +0100 Thomas Weißschuh wrote:
Quoted 2 lines
FWIW the typelimits change broke compilation of ethtool, we'll see if anyone "outside kernel community itself" complains.
Can you point me to that breakage? I was unable to find it.
Not reported on the ML, and it's kinda annoying to repro because the uAPI header sync script isn't committed :/ You have to check this out
https://git.kernel.org/pub/scm/network/ethtool/ethtool.git/
and run a script like this to sync headers from the kernel (then build):
#!/bin/bash -e
sn="${0##*/}"
export ARCH="x86_64"if [ ! -d "$LINUX_GIT" ]; then
echo "${sn}: LINUX_GIT not set" >&2 exit 1fi
pushd "$LINUX_GIT"
if [ -n "$1" ]; then
git checkout "$1"
fi
Quoted 6 lines
desc=$(git describe --exact-match 2>/dev/null \ || git show -s --abbrev=12 --pretty='commit %h')kobj=$(mktemp -d)
make -j16 O="$kobj" allmodconfig
make -j16 O="$kobj" prepare
These are not necessary.
The UAPI generation does not need a kernel configuration.
Quoted 5 lines
make -j16 O="$kobj" INSTALL_HDR_PATH="${kobj}/hdr"
headers_installpopdpushd uapi
find . -type f -name '*.h' -exec cp -v "${kobj}/hdr/include/{}" {} \;
Here only those headers which already exist in ethtool's uapi/ directory are copied. As linux/typelimits.h is new, it is now missing. Honestly, if a user fiddles with the internals of the UAPI headers like this, it is on them to update their code if the internal structure changes. In your case a simple 'touch uapi/linux/typelimits.h' before running the script will be enough. Also internal.h now requires an explicit inclusion of <limits.h>, as that is not satisfied by the UAPI anymore.
Quoted 10 lines
popd
rm -rf "$kobj"git add uapi
git commit -s -F - <<EOT
update UAPI header copiesUpdate to kernel ${desc}.
EOT
Jakub Kicinski
maintainerQuoted 6 lines · On Wed, 4 Feb 2026 06:51:46 +0100 Thomas Weißschuh wrote:
Quoted 5 lines
make -j16 O="$kobj" INSTALL_HDR_PATH="${kobj}/hdr"
headers_installpopdpushd uapi
find . -type f -name '*.h' -exec cp -v "${kobj}/hdr/include/{}" {} \;
Quoted 8 lines
Here only those headers which already exist in ethtool's uapi/ directory are copied. As
linux/typelimits.his new, it is now missing. Honestly, if a user fiddles with the internals of the UAPI headers like this, it is on them to update their code if the internal structure changes. In your case a simple 'touchuapi/linux/typelimits.h' before running the script will be enough. Alsointernal.hnow requires an explicit inclusion of <limits.h>, as that is not satisfied by the UAPI anymore.
Hopefully you understand that while due to uapi header copy this is not a huge issue for ethtool itself, but it is a proof that your changes can break normal user space applications which do not vendor in uapi.
Quoted 16 lines · Jakub Kicinski
Quoted 6 lines · On Wed, 4 Feb 2026 06:51:46 +0100 Thomas Weißschuh wrote:
Quoted 5 lines
make -j16 O="$kobj" INSTALL_HDR_PATH="${kobj}/hdr"
headers_installpopdpushd uapi
find . -type f -name '*.h' -exec cp -v "${kobj}/hdr/include/{}" {} \;Quoted 8 lines
Here only those headers which already exist in ethtool's uapi/ directory are copied. As
linux/typelimits.his new, it is now missing. Honestly, if a user fiddles with the internals of the UAPI headers like this, it is on them to update their code if the internal structure changes. In your case a simple 'touchuapi/linux/typelimits.h' before running the script will be enough. Alsointernal.hnow requires an explicit inclusion of <limits.h>, as that is not satisfied by the UAPI anymore.
Quoted 3 lines
Hopefully you understand that while due to uapi header copy this is not a huge issue for ethtool itself, but it is a proof that your changes can break normal user space applications which do not vendor in uapi.
A regular application which uses a full UAPI headers tree will get access to the new header automatically.
If the application uses symbols from <limits.h> without including <limits.h> on its own, it is broken.
Thomas