From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 717CD5A027D for ; Wed, 16 Nov 2022 05:42:24 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4NBr4R2wK1z4xwt; Wed, 16 Nov 2022 15:42:15 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1668573735; bh=ba3SCWBe1oCkmqEOXn8rb+yHYv0lr+6Jj6gdQ1SAH98=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aX8r8s/4sFBlBp+GqtphtdxgNoyJMATI6m1/Z7cTfgGjHG0thmDfVPKQALQkVCYFX V+9ZTE7gbEwRY+jy2AhdfcP8CViWZNvk1b03nJRzKIc0OusHzwiIfSkgPt9OcVR014 NrYaGkss94Ydrfz+SpqrA7pRn9CTbizhVOiDDYpk= From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 21/32] tcp: Take tcp_hash_insert() address from struct tcp_conn Date: Wed, 16 Nov 2022 15:42:01 +1100 Message-Id: <20221116044212.3876516-22-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221116044212.3876516-1-david@gibson.dropbear.id.au> References: <20221116044212.3876516-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: JPCDSDMK6AXVHKQC7H7W3FXF7BXA6W2O X-Message-ID-Hash: JPCDSDMK6AXVHKQC7H7W3FXF7BXA6W2O X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.3 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- tcp.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/tcp.c b/tcp.c index 56da864..ca7f295 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; -- 2.38.1