From f8c6ff1fc1415c3e66450ba45e55ca35ac7f0846 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Wed, 1 May 2024 14:50:16 +0200 Subject: [PATCH] streams: Add ability to listen on any VSOCK CID Can be useful if the CID inside the VM is not known. The \htmlonly\endhtmlonly hack is used to avoid compiler warnings due to /* inside a block comment. --- src/libstrongswan/networking/streams/stream_vsock.c | 11 ++++++++++- src/libstrongswan/networking/streams/stream_vsock.h | 6 +++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/libstrongswan/networking/streams/stream_vsock.c b/src/libstrongswan/networking/streams/stream_vsock.c index 4cfab426e..5a2eed5ca 100644 --- a/src/libstrongswan/networking/streams/stream_vsock.c +++ b/src/libstrongswan/networking/streams/stream_vsock.c @@ -1,4 +1,5 @@ /* + * Copyright (C) 2024 Tobias Brunner * Copyright (C) 2024 Thomas Egerer * * Copyright (C) secunet Security Networks AG @@ -40,7 +41,15 @@ static int stream_parse_uri_vsock(char *uri, struct sockaddr_vm *addr) } uri += strlen("vsock://"); - cid = strtoul(uri, &uri, 10); + if (*uri == '*') + { + cid = VMADDR_CID_ANY; + uri++; + } + else + { + cid = strtoul(uri, &uri, 10); + } if (*uri != ':' || cid > UINT_MAX) { diff --git a/src/libstrongswan/networking/streams/stream_vsock.h b/src/libstrongswan/networking/streams/stream_vsock.h index 14ef11a0f..3950a9ae5 100644 --- a/src/libstrongswan/networking/streams/stream_vsock.h +++ b/src/libstrongswan/networking/streams/stream_vsock.h @@ -1,4 +1,5 @@ /* + * Copyright (C) 2024 Tobias Brunner * Copyright (C) 2024 Thomas Egerer * * Copyright (C) secunet Security Networks AG @@ -29,7 +30,10 @@ * identifier, CID), followed by a colon separated port. CID as well as port * are 32-bit unsigned integers. A full VSOCK uri looks something like: * - * vsock://2:12345 + * * vsock://1:12345 (loopback) + * * vsock://2:12345 (connect from the VM to the well-known CID of the host) + * * vsock://3:12345 (CID 3 as assigned to a VM) + * * vsock://\htmlonly\endhtmlonly*:12345 (listen on any CID) * * There is no default port, so a colon after vsock:// is mandatory. *