aboutgitcodebugslistschat
path: root/tcp.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2022-11-17 16:58:57 +1100
committerStefano Brivio <sbrivio@redhat.com>2022-11-25 01:35:36 +0100
commiteb050b5a192c82ef659d738f6dbdf63b694d8cf3 (patch)
tree5c22979dc84a748711a91c64097a823439bc9023 /tcp.c
parent685f97b8de9ebf2d959433b67aa2821364a6f7f6 (diff)
downloadpasst-eb050b5a192c82ef659d738f6dbdf63b694d8cf3.tar
passt-eb050b5a192c82ef659d738f6dbdf63b694d8cf3.tar.gz
passt-eb050b5a192c82ef659d738f6dbdf63b694d8cf3.tar.bz2
passt-eb050b5a192c82ef659d738f6dbdf63b694d8cf3.tar.lz
passt-eb050b5a192c82ef659d738f6dbdf63b694d8cf3.tar.xz
passt-eb050b5a192c82ef659d738f6dbdf63b694d8cf3.tar.zst
passt-eb050b5a192c82ef659d738f6dbdf63b694d8cf3.zip
tcp: Take tcp_hash_insert() address from struct tcp_conn
tcp_hash_insert() takes an address to control which hash bucket the connection will go into. However, an inany_addr representation of that address is already stored in struct tcp_conn. Now that we've made the hashing of IPv4 and IPv4-mapped IPv6 addresses equivalent, we can simplify tcp_hash_insert() to use the address in struct tcp_conn, rather than taking it as an extra parameter. 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.c17
1 files changed, 5 insertions, 12 deletions
diff --git a/tcp.c b/tcp.c
index 92dd422..0ce7944 100644
--- a/tcp.c
+++ b/tcp.c
@@ -1248,17 +1248,12 @@ static unsigned int tcp_conn_hash(const struct ctx *c,
* tcp_hash_insert() - Insert connection into hash table, chain link
* @c: Execution context
* @conn: Connection pointer
- * @af: Address family, AF_INET or AF_INET6
- * @addr: Remote address, pointer to in_addr or in6_addr
*/
-static void tcp_hash_insert(const struct ctx *c, struct tcp_tap_conn *conn,
- int af, const void *addr)
+static void tcp_hash_insert(const struct ctx *c, struct tcp_tap_conn *conn)
{
- union inany_addr aany;
int b;
- inany_from_af(&aany, af, addr);
- b = tcp_hash(c, &aany, conn->tap_port, conn->sock_port);
+ b = tcp_hash(c, &conn->addr, conn->tap_port, conn->sock_port);
conn->next_index = tc_hash[b] ? CONN_IDX(tc_hash[b]) : -1;
tc_hash[b] = conn;
@@ -2153,7 +2148,7 @@ static void tcp_conn_from_tap(struct ctx *c, int af, const void *addr,
conn->seq_to_tap = tcp_seq_init(c, af, addr, th->dest, th->source, now);
conn->seq_ack_from_tap = conn->seq_to_tap + 1;
- tcp_hash_insert(c, conn, af, addr);
+ tcp_hash_insert(c, conn);
if (!bind(s, sa, sl)) {
tcp_rst(c, conn); /* Nobody is listening then */
@@ -2802,8 +2797,6 @@ static void tcp_tap_conn_from_sock(struct ctx *c, union epoll_ref ref,
conn->sock_port,
conn->tap_port,
now);
-
- tcp_hash_insert(c, conn, AF_INET6, &sa6.sin6_addr);
} else {
struct sockaddr_in sa4;
@@ -2823,10 +2816,10 @@ static void tcp_tap_conn_from_sock(struct ctx *c, union epoll_ref ref,
conn->sock_port,
conn->tap_port,
now);
-
- tcp_hash_insert(c, conn, AF_INET, &sa4.sin_addr);
}
+ tcp_hash_insert(c, conn);
+
conn->seq_ack_from_tap = conn->seq_to_tap + 1;
conn->wnd_from_tap = WINDOW_DEFAULT;