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 672565A0271 for ; Mon, 28 Aug 2023 07:42:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1693201322; bh=+px+hSWUPl1je8sD24dkXGPnp/p1ZnHNFVH6jLwcGWY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JonOvHsP/Oky5EAutnNYwp1YVPIccUUxn1BkFb9eX3ZV3e/Z7D3mJ7V9mgbz6P2Oe 4OViLEA+dAmPMnJ/TCvwF6YyS4MVmRYey+nwjp4FLiHsNnURuuHKsiAikUpgBjfOku OuU2r0+tFgnTjT7ZtcP5G27hSTw3r9gw52/RSYzU= Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4RYzvt68vTz4x2Y; Mon, 28 Aug 2023 15:42:02 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 08/10] tcp: Re-use flowside_hash for initial sequence number generation Date: Mon, 28 Aug 2023 15:41:44 +1000 Message-ID: <20230828054146.48673-9-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230828054146.48673-1-david@gibson.dropbear.id.au> References: <20230828054146.48673-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: ME5GY5OE2FGZCHZABTJTB4YKJ74F4LGD X-Message-ID-Hash: ME5GY5OE2FGZCHZABTJTB4YKJ74F4LGD 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: We generate TCP initial sequence numbers, when we need them, from a hash of the source and destination addresses and ports, plus a timestamp. The contents of that hash are now exactly the same as the flowside_hash() we use elsewhere. The values won't be identical because we order the fields in the hash differently, but that doesn't matter for our purposes. Signed-off-by: David Gibson --- tcp.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/tcp.c b/tcp.c index 27cdd15..a9ddce6 100644 --- a/tcp.c +++ b/tcp.c @@ -1754,20 +1754,7 @@ static void tcp_clamp_window(const struct ctx *c, struct tcp_tap_conn *conn, static void tcp_seq_init(const struct ctx *c, struct tcp_tap_conn *conn, const struct timespec *now) { - struct { - union inany_addr src; - in_port_t srcport; - union inany_addr dst; - in_port_t dstport; - } __attribute__((__packed__)) in = { - .src = TAPSIDE(conn)->faddr, - .srcport = TAPSIDE(conn)->fport, - .dst = TAPSIDE(conn)->eaddr, - .dstport = TAPSIDE(conn)->eport, - }; - uint32_t ns, seq = 0; - - seq = siphash_36b((uint8_t *)&in, c->tcp.hash_secret); + uint32_t ns, seq = flowside_hash(TAPSIDE(conn), c->tcp.hash_secret); /* 32ns ticks, overflows 32 bits every 137s */ ns = (now->tv_sec * 1000000000 + now->tv_nsec) >> 5; -- 2.41.0