aboutgitcodebugslistschat
path: root/tcp.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2023-09-28 11:20:53 +1000
committerStefano Brivio <sbrivio@redhat.com>2023-09-30 12:40:30 +0200
commitca6e94702cfbe29b279cf18f39a0fe492fae6f83 (patch)
tree2422a255629f810d9cdbe1617860d444feceaea6 /tcp.c
parentc1d2a070f282a95316e8f045e8959856518ab2f0 (diff)
downloadpasst-ca6e94702cfbe29b279cf18f39a0fe492fae6f83.tar
passt-ca6e94702cfbe29b279cf18f39a0fe492fae6f83.tar.gz
passt-ca6e94702cfbe29b279cf18f39a0fe492fae6f83.tar.bz2
passt-ca6e94702cfbe29b279cf18f39a0fe492fae6f83.tar.lz
passt-ca6e94702cfbe29b279cf18f39a0fe492fae6f83.tar.xz
passt-ca6e94702cfbe29b279cf18f39a0fe492fae6f83.tar.zst
passt-ca6e94702cfbe29b279cf18f39a0fe492fae6f83.zip
siphash: Make siphash functions consistently return 64-bit results
Some of the siphas_*b() functions return 64-bit results, others 32-bit results, with no obvious pattern. siphash_32b() also appears to do this incorrectly - taking the 64-bit hash value and simply returning it truncated, rather than folding the two halves together. Since SipHash proper is defined to give a 64-bit hash, make all of them return 64-bit results. In the one caller which needs a 32-bit value, tcp_seq_init() do the fold down to 32-bits ourselves. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'tcp.c')
-rw-r--r--tcp.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/tcp.c b/tcp.c
index 2933123..19baba5 100644
--- a/tcp.c
+++ b/tcp.c
@@ -1826,7 +1826,8 @@ static void tcp_seq_init(const struct ctx *c, struct tcp_tap_conn *conn,
.srcport = conn->fport,
.dstport = conn->eport,
};
- uint32_t ns, seq = 0;
+ uint64_t hash;
+ uint32_t ns;
if (CONN_V4(conn))
inany_from_af(&aany, AF_INET, &c->ip4.addr);
@@ -1834,12 +1835,12 @@ static void tcp_seq_init(const struct ctx *c, struct tcp_tap_conn *conn,
inany_from_af(&aany, AF_INET6, &c->ip6.addr);
in.dst = aany;
- seq = siphash_36b((uint8_t *)&in, c->tcp.hash_secret);
+ hash = siphash_36b((uint8_t *)&in, c->tcp.hash_secret);
/* 32ns ticks, overflows 32 bits every 137s */
ns = (now->tv_sec * 1000000000 + now->tv_nsec) >> 5;
- conn->seq_to_tap = seq + ns;
+ conn->seq_to_tap = ((uint32_t)(hash >> 32) ^ (uint32_t)hash) + ns;
}
/**