vsock-util: allow VMADDR_CID_ANY as local CID if enabled in hwdb

On Hyper-V guests, `VMADDR_CID_ANY` is valid as per implementation in
kernel driver: net/vmw_vsock/hyperv_transport.c.

Fixes https://github.com/systemd/systemd/issues/42496

Follow-up for 83359c4da0
This commit is contained in:
Chitoku
2026-06-13 15:54:50 +02:00
committed by Zbigniew Jędrzejewski-Szmek
parent 92e4afc4d3
commit 85afe8e82d
11 changed files with 114 additions and 29 deletions
-24
View File
@@ -1798,30 +1798,6 @@ 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;
vsock_fd = open("/dev/vsock", O_RDONLY|O_CLOEXEC);
if (vsock_fd < 0)
return log_debug_errno(errno, "Failed to open %s: %m", "/dev/vsock");
unsigned tmp;
if (ioctl(vsock_fd, IOCTL_VM_SOCKETS_GET_LOCAL_CID, &tmp) < 0)
return log_debug_errno(errno, "Failed to query local AF_VSOCK CID: %m");
log_debug("Local AF_VSOCK CID: %u", tmp);
/* If ret == NULL, we're just want to check if AF_VSOCK is available, so accept
* any address. Otherwise, filter out special addresses that are cannot be used
* to identify _this_ machine from the outside. */
if (ret && IN_SET(tmp, VMADDR_CID_LOCAL, VMADDR_CID_HOST, VMADDR_CID_ANY))
return log_debug_errno(SYNTHETIC_ERRNO(EADDRNOTAVAIL),
"IOCTL_VM_SOCKETS_GET_LOCAL_CID returned special value (%u), ignoring.", tmp);
if (ret)
*ret = tmp;
return 0;
}
int netlink_socket_get_multicast_groups(int fd, size_t *ret_len, uint32_t **ret_groups) {
_cleanup_free_ uint32_t *groups = NULL;
socklen_t len = 0, old_len;
-2
View File
@@ -261,8 +261,6 @@ int socket_address_equal_unix(const char *a, const char *b);
* authoritative. */
#define SOMAXCONN_DELUXE INT_MAX
int vsock_get_local_cid(unsigned *ret);
int netlink_socket_get_multicast_groups(int fd, size_t *ret_len, uint32_t **ret_groups);
int socket_get_cookie(int fd, uint64_t *ret);