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.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
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(-)
diff --git a/tools/testing/selftests/net/af_unix/diag_uid.c b/tools/testing/selftests/net/af_unix/diag_uid.c
index da7d50cedee6..05456a205325 100644
--- a/tools/testing/selftests/net/af_unix/diag_uid.c
+++ b/tools/testing/selftests/net/af_unix/diag_uid.c
@@ -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)
diff --git a/tools/testing/selftests/net/busy_poller.c b/tools/testing/selftests/net/busy_poller.c
index 3a81f9c94795..34bd8d28808a 100644
--- a/tools/testing/selftests/net/busy_poller.c
+++ b/tools/testing/selftests/net/busy_poller.c
@@ -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>
diff --git a/tools/testing/selftests/net/mptcp/mptcp_diag.c b/tools/testing/selftests/net/mptcp/mptcp_diag.c
index 8e0b1b8d84b6..af25ebfd2915 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_diag.c
+++ b/tools/testing/selftests/net/mptcp/mptcp_diag.c
@@ -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
diff --git a/tools/testing/selftests/net/nettest.c b/tools/testing/selftests/net/nettest.c
index 1f5227f3d64d..71430403b50b 100644
--- a/tools/testing/selftests/net/nettest.c
+++ b/tools/testing/selftests/net/nettest.c
@@ -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>
diff --git a/tools/testing/selftests/net/tcp_ao/icmps-discard.c b/tools/testing/selftests/net/tcp_ao/icmps-discard.c
index 85c1a1e958c6..451ba89914c9 100644
--- a/tools/testing/selftests/net/tcp_ao/icmps-discard.c
+++ b/tools/testing/selftests/net/tcp_ao/icmps-discard.c
@@ -16,12 +16,12 @@
* Author: Dmitry Safonov <dima@arista.com>
*/
#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"
diff --git a/tools/testing/selftests/net/tcp_ao/lib/netlink.c b/tools/testing/selftests/net/tcp_ao/lib/netlink.c
index 7f108493a29a..69a05820782a 100644
--- a/tools/testing/selftests/net/tcp_ao/lib/netlink.c
+++ b/tools/testing/selftests/net/tcp_ao/lib/netlink.c
@@ -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
diff --git a/tools/testing/selftests/net/tun.c b/tools/testing/selftests/net/tun.c
index 0efc67b0357a..e6e4c52d538e 100644
--- a/tools/testing/selftests/net/tun.c
+++ b/tools/testing/selftests/net/tun.c
@@ -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"
--
2.52.0
Hi Thomas, On 20/01/2026 15:10, Thomas Weißschuh wrote: > 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. Thank you for looking at this! Here is my (late, sorry) review for the modifications related to MPTCP: > diff --git a/tools/testing/selftests/net/mptcp/mptcp_diag.c b/tools/testing/selftests/net/mptcp/mptcp_diag.c > index 8e0b1b8d84b6..af25ebfd2915 100644 > --- a/tools/testing/selftests/net/mptcp/mptcp_diag.c > +++ b/tools/testing/selftests/net/mptcp/mptcp_diag.c > @@ -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> There is a remaining one (linux/tcp.h) here that you might want to move below too. > @@ -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 -- Sponsored by the NGI0 Core fund.
(trimmed the recipient list) Hi Matt, On Mon, Jan 26, 2026 at 07:13:50PM +0100, Matthieu Baerts wrote: > On 20/01/2026 15:10, Thomas Weißschuh wrote: > > 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. > > Thank you for looking at this! > > Here is my (late, sorry) review for the modifications related to MPTCP: > > diff --git a/tools/testing/selftests/net/mptcp/mptcp_diag.c b/tools/testing/selftests/net/mptcp/mptcp_diag.c > > index 8e0b1b8d84b6..af25ebfd2915 100644 > > --- a/tools/testing/selftests/net/mptcp/mptcp_diag.c > > +++ b/tools/testing/selftests/net/mptcp/mptcp_diag.c > > @@ -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> > > There is a remaining one (linux/tcp.h) here that you might want to move > below too. Good point. > > @@ -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? I'll send a v3 during the next cycle. > 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
Hi Thomas, On 30/01/2026 11:22, Thomas Weißschuh wrote: (...) >> 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? > > I'll send a v3 during the next cycle. Thanks! >> 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 -- Sponsored by the NGI0 Core fund.
© 2016 - 2026 Red Hat, Inc.