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 C9A045A0272 for ; Thu, 7 Dec 2023 06:53:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1701928435; bh=EGJsHa0S++d1Z7Wfr9cQSg8XmNKrB+DD7jgY+jkyGdA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KkSbIyIwfLdxgTwt7oP47EGJ11oSKeh6tvbwPRUwYqKRyoQFElxuqlo1uLkL2GASh xW6w/59ZVF7NxfeykYAyBdqWdegdLxLwTnxmsRQQwEMidOny0tR5ZkCljscFp58UQo hAD7CC/D3gDBhXsZUydm50gzgr7/PWuF/V5V1/I9jImDupj/7VasBQsyiE5aTsRV5q rnijG/b4i1zWbs0FxW/E9dS+/6ZkmdmD5qyW7axVeFQbN5AVjguAs0LkU9cRB9vZmK LGWEQmlK7u2xz50WgNlY5LVTZemF+7b3TzYRfrMTYuUT7Jnnk4UOQAIPtZaJtAafBq MJRv70+bwrASQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Sm3Nz5qnzz4x1p; Thu, 7 Dec 2023 16:53:55 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH v2 1/4] tcp: Fix conceptually incorrect byte-order switch in tcp_tap_handler() Date: Thu, 7 Dec 2023 16:53:50 +1100 Message-ID: <20231207055353.1245933-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207055353.1245933-1-david@gibson.dropbear.id.au> References: <20231207055353.1245933-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: JZK7UXTOBA2RK6I2VDC57YGC2Y33U4CG X-Message-ID-Hash: JZK7UXTOBA2RK6I2VDC57YGC2Y33U4CG 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.8 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_lookup() expects the port numbers in host order, but the TCP header, of course, has them in network order, so we need to switch them. However we call htons() (host to network) instead of ntohs() (network to host). This works because those do the same thing in practice (they only wouldn't on very strange theoretical platforms which are neither big nor little endian). But, having this the "wrong" way around is misleading, so switch it around. Signed-off-by: David Gibson --- tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcp.c b/tcp.c index f506cfd..bf58938 100644 --- a/tcp.c +++ b/tcp.c @@ -2532,7 +2532,7 @@ int tcp_tap_handler(struct ctx *c, uint8_t pif, int af, optlen = MIN(optlen, ((1UL << 4) /* from doff width */ - 6) * 4UL); opts = packet_get(p, idx, sizeof(*th), optlen, NULL); - conn = tcp_hash_lookup(c, af, daddr, htons(th->source), htons(th->dest)); + conn = tcp_hash_lookup(c, af, daddr, ntohs(th->source), ntohs(th->dest)); /* New connection from tap */ if (!conn) { -- 2.43.0