]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd,test_mkfds: make linux/vm_sockets_diag.h optional
authorMasatake YAMATO <yamato@redhat.com>
Wed, 24 Dec 2025 21:54:13 +0000 (06:54 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Mon, 29 Dec 2025 07:07:17 +0000 (16:07 +0900)
Older kernels (at least 3.10 used by CentOS/RH/OEL 7.9) do not have
linux/vm_sockets_diag.h yet.

Closes: https://github.com/util-linux/util-linux/issues/3916
Co-Author: Fabian Groffen <grobian@bitzolder.nl>
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
configure.ac
lsfd-cmd/sock-xinfo.c
meson.build
tests/helpers/test_mkfds.c

index a424e09476bb1350b762d2132fcac149b7a735f3..2ff5c0d32a74e55e90335b06f394d5aabf2643e0 100644 (file)
@@ -353,6 +353,7 @@ AC_CHECK_HEADERS([ \
        linux/securebits.h \
        linux/tiocl.h \
        linux/version.h \
+       linux/vm_sockets_diag.h \
        linux/watchdog.h \
        linux/if_alg.h \
        locale.h \
index 78986eb46792f1fae7b58fa3ba0a75bf452c821c..7e6ca0cf89e105ecc21ed705bad72684e93aa445 100644 (file)
@@ -35,7 +35,9 @@
 #include <linux/unix_diag.h>   /* UNIX_DIAG_*, UDIAG_SHOW_*,
                                   struct unix_diag_req */
 #include <linux/vm_sockets.h>  /* VMADDR_CID* */
-#include <linux/vm_sockets_diag.h> /* vsock_diag_req/vsock_diag_msg */
+#if HAVE_LINUX_VM_SOCKETS_DIAG_H
+# include <linux/vm_sockets_diag.h> /* vsock_diag_req/vsock_diag_msg */
+#endif
 #include <sched.h>             /* for setns(2) */
 #include <search.h>            /* tfind, tsearch */
 #include <stdint.h>
@@ -2629,6 +2631,7 @@ static void load_xinfo_from_proc_packet(ino_t netns_inode)
 /*
  * VSOCK
  */
+#if HAVE_LINUX_VM_SOCKETS_DIAG_H
 struct vsock_addr {
        uint32_t cid;
        uint32_t port;
@@ -2837,3 +2840,9 @@ static void load_xinfo_from_diag_vsock(int diagsd, ino_t netns)
 
        send_diag_request(diagsd, &vdr, sizeof(vdr), handle_diag_vsock, netns);
 }
+#else
+static void load_xinfo_from_diag_vsock(int diagsd __attribute__((__unused__)),
+                                      ino_t netns __attribute__((__unused__)))
+{
+}
+#endif /* HAVE_LINUX_VM_SOCKETS_DIAG_H */
index 8b7880e465d7c5cbbe69310664c4d0a21726649a..c09342b1f66572ee8fcfe845442fb427daffb84d 100644 (file)
@@ -232,6 +232,7 @@ headers = '''
         linux/securebits.h
         linux/tiocl.h
         linux/version.h
+        linux/vm_sockets_diag.h
         linux/watchdog.h
         mqueue.h
         net/if.h
index 57f99e5a3bad34af4917efbcdf3dce27c826530a..299c23b838f25213ce1a144c28a2fdd9849686cb 100644 (file)
@@ -39,7 +39,9 @@
 # include <linux/unix_diag.h> /* for UNIX domain sockets */
 #include <linux/sockios.h>  /* SIOCGSKNS */
 #include <linux/vm_sockets.h>
-#include <linux/vm_sockets_diag.h> /* vsock_diag_req/vsock_diag_msg */
+#if HAVE_LINUX_VM_SOCKETS_DIAG_H
+# include <linux/vm_sockets_diag.h> /* vsock_diag_req/vsock_diag_msg */
+#endif
 #include <mqueue.h>
 #include <net/if.h>
 #include <netinet/in.h>
@@ -2024,7 +2026,7 @@ static void *make_ping6(const struct factory *factory, struct fdesc fdescs[],
                                (struct sockaddr *)&in6);
 }
 
-#if HAVE_DECL_VMADDR_CID_LOCAL
+#if HAVE_DECL_VMADDR_CID_LOCAL && HAVE_LINUX_VM_SOCKETS_DIAG_H
 static void *make_vsock(const struct factory *factory, struct fdesc fdescs[],
                        int argc, char ** argv)
 {
@@ -2161,7 +2163,7 @@ static void *make_vsock(const struct factory *factory, struct fdesc fdescs[],
        };
        return NULL;
 }
-#endif /* HAVE_DECL_VMADDR_CID_LOCAL */
+#endif /* HAVE_DECL_VMADDR_CID_LOCAL && HAVE_LINUX_VM_SOCKETS_DIAG_H */
 
 #ifdef SIOCGSKNS
 static void *make_netns(const struct factory *factory _U_, struct fdesc fdescs[],
@@ -3237,12 +3239,16 @@ static void *make_sockdiag(const struct factory *factory, struct fdesc fdescs[],
        size_t reqlen = 0;
        int e;
        struct unix_diag_req udr;
+#if HAVE_LINUX_VM_SOCKETS_DIAG_H
        struct vsock_diag_req vdr;
+#endif /* HAVE_LINUX_VM_SOCKETS_DIAG_H */
 
        if (strcmp(sfamily, "unix") == 0)
                ifamily = AF_UNIX;
+#if HAVE_LINUX_VM_SOCKETS_DIAG_H
        else if (strcmp(sfamily, "vsock") == 0)
                ifamily = AF_VSOCK;
+#endif /* HAVE_LINUX_VM_SOCKETS_DIAG_H */
        else
                errx(EXIT_FAILURE, "unknown/unsupported family: %s", sfamily);
 
@@ -3269,7 +3275,9 @@ static void *make_sockdiag(const struct factory *factory, struct fdesc fdescs[],
                };
                req = &udr;
                reqlen = sizeof(udr);
-       } else if (ifamily == AF_VSOCK) {
+       }
+#if HAVE_LINUX_VM_SOCKETS_DIAG_H
+       else if (ifamily == AF_VSOCK) {
                vdr = (struct vsock_diag_req) {
                        .sdiag_family = AF_VSOCK,
                        .vdiag_states = ~(uint32_t)0,
@@ -3277,6 +3285,7 @@ static void *make_sockdiag(const struct factory *factory, struct fdesc fdescs[],
                req = &vdr;
                reqlen = sizeof(vdr);
        }
+#endif /* HAVE_LINUX_VM_SOCKETS_DIAG_H  */
 
        e = send_diag_request(diagsd, req, reqlen);
        if (e) {
@@ -3986,7 +3995,7 @@ static const struct factory factories[] = {
                        PARAM_END
                }
        },
-#if HAVE_DECL_VMADDR_CID_LOCAL
+#if HAVE_DECL_VMADDR_CID_LOCAL && HAVE_LINUX_VM_SOCKETS_DIAG_H
        {
                "vsock",
                .desc = "AF_VSOCK sockets",
@@ -4016,7 +4025,7 @@ static const struct factory factories[] = {
                        PARAM_END
                }
        },
-#endif /* HAVE_DECL_VMADDR_CID_LOCAL */
+#endif /* HAVE_DECL_VMADDR_CID_LOCAL && HAVE_LINUX_VM_SOCKETS_DIAG_H */
 #ifdef SIOCGSKNS
        {
                .name = "netns",
@@ -4314,7 +4323,11 @@ static const struct factory factories[] = {
                                .name = "family",
                                .type = PTYPE_STRING,
                                /* TODO: inet, inet6 */
-                               .desc = "name of a protocol family ([unix]|vsock)",
+                               .desc = "name of a protocol family ([unix]"
+#if HAVE_LINUX_VM_SOCKETS_DIAG_H
+                               "|vsock"
+#endif /* HAVE_LINUX_VM_SOCKETS_DIAG_H */
+                               ")",
                                .defv.string = "unix",
                        },
                        PARAM_END