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 6DC445A0281 for ; Thu, 17 Nov 2022 06:59:21 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4NCTkl45lVz4xyF; Thu, 17 Nov 2022 16:59:11 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1668664751; bh=wDhyxblYmzkmmELImx5fHBnVW37wcEMXxzrOe3zsAl0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GAWX25Ai05Fh9j+dYFHlaEXKAaDpWZWptsccnR2gEi7W2RHiJsZXZ/sNY8FQWqWMG OGn2i/RGxkrBDXEDn4TZ8kS8BZj6MahV7t7lIWK6yVExYMPIzAl4asmwozKraFTnkg NhZqU/lDybCa/Iw0vhMoTkqr+5BFz9y6pGALG5cw= From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 22/32] tcp: Simplify tcp_hash_match() to take an inany_addr Date: Thu, 17 Nov 2022 16:58:58 +1100 Message-Id: <20221117055908.2782981-23-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221117055908.2782981-1-david@gibson.dropbear.id.au> References: <20221117055908.2782981-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: NRBLWRE2RYF2JFYZV5AHJRNHPHVTWUY3 X-Message-ID-Hash: NRBLWRE2RYF2JFYZV5AHJRNHPHVTWUY3 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_match() can take either an IPv4 (struct in_addr) or IPv6 (struct in6_addr) address. It has two different paths for each of those cases. However, its only caller has already constructed an equivalent inany representation of the address, so we can have tcp_hash_match take that directly and use a simpler comparison with the inany_equals() helper. Signed-off-by: David Gibson --- tcp.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/tcp.c b/tcp.c index 0ce7944..8ebd90a 100644 --- a/tcp.c +++ b/tcp.c @@ -1177,25 +1177,17 @@ static int tcp_opt_get(const char *opts, size_t len, uint8_t type_find, /** * tcp_hash_match() - Check if a connection entry matches address and ports * @conn: Connection entry to match against - * @af: Address family, AF_INET or AF_INET6 - * @addr: Remote address, pointer to in_addr or in6_addr + * @addr: Remote address * @tap_port: tap-facing port * @sock_port: Socket-facing port * * Return: 1 on match, 0 otherwise */ static int tcp_hash_match(const struct tcp_tap_conn *conn, - int af, const void *addr, + const union inany_addr *addr, in_port_t tap_port, in_port_t sock_port) { - const struct in_addr *a4 = inany_v4(&conn->addr); - - if (af == AF_INET && a4 && !memcmp(a4, addr, sizeof(*a4)) && - conn->tap_port == tap_port && conn->sock_port == sock_port) - return 1; - - if (af == AF_INET6 && - IN6_ARE_ADDR_EQUAL(&conn->addr.a6, addr) && + if (inany_equals(&conn->addr, addr) && conn->tap_port == tap_port && conn->sock_port == sock_port) return 1; @@ -1340,7 +1332,7 @@ static struct tcp_tap_conn *tcp_hash_lookup(const struct ctx *c, inany_from_af(&aany, af, addr); b = tcp_hash(c, &aany, tap_port, sock_port); for (conn = tc_hash[b]; conn; conn = conn_at_idx(conn->next_index)) { - if (tcp_hash_match(conn, af, addr, tap_port, sock_port)) + if (tcp_hash_match(conn, &aany, tap_port, sock_port)) return conn; } -- 2.38.1