mirror of
https://repo.or.cz/socat.git
synced 2024-12-22 23:42:34 +00:00
VSOCK: short alias names, env var with peer info
This commit is contained in:
parent
cb03d2f075
commit
2882ac6976
6 changed files with 63 additions and 2 deletions
7
CHANGES
7
CHANGES
|
@ -85,6 +85,10 @@ Features:
|
||||||
Filan prints target of symlink when appropriate
|
Filan prints target of symlink when appropriate
|
||||||
Test: FILANSYMLINK
|
Test: FILANSYMLINK
|
||||||
|
|
||||||
|
VSOCK-LISTEN now generates environment variables SOCAT_PEERADDR,
|
||||||
|
SOCAT_PEERPORT, SOCAT_SOCKADDR, SOCAT_SOCKPORT
|
||||||
|
New address aliases VSOCK, VSOCK-L
|
||||||
|
|
||||||
Documentation:
|
Documentation:
|
||||||
Fixed typo in doc/socat-tun.html and link in README.
|
Fixed typo in doc/socat-tun.html and link in README.
|
||||||
Thanks to William Suthers for reporting.
|
Thanks to William Suthers for reporting.
|
||||||
|
@ -128,6 +132,9 @@ Testing:
|
||||||
not in kernel. test.sh now detects this situation and reacts with
|
not in kernel. test.sh now detects this situation and reacts with
|
||||||
warnings.
|
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:
|
####################### V 1.7.4.3:
|
||||||
|
|
||||||
Corrections:
|
Corrections:
|
||||||
|
|
4
test.sh
4
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
|
$PRINTF "${YELLOW}works only on Linux from 5.6${NORMAL}\n" $N
|
||||||
numCANT=$((numCANT+1))
|
numCANT=$((numCANT+1))
|
||||||
listCANT="$listCANT $N"
|
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
|
elif [ $rc1 -ne 0 ]; then
|
||||||
$PRINTF "$FAILED\n"
|
$PRINTF "$FAILED\n"
|
||||||
echo "$CMD0 &" >&2
|
echo "$CMD0 &" >&2
|
||||||
|
|
16
xio-socket.c
16
xio-socket.c
|
@ -14,6 +14,9 @@
|
||||||
#include "xio-socket.h"
|
#include "xio-socket.h"
|
||||||
#include "xio-named.h"
|
#include "xio-named.h"
|
||||||
#include "xio-unix.h"
|
#include "xio-unix.h"
|
||||||
|
#if WITH_VSOCK
|
||||||
|
#include "xio-vsock.h"
|
||||||
|
#endif
|
||||||
#if WITH_IP4
|
#if WITH_IP4
|
||||||
#include "xio-ip4.h"
|
#include "xio-ip4.h"
|
||||||
#endif /* WITH_IP4 */
|
#endif /* WITH_IP4 */
|
||||||
|
@ -2071,6 +2074,19 @@ int xiosetsockaddrenv(const char *lr,
|
||||||
} while (result > 0);
|
} while (result > 0);
|
||||||
break;
|
break;
|
||||||
#endif /* WITH_IP6 */
|
#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
|
#if LATER
|
||||||
case PF_PACKET:
|
case PF_PACKET:
|
||||||
result = xiosetsockaddrenv_packet(lr, (void *)sau, proto); break;
|
result = xiosetsockaddrenv_packet(lr, (void *)sau, proto); break;
|
||||||
|
|
30
xio-vsock.c
30
xio-vsock.c
|
@ -3,7 +3,7 @@
|
||||||
/* Author: Stefano Garzarella <sgarzare@redhat.com */
|
/* Author: Stefano Garzarella <sgarzare@redhat.com */
|
||||||
/* Published under the GNU General Public License V.2, see file COPYING */
|
/* Published under the GNU General Public License V.2, see file COPYING */
|
||||||
|
|
||||||
/* this file contains the source for opening addresses of VSOCK socket type */
|
/* This file contains the source for opening addresses of VSOCK socket type */
|
||||||
|
|
||||||
#include "xiosysincludes.h"
|
#include "xiosysincludes.h"
|
||||||
|
|
||||||
|
@ -164,4 +164,32 @@ static int xioopen_vsock_listen(int argc, const char *argv[], struct opt *opts,
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* WITH_LISTEN */
|
#endif /* WITH_LISTEN */
|
||||||
|
|
||||||
|
/* Returns information that can be used for constructing an environment
|
||||||
|
variable describing the socket address.
|
||||||
|
if idx is 0, this function writes "ADDR" into namebuff and the CID address
|
||||||
|
into valuebuff, and returns 1 (which means that one more info is there).
|
||||||
|
if idx is 1, it writes "PORT" into namebuff and the port number into
|
||||||
|
valuebuff, and returns 0 (no more info)
|
||||||
|
namelen and valuelen contain the max. allowed length of output chars in the
|
||||||
|
respective buffer.
|
||||||
|
on error this function returns -1.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
xiosetsockaddrenv_vsock(int idx, char *namebuff, size_t namelen,
|
||||||
|
char *valuebuff, size_t valuelen,
|
||||||
|
struct sockaddr_vm *sa, int ipproto) {
|
||||||
|
switch (idx) {
|
||||||
|
case 0:
|
||||||
|
strcpy(namebuff, "ADDR");
|
||||||
|
snprintf(valuebuff, valuelen, F_uint32_t, sa->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 */
|
#endif /* WITH_VSOCK */
|
||||||
|
|
|
@ -8,4 +8,8 @@
|
||||||
extern const struct addrdesc addr_vsock_connect;
|
extern const struct addrdesc addr_vsock_connect;
|
||||||
extern const struct addrdesc addr_vsock_listen;
|
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) */
|
#endif /* !defined(__xio_vsock_h_included) */
|
||||||
|
|
|
@ -308,9 +308,11 @@ const struct addrname addressnames[] = {
|
||||||
{ "unix-sendto", &xioaddr_unix_sendto },
|
{ "unix-sendto", &xioaddr_unix_sendto },
|
||||||
#endif
|
#endif
|
||||||
#if WITH_VSOCK
|
#if WITH_VSOCK
|
||||||
|
{ "vsock", &addr_vsock_connect },
|
||||||
{ "vsock-connect", &addr_vsock_connect },
|
{ "vsock-connect", &addr_vsock_connect },
|
||||||
#endif
|
#endif
|
||||||
#if WITH_VSOCK && WITH_LISTEN
|
#if WITH_VSOCK && WITH_LISTEN
|
||||||
|
{ "vsock-l", &addr_vsock_listen },
|
||||||
{ "vsock-listen", &addr_vsock_listen },
|
{ "vsock-listen", &addr_vsock_listen },
|
||||||
#endif
|
#endif
|
||||||
#else /* !0 */
|
#else /* !0 */
|
||||||
|
|
Loading…
Reference in a new issue