aboutgitcodebugslistschat
path: root/tcp.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2021-10-21 17:36:36 +0200
committerStefano Brivio <sbrivio@redhat.com>2021-10-21 17:54:03 +0200
commita2b86c5f9002ef3f7165f84a51c8dab4f574af29 (patch)
tree583242a8fc67698e96934f0ffb5e8c1e3e67b767 /tcp.c
parent000ae818d4e97b14fbf7fd83433db6df1de48e31 (diff)
downloadpasst-a2b86c5f9002ef3f7165f84a51c8dab4f574af29.tar
passt-a2b86c5f9002ef3f7165f84a51c8dab4f574af29.tar.gz
passt-a2b86c5f9002ef3f7165f84a51c8dab4f574af29.tar.bz2
passt-a2b86c5f9002ef3f7165f84a51c8dab4f574af29.tar.lz
passt-a2b86c5f9002ef3f7165f84a51c8dab4f574af29.tar.xz
passt-a2b86c5f9002ef3f7165f84a51c8dab4f574af29.tar.zst
passt-a2b86c5f9002ef3f7165f84a51c8dab4f574af29.zip
tcp: Restore source address to network endianness before using it for hash table
This was actually fine "on the wire", but it's inconsistent with the way we hash other addresses/protocols and also ends up with a wrong endianness in captures in case we replace the address with our default gateway. Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'tcp.c')
-rw-r--r--tcp.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/tcp.c b/tcp.c
index 9c2881c..df8a57f 100644
--- a/tcp.c
+++ b/tcp.c
@@ -2970,9 +2970,10 @@ 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 (s_addr >> IN_CLASSA_NSHIFT == IN_LOOPBACKNET ||
- s_addr == INADDR_ANY || s_addr == htonl(c->addr4_seen))
- sa4.sin_addr.s_addr = c->gw4;
+ s_addr == INADDR_ANY || htonl(s_addr) == c->addr4_seen)
+ s_addr = ntohl(c->gw4);
+ s_addr = htonl(s_addr);
memcpy(&conn->a.a4.a, &s_addr, sizeof(conn->a.a4.a));
conn->sock_port = ntohs(sa4.sin_port);