From 2882ac6976f68d845caab50f290bc3f3ee77a1ea Mon Sep 17 00:00:00 2001 From: Gerhard Rieger Date: Sun, 30 Oct 2022 11:25:19 +0100 Subject: [PATCH] VSOCK: short alias names, env var with peer info --- CHANGES | 7 +++++++ test.sh | 4 ++++ xio-socket.c | 18 +++++++++++++++++- xio-vsock.c | 30 +++++++++++++++++++++++++++++- xio-vsock.h | 4 ++++ xioopen.c | 2 ++ 6 files changed, 63 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 26a1b2f..2bb7622 100644 --- a/CHANGES +++ b/CHANGES @@ -85,6 +85,10 @@ Features: Filan prints target of symlink when appropriate Test: FILANSYMLINK + VSOCK-LISTEN now generates environment variables SOCAT_PEERADDR, + SOCAT_PEERPORT, SOCAT_SOCKADDR, SOCAT_SOCKPORT + New address aliases VSOCK, VSOCK-L + Documentation: Fixed typo in doc/socat-tun.html and link in README. Thanks to William Suthers for reporting. @@ -128,6 +132,9 @@ Testing: not in kernel. test.sh now detects this situation and reacts with warnings. + VSOCK loopback still does not seem to work even in kernel 5.13, so just + issue warning on "No such device". + ####################### V 1.7.4.3: Corrections: diff --git a/test.sh b/test.sh index 2b80b76..40a4820 100755 --- a/test.sh +++ b/test.sh @@ -14736,6 +14736,10 @@ elif [ $rc1 -ne 0 ] && [ "$UNAME" = Linux ] && ! [[ $UNAME_R =~ ^[6-9]\.* ]] && $PRINTF "${YELLOW}works only on Linux from 5.6${NORMAL}\n" $N numCANT=$((numCANT+1)) listCANT="$listCANT $N" +elif grep -q "No such device" "${te}1"; then + $PRINTF "${YELLOW}Loopback does not work${NORMAL}\n" $N + numCANT=$((numCANT+1)) + listCANT="$listCANT $N" elif [ $rc1 -ne 0 ]; then $PRINTF "$FAILED\n" echo "$CMD0 &" >&2 diff --git a/xio-socket.c b/xio-socket.c index 465aaaf..a81ddf8 100644 --- a/xio-socket.c +++ b/xio-socket.c @@ -14,6 +14,9 @@ #include "xio-socket.h" #include "xio-named.h" #include "xio-unix.h" +#if WITH_VSOCK +#include "xio-vsock.h" +#endif #if WITH_IP4 #include "xio-ip4.h" #endif /* WITH_IP4 */ @@ -2069,8 +2072,21 @@ int xiosetsockaddrenv(const char *lr, xiosetenv(namebuff, valuebuff, 1, NULL); namebuff[strlen(lr)] = '\0'; ++idx; } while (result > 0); - break; + break; #endif /* WITH_IP6 */ +#if WITH_VSOCK + case PF_VSOCK: + strcpy(namebuff, lr); + do { + result = + xiosetsockaddrenv_vsock(idx, strchr(namebuff, '\0'), XIOSOCKADDRENVLEN-strlen(lr), + valuebuff, XIOSOCKADDRENVLEN, + &sau->vm, proto); + xiosetenv(namebuff, valuebuff, 1, NULL); + namebuff[strlen(lr)] = '\0'; ++idx; + } while (result > 0); + break; +#endif /* WITH_VSOCK */ #if LATER case PF_PACKET: result = xiosetsockaddrenv_packet(lr, (void *)sau, proto); break; diff --git a/xio-vsock.c b/xio-vsock.c index 5078e9c..957707a 100644 --- a/xio-vsock.c +++ b/xio-vsock.c @@ -3,7 +3,7 @@ /* Author: Stefano Garzarella svm_cid); + return 1; + case 1: + strcpy(namebuff, "PORT"); + snprintf(valuebuff, valuelen, F_uint32_t, sa->svm_port); + return 0; + } + return -1; +} + #endif /* WITH_VSOCK */ diff --git a/xio-vsock.h b/xio-vsock.h index 20e36a4..0e88036 100644 --- a/xio-vsock.h +++ b/xio-vsock.h @@ -8,4 +8,8 @@ extern const struct addrdesc addr_vsock_connect; extern const struct addrdesc addr_vsock_listen; +extern int xiosetsockaddrenv_vsock(int idx, char *namebuff, size_t namelen, + char *valuebuff, size_t valuelen, + struct sockaddr_vm *sa, int ipproto); + #endif /* !defined(__xio_vsock_h_included) */ diff --git a/xioopen.c b/xioopen.c index d822e38..50b449f 100644 --- a/xioopen.c +++ b/xioopen.c @@ -308,9 +308,11 @@ const struct addrname addressnames[] = { { "unix-sendto", &xioaddr_unix_sendto }, #endif #if WITH_VSOCK + { "vsock", &addr_vsock_connect }, { "vsock-connect", &addr_vsock_connect }, #endif #if WITH_VSOCK && WITH_LISTEN + { "vsock-l", &addr_vsock_listen }, { "vsock-listen", &addr_vsock_listen }, #endif #else /* !0 */