aboutgitcodebugslistschat
path: root/tcp.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2021-07-21 12:05:58 +0200
committerStefano Brivio <sbrivio@redhat.com>2021-07-21 12:05:58 +0200
commitb508079c4c6ef3b79b253736eaeb654486922324 (patch)
tree7eba8f13c1e05c059829313cfd8e15b6f24c4491 /tcp.c
parent1642a04f484bfd7ea92d63d0ad6bfb3046f0c206 (diff)
downloadpasst-b508079c4c6ef3b79b253736eaeb654486922324.tar
passt-b508079c4c6ef3b79b253736eaeb654486922324.tar.gz
passt-b508079c4c6ef3b79b253736eaeb654486922324.tar.bz2
passt-b508079c4c6ef3b79b253736eaeb654486922324.tar.lz
passt-b508079c4c6ef3b79b253736eaeb654486922324.tar.xz
passt-b508079c4c6ef3b79b253736eaeb654486922324.tar.zst
passt-b508079c4c6ef3b79b253736eaeb654486922324.zip
tcp: Replace source address also if it's the same as the guest address
...not just for loopback addresses, with the address of the default gateway. Otherwise, the guest might receive packets with source and destination set to the same address. Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'tcp.c')
-rw-r--r--tcp.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/tcp.c b/tcp.c
index 58af89f..efcf466 100644
--- a/tcp.c
+++ b/tcp.c
@@ -1814,7 +1814,8 @@ static void tcp_conn_from_sock(struct ctx *c, union epoll_ref ref,
if (ref.tcp.v6) {
struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)&sa;
- if (IN6_IS_ADDR_LOOPBACK(&sa6->sin6_addr))
+ if (IN6_IS_ADDR_LOOPBACK(&sa6->sin6_addr) ||
+ !memcmp(&sa6->sin6_addr, &c->addr6_seen, sizeof(c->addr6)))
memcpy(&sa6->sin6_addr, &c->gw6, sizeof(c->gw6));
memcpy(&conn->a.a6, &sa6->sin6_addr, sizeof(conn->a.a6));
@@ -1835,7 +1836,8 @@ static void tcp_conn_from_sock(struct ctx *c, union epoll_ref ref,
memset(&conn->a.a4.one, 0xff, sizeof(conn->a.a4.one));
if (ntohl(sa4->sin_addr.s_addr) == INADDR_LOOPBACK ||
- ntohl(sa4->sin_addr.s_addr) == INADDR_ANY)
+ ntohl(sa4->sin_addr.s_addr) == INADDR_ANY ||
+ sa4->sin_addr.s_addr == c->addr4_seen)
sa4->sin_addr.s_addr = c->gw4;
memcpy(&conn->a.a4.a, &sa4->sin_addr, sizeof(conn->a.a4.a));