1
0
mirror of https://passt.top/passt synced 2024-11-05 20:31:11 +00:00

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>
This commit is contained in:
Stefano Brivio 2021-08-28 03:19:25 +02:00
parent f29c48db6b
commit 647a413794
2 changed files with 11 additions and 6 deletions

5
tcp.c
View File

@ -1387,6 +1387,11 @@ static void tcp_conn_from_tap(struct ctx *c, int af, void *addr,
if (s < 0) if (s < 0)
return; 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)) { if (af == AF_INET6 && IN6_IS_ADDR_LINKLOCAL(&addr6.sin6_addr)) {
struct sockaddr_in6 addr6_ll = { struct sockaddr_in6 addr6_ll = {
.sin6_family = AF_INET6, .sin6_family = AF_INET6,

12
udp.c
View File

@ -923,9 +923,9 @@ int udp_tap_handler(struct ctx *c, int af, void *addr,
udp_tap_map[V4][src].ts = now->tv_sec; udp_tap_map[V4][src].ts = now->tv_sec;
if (s_in.sin_addr.s_addr == c->gw4 && if (s_in.sin_addr.s_addr == c->gw4) {
udp_tap_map[V4][dst].ts_local) { if (!udp_tap_map[V4][dst].ts_local ||
if (udp_tap_map[V4][dst].loopback) udp_tap_map[V4][dst].loopback)
s_in.sin_addr.s_addr = htonl(INADDR_LOOPBACK); s_in.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
else else
s_in.sin_addr.s_addr = c->addr4_seen; 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; sa = (struct sockaddr *)&s_in6;
sl = sizeof(s_in6); sl = sizeof(s_in6);
if (!memcmp(addr, &c->gw6, sizeof(c->gw6)) && if (!memcmp(addr, &c->gw6, sizeof(c->gw6))) {
udp_tap_map[V6][dst].ts_local) { if (!udp_tap_map[V6][dst].ts_local ||
if (udp_tap_map[V6][dst].loopback) udp_tap_map[V6][dst].loopback)
s_in6.sin6_addr = in6addr_loopback; s_in6.sin6_addr = in6addr_loopback;
else else
s_in6.sin6_addr = c->addr6_seen; s_in6.sin6_addr = c->addr6_seen;