From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id E92C95A026F for ; Fri, 4 Nov 2022 09:43:44 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4N3Z0W2bfNz4xwv; Fri, 4 Nov 2022 19:43:39 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1667551419; bh=J4mEutSdz238RoBoCG7IEjIWHL2CDBtLnrkbMBk7nwM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ca/afK1OxoisC/2vKpk028jM+npn0dnTYnBtsOuHcw2i/4TcCPKF3sZu11KUl6Zsd AB6IiDVYoGQxMf6n75/M51NH8+bJJkn9yReHJwjq0S46I5zuxWLq2wLcIys85hF2wg HNAc5I/23pBe9gQC4t26yJB3rJn2nIcqt5neQCH0= From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 05/10] tcp: Take tcp_hash_insert() address from struct tcp_conn Date: Fri, 4 Nov 2022 19:43:28 +1100 Message-Id: <20221104084333.3761760-6-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221104084333.3761760-1-david@gibson.dropbear.id.au> References: <20221104084333.3761760-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 6ZAV3P345BZBNR7WHSJSHR4WVVP5ASGO X-Message-ID-Hash: 6ZAV3P345BZBNR7WHSJSHR4WVVP5ASGO 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. For IPv6 connections that address is alreadys stored in struct tcp_conn. For IPv4 connections, an equivalent IPv4-mapped IPv6 address is 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 | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tcp.c b/tcp.c index 4645004..dfa73a3 100644 --- a/tcp.c +++ b/tcp.c @@ -1343,15 +1343,12 @@ static unsigned int tcp_hash(const struct ctx *c, int af, const void *addr, * 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_conn *conn, - int af, const void *addr) +static void tcp_hash_insert(const struct ctx *c, struct tcp_conn *conn) { int b; - b = tcp_hash(c, af, addr, conn->tap_port, conn->sock_port); + b = tcp_hash(c, AF_INET6, &conn->a.a6, conn->tap_port, conn->sock_port); conn->next_index = tc_hash[b] ? tc_hash[b] - tc : -1; tc_hash[b] = conn; conn->hash_bucket = b; @@ -2233,7 +2230,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 */ @@ -2891,8 +2888,6 @@ static void tcp_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; @@ -2912,10 +2907,10 @@ static void tcp_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