diff options
author | Nicholas Ngai <nicholas@ngai.me> | 2021-09-27 14:21:45 -0700 |
---|---|---|
committer | Nicholas Ngai <nicholas@ngai.me> | 2021-09-27 14:21:45 -0700 |
commit | 92346097c2148d1a7ff73223d20409db4ac6ba22 (patch) | |
tree | ed0b67e72894061d34f96f0aee6bfd2cd70f5d89 /src/socket.c | |
parent | 23db43abdb5740287bbb7cbf5cc99eb22e121298 (diff) | |
download | slirp-92346097c2148d1a7ff73223d20409db4ac6ba22.zip slirp-92346097c2148d1a7ff73223d20409db4ac6ba22.tar.gz slirp-92346097c2148d1a7ff73223d20409db4ac6ba22.tar.bz2 |
Support Unix sockets in hostfwd
QEMU has an issue open
(https://gitlab.com/qemu-project/qemu/-/issues/347) to forward a Unix
domain socket to guest TCP port. Both of these protocols support stream
modes of operation (and user-mode networking can only access the stream
anyway), so this patch enables Unix-to-TCP hostfwds.
Like with localhost hostfwds, the sotranslate_accept function will
translate a Unix domain socket connection to a TCP connection
originating from vhost_addr and a randomized ephemeral port.
Signed-off-by: Nicholas Ngai <nicholas@ngai.me>
Diffstat (limited to 'src/socket.c')
-rw-r--r-- | src/socket.c | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/src/socket.c b/src/socket.c index 2c1b789..09ce6bf 100644 --- a/src/socket.c +++ b/src/socket.c @@ -769,18 +769,6 @@ struct socket *tcpx_listen(Slirp *slirp, socklen_t addrlen; DEBUG_CALL("tcpx_listen"); - /* AF_INET6 addresses are bigger than AF_INET, so this is big enough. */ - char addrstr[INET6_ADDRSTRLEN]; - char portstr[6]; - int ret; - ret = getnameinfo(haddr, haddrlen, addrstr, sizeof(addrstr), portstr, sizeof(portstr), NI_NUMERICHOST|NI_NUMERICSERV); - g_assert(ret == 0); - DEBUG_ARG("haddr = %s", addrstr); - DEBUG_ARG("hport = %s", portstr); - ret = getnameinfo(laddr, laddrlen, addrstr, sizeof(addrstr), portstr, sizeof(portstr), NI_NUMERICHOST|NI_NUMERICSERV); - g_assert(ret == 0); - DEBUG_ARG("laddr = %s", addrstr); - DEBUG_ARG("lport = %s", portstr); DEBUG_ARG("flags = %x", flags); /* @@ -1041,6 +1029,13 @@ void sotranslate_accept(struct socket *so) } break; + case AF_UNIX: + /* Translate Unix socket to random ephemeral source port. */ + so->so_ffamily = AF_INET; + so->so_faddr = slirp->vhost_addr; + so->so_fport = g_rand_int_range(slirp->grand, 49152, 65536); + break; + default: break; } |