From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=cMzx9b98; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 49C985A061A for ; Wed, 01 Apr 2026 21:18:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775071121; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ms9pfdpMf0L/SOOYJ70yTPyF/6MGEeo1c1xOG7vSvIg=; b=cMzx9b98FeuZA+xLmqnbh3tjjbNUsl23VoArsjOV85xR0zpgrVHbbYusLiwvK2bPigf+RS GlMQ0jqGXMJ3sgVL4pZzMsh+ukhKqzLsmPUkDU4AA7T7xolt3//ymjlxp7KC6o2FRrLlnj sMpNoUJcCxiLNQEHGx+FQEFB/4JkuNo= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-57-z4rJ4Re-P5-SCOFJcGki3g-1; Wed, 01 Apr 2026 15:18:39 -0400 X-MC-Unique: z4rJ4Re-P5-SCOFJcGki3g-1 X-Mimecast-MFC-AGG-ID: z4rJ4Re-P5-SCOFJcGki3g_1775071119 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3523F19560B4 for ; Wed, 1 Apr 2026 19:18:39 +0000 (UTC) Received: from lenovo-t14s.redhat.corp (headnet01.pony-001.prod.iad2.dc.redhat.com [10.2.32.101]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6C19019560AB; Wed, 1 Apr 2026 19:18:38 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH 09/10] tcp: Pass explicit data length to tcp_fill_headers() Date: Wed, 1 Apr 2026 21:18:25 +0200 Message-ID: <20260401191826.1782394-10-lvivier@redhat.com> In-Reply-To: <20260401191826.1782394-1-lvivier@redhat.com> References: <20260401191826.1782394-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: oeGz2p_a_KM3Ae-RYmhgZ7861cczfPNyqrk47U-M6fg_1775071119 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: O4PTSJSGK7BJV7M5ZU2WUC7FXZBCQTEO X-Message-ID-Hash: O4PTSJSGK7BJV7M5ZU2WUC7FXZBCQTEO X-MailFrom: lvivier@redhat.com 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 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() computed the TCP payload length from iov_tail_size(), but with vhost-user multibuffer frames, the iov_tail will be larger than the actual data. Pass the data length explicitly so that IP total length, pseudo-header, and checksum computations use the correct value. Signed-off-by: Laurent Vivier --- tcp.c | 5 +++-- tcp_buf.c | 3 ++- tcp_internal.h | 2 +- tcp_vu.c | 9 +++++---- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/tcp.c b/tcp.c index 49c6fb57ce16..6b0e25f33bf1 100644 --- a/tcp.c +++ b/tcp.c @@ -945,6 +945,7 @@ static void tcp_fill_header(struct tcphdr *th, * @ip6h: Pointer to IPv6 header, or NULL * @th: Pointer to TCP header * @payload: TCP payload + * @dlen: TCP payload length * @ip4_check: IPv4 checksum, if already known * @seq: Sequence number for this segment * @no_tcp_csum: Do not set TCP checksum @@ -955,11 +956,11 @@ size_t tcp_fill_headers(const struct ctx *c, struct tcp_tap_conn *conn, struct ethhdr *eh, struct iphdr *ip4h, struct ipv6hdr *ip6h, struct tcphdr *th, struct iov_tail *payload, - const uint16_t *ip4_check, uint32_t seq, + size_t dlen, const uint16_t *ip4_check, uint32_t seq, bool no_tcp_csum) { const struct flowside *tapside = TAPFLOW(conn); - size_t l4len = iov_tail_size(payload) + sizeof(*th); + size_t l4len = dlen + sizeof(*th); uint8_t *omac = conn->f.tap_omac; size_t l3len = l4len; uint32_t psum = 0; diff --git a/tcp_buf.c b/tcp_buf.c index 41965b107567..27151854033c 100644 --- a/tcp_buf.c +++ b/tcp_buf.c @@ -190,7 +190,8 @@ static void tcp_l2_buf_fill_headers(const struct ctx *c, else ip6h = iov[TCP_IOV_IP].iov_base; - l2len = tcp_fill_headers(c, conn, eh, ip4h, ip6h, th, &tail, check, seq, + l2len = tcp_fill_headers(c, conn, eh, ip4h, ip6h, th, &tail, + iov_tail_size(&tail), check, seq, no_tcp_csum); tap_hdr_update(taph, l2len); } diff --git a/tcp_internal.h b/tcp_internal.h index d9408852571f..a0fa19f4ed11 100644 --- a/tcp_internal.h +++ b/tcp_internal.h @@ -187,7 +187,7 @@ size_t tcp_fill_headers(const struct ctx *c, struct tcp_tap_conn *conn, struct ethhdr *eh, struct iphdr *ip4h, struct ipv6hdr *ip6h, struct tcphdr *th, struct iov_tail *payload, - const uint16_t *ip4_check, uint32_t seq, + size_t dlen, const uint16_t *ip4_check, uint32_t seq, bool no_tcp_csum); int tcp_update_seqack_wnd(const struct ctx *c, struct tcp_tap_conn *conn, diff --git a/tcp_vu.c b/tcp_vu.c index 105bca41c6de..ae79a6d856b0 100644 --- a/tcp_vu.c +++ b/tcp_vu.c @@ -135,7 +135,7 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags) seq--; tcp_fill_headers(c, conn, eh, ip4h, ip6h, th, &payload, - NULL, seq, !*c->pcap); + optlen, NULL, seq, !*c->pcap); l2len = optlen + hdrlen - VNET_HLEN; vu_pad(&flags_elem[0].in_sg[0], l2len); @@ -280,12 +280,13 @@ static ssize_t tcp_vu_sock_recv(const struct ctx *c, struct vu_virtq *vq, * @conn: Connection pointer * @iov: Pointer to the array of IO vectors * @iov_cnt: Number of entries in @iov + * @dlen: Data length * @check: Checksum, if already known * @no_tcp_csum: Do not set TCP checksum * @push: Set PSH flag, last segment in a batch */ static void tcp_vu_prepare(const struct ctx *c, struct tcp_tap_conn *conn, - struct iovec *iov, size_t iov_cnt, + struct iovec *iov, size_t iov_cnt, size_t dlen, const uint16_t **check, bool no_tcp_csum, bool push) { const struct flowside *toside = TAPFLOW(conn); @@ -329,7 +330,7 @@ static void tcp_vu_prepare(const struct ctx *c, struct tcp_tap_conn *conn, th->ack = 1; th->psh = push; - tcp_fill_headers(c, conn, eh, ip4h, ip6h, th, &payload, + tcp_fill_headers(c, conn, eh, ip4h, ip6h, th, &payload, dlen, *check, conn->seq_to_tap, no_tcp_csum); if (ip4h) *check = &ip4h->check; @@ -457,7 +458,7 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn) check = NULL; previous_dlen = dlen; - tcp_vu_prepare(c, conn, iov, buf_cnt, &check, !*c->pcap, push); + tcp_vu_prepare(c, conn, iov, buf_cnt, dlen, &check, !*c->pcap, push); /* Pad first/single buffer only, it's at least ETH_ZLEN long */ l2len = dlen + hdrlen - VNET_HLEN; -- 2.53.0