diff options
author | Stefano Brivio <sbrivio@redhat.com> | 2021-08-28 03:19:25 +0200 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2021-09-01 17:00:27 +0200 |
commit | 647a41379402cf0fae495f1be5d15d0ca8ed1e16 (patch) | |
tree | 328021386ed7887ef160dd0ad36fe37ef339e970 | |
parent | f29c48db6b3d1e9e3efde1402ebd1e57dd7f802e (diff) | |
download | passt-647a41379402cf0fae495f1be5d15d0ca8ed1e16.tar passt-647a41379402cf0fae495f1be5d15d0ca8ed1e16.tar.gz passt-647a41379402cf0fae495f1be5d15d0ca8ed1e16.tar.bz2 passt-647a41379402cf0fae495f1be5d15d0ca8ed1e16.tar.lz passt-647a41379402cf0fae495f1be5d15d0ca8ed1e16.tar.xz passt-647a41379402cf0fae495f1be5d15d0ca8ed1e16.tar.zst passt-647a41379402cf0fae495f1be5d15d0ca8ed1e16.zip |
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 <sbrivio@redhat.com>
-rw-r--r-- | tcp.c | 5 | ||||
-rw-r--r-- | udp.c | 12 |
2 files changed, 11 insertions, 6 deletions
@@ -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, @@ -923,9 +923,9 @@ int udp_tap_handler(struct ctx *c, int af, void *addr, udp_tap_map[V4][src].ts = now->tv_sec; - if (s_in.sin_addr.s_addr == c->gw4 && - udp_tap_map[V4][dst].ts_local) { - if (udp_tap_map[V4][dst].loopback) + if (s_in.sin_addr.s_addr == c->gw4) { + if (!udp_tap_map[V4][dst].ts_local || + udp_tap_map[V4][dst].loopback) s_in.sin_addr.s_addr = htonl(INADDR_LOOPBACK); else s_in.sin_addr.s_addr = c->addr4_seen; @@ -941,9 +941,9 @@ int udp_tap_handler(struct ctx *c, int af, void *addr, sa = (struct sockaddr *)&s_in6; sl = sizeof(s_in6); - if (!memcmp(addr, &c->gw6, sizeof(c->gw6)) && - udp_tap_map[V6][dst].ts_local) { - if (udp_tap_map[V6][dst].loopback) + if (!memcmp(addr, &c->gw6, sizeof(c->gw6))) { + if (!udp_tap_map[V6][dst].ts_local || + udp_tap_map[V6][dst].loopback) s_in6.sin6_addr = in6addr_loopback; else s_in6.sin6_addr = c->addr6_seen; |