From: Masatake YAMATO Date: Wed, 24 Dec 2025 21:54:13 +0000 (+0900) Subject: lsfd,test_mkfds: make linux/vm_sockets_diag.h optional X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3a3a77bfe008c405f364b4563bd2c927e2053aa7;p=thirdparty%2Futil-linux.git lsfd,test_mkfds: make linux/vm_sockets_diag.h optional 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 Signed-off-by: Masatake YAMATO --- diff --git a/configure.ac b/configure.ac index a424e0947..2ff5c0d32 100644 --- a/configure.ac +++ b/configure.ac @@ -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 \ diff --git a/lsfd-cmd/sock-xinfo.c b/lsfd-cmd/sock-xinfo.c index 78986eb46..7e6ca0cf8 100644 --- a/lsfd-cmd/sock-xinfo.c +++ b/lsfd-cmd/sock-xinfo.c @@ -35,7 +35,9 @@ #include /* UNIX_DIAG_*, UDIAG_SHOW_*, struct unix_diag_req */ #include /* VMADDR_CID* */ -#include /* vsock_diag_req/vsock_diag_msg */ +#if HAVE_LINUX_VM_SOCKETS_DIAG_H +# include /* vsock_diag_req/vsock_diag_msg */ +#endif #include /* for setns(2) */ #include /* tfind, tsearch */ #include @@ -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 */ diff --git a/meson.build b/meson.build index 8b7880e46..c09342b1f 100644 --- a/meson.build +++ b/meson.build @@ -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 diff --git a/tests/helpers/test_mkfds.c b/tests/helpers/test_mkfds.c index 57f99e5a3..299c23b83 100644 --- a/tests/helpers/test_mkfds.c +++ b/tests/helpers/test_mkfds.c @@ -39,7 +39,9 @@ # include /* for UNIX domain sockets */ #include /* SIOCGSKNS */ #include -#include /* vsock_diag_req/vsock_diag_msg */ +#if HAVE_LINUX_VM_SOCKETS_DIAG_H +# include /* vsock_diag_req/vsock_diag_msg */ +#endif #include #include #include @@ -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