From 647a41379402cf0fae495f1be5d15d0ca8ed1e16 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Sat, 28 Aug 2021 03:19:25 +0200 Subject: tcp, udp: Restore usage of gateway for guest to connect to local host This went lost in a recent rework: if the guest wants to connect directly to the host, it can use the address of the default gateway. Signed-off-by: Stefano Brivio --- tcp.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tcp.c') diff --git a/tcp.c b/tcp.c index eb83cc4..8aa9740 100644 --- a/tcp.c +++ b/tcp.c @@ -1387,6 +1387,11 @@ static void tcp_conn_from_tap(struct ctx *c, int af, void *addr, if (s < 0) return; + if (af == AF_INET && addr4.sin_addr.s_addr == c->gw4) + addr4.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + else if (af == AF_INET6 && !memcmp(addr, &c->gw6, sizeof(c->gw6))) + addr6.sin6_addr = in6addr_loopback; + if (af == AF_INET6 && IN6_IS_ADDR_LINKLOCAL(&addr6.sin6_addr)) { struct sockaddr_in6 addr6_ll = { .sin6_family = AF_INET6, -- cgit v1.2.3