socket-util: add helper for querying the local AF_VSOCK CID

This commit is contained in:
Lennart Poettering 2024-01-05 16:33:58 +01:00
parent 96f1f03c03
commit d3109d8de0
2 changed files with 17 additions and 0 deletions

View file

@ -1753,3 +1753,18 @@ int socket_address_parse_vsock(SocketAddress *ret_address, const char *s) {
return 0;
}
int vsock_get_local_cid(unsigned *ret) {
_cleanup_close_ int vsock_fd = -EBADF;
assert(ret);
vsock_fd = open("/dev/vsock", O_RDONLY|O_CLOEXEC);
if (vsock_fd < 0)
return log_debug_errno(errno, "Failed to open /dev/vsock: %m");
if (ioctl(vsock_fd, IOCTL_VM_SOCKETS_GET_LOCAL_CID, ret) < 0)
return log_debug_errno(errno, "Failed to query local AF_VSOCK CID: %m");
return 0;
}

View file

@ -389,3 +389,5 @@ int socket_address_parse_vsock(SocketAddress *ret_address, const char *s);
* /proc/sys/net/core/somaxconn anyway, thus by setting this to unbounded we just make that sysctl file
* authoritative. */
#define SOMAXCONN_DELUXE INT_MAX
int vsock_get_local_cid(unsigned *ret);