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 72AA75A027C for ; Mon, 29 Apr 2024 09:09:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1714374575; bh=Oe9QbF1TjXLxzd5V8JrMwYHnxrBNnuPXHIcyvBDxOj8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BZ3f4KNMAZGuJDqyMjRsY1UDi7Qx2KR/uolftxJo1Ci2R+J18iWV3D0EJDodsCZ47 hwAwq3McKWMBzSFsL+XV238Yz06mtd62xtajmvcZIAJQaXPGSf49DudEAeMpvaYkRB cPELQcFlkIXiYl96ITscyD3Pn7P+Wo+OWoUplz99631KSFg5RBpwaOojEXrS0lokto s4mSEBbEd/xPrra9fwbpAK5/Z8O/A22Ve50x+KE7spaush11idr28bpf2oHdgCOfhq FE91TC3mYanBJOK/c/3L6cwr5GiIByB3VhLyUj6M1/qXk64rN34xkBFn+HKG1jNE3P j2GDsVkCZnLjw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4VSZFq5NZPz4x3v; Mon, 29 Apr 2024 17:09:35 +1000 (AEST) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 4/7] tcp: Simplify packet length calculation when preparing headers Date: Mon, 29 Apr 2024 17:09:30 +1000 Message-ID: <20240429070933.1366881-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240429070933.1366881-1-david@gibson.dropbear.id.au> References: <20240429070933.1366881-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: WRE5C3E5IQBLQ47KVNSX2IS55O3RSAX7 X-Message-ID-Hash: WRE5C3E5IQBLQ47KVNSX2IS55O3RSAX7 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: Laurent Vivier , 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_fill_headers[46]() compute the L3 packet length from the L4 packet length, then their caller tcp_l2_buf_fill_headers() converts it back to the L4 packet length. We can just use the L4 length throughout. Signed-off-by: David Gibson eewwee --- tcp.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/tcp.c b/tcp.c index 23d408f2..08899367 100644 --- a/tcp.c +++ b/tcp.c @@ -1341,7 +1341,7 @@ static void tcp_fill_header(struct tcphdr *th, * @check: Checksum, if already known * @seq: Sequence number for this segment * - * Return: The total length of the IPv4 packet, host order + * Return: The IPv4 payload length, host order */ static size_t tcp_fill_headers4(const struct ctx *c, const struct tcp_tap_conn *conn, @@ -1367,7 +1367,7 @@ static size_t tcp_fill_headers4(const struct ctx *c, tcp_update_check_tcp4(iph, th); - return l3len; + return l4len; } /** @@ -1380,7 +1380,7 @@ static size_t tcp_fill_headers4(const struct ctx *c, * @check: Checksum, if already known * @seq: Sequence number for this segment * - * Return: The total length of the IPv6 packet, host order + * Return: The IPv6 payload length, host order */ static size_t tcp_fill_headers6(const struct ctx *c, const struct tcp_tap_conn *conn, @@ -1388,7 +1388,6 @@ static size_t tcp_fill_headers6(const struct ctx *c, size_t plen, uint32_t seq) { size_t l4len = plen + sizeof(*th); - size_t l3len = l4len + sizeof(*ip6h); ip6h->payload_len = htons(l4len); ip6h->saddr = conn->faddr.a6; @@ -1409,7 +1408,7 @@ static size_t tcp_fill_headers6(const struct ctx *c, tcp_update_check_tcp6(ip6h, th); - return l3len; + return l4len; } /** @@ -1429,21 +1428,16 @@ static size_t tcp_l2_buf_fill_headers(const struct ctx *c, const uint16_t *check, uint32_t seq) { const struct in_addr *a4 = inany_v4(&conn->faddr); - size_t l3len, l4len; if (a4) { - l3len = tcp_fill_headers4(c, conn, iov[TCP_IOV_IP].iov_base, - iov[TCP_IOV_PAYLOAD].iov_base, plen, - check, seq); - l4len = l3len - sizeof(struct iphdr); - } else { - l3len = tcp_fill_headers6(c, conn, iov[TCP_IOV_IP].iov_base, - iov[TCP_IOV_PAYLOAD].iov_base, plen, - seq); - l4len = l3len - sizeof(struct ipv6hdr); + return tcp_fill_headers4(c, conn, iov[TCP_IOV_IP].iov_base, + iov[TCP_IOV_PAYLOAD].iov_base, plen, + check, seq); } - return l4len; + return tcp_fill_headers6(c, conn, iov[TCP_IOV_IP].iov_base, + iov[TCP_IOV_PAYLOAD].iov_base, plen, + seq); } /** -- 2.44.0