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=SX6UsdjH; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id 698935A0653 for ; Mon, 23 Mar 2026 17:53:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774284789; 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=axmqhmdIFeE2tcy4DFEYxcEmZhlTVs3CwRRJCrI3GWE=; b=SX6UsdjHepKSjQ1f/UNKBBuNRGjeF0UtRmMhdS2GUbxhlqSTCbruadjQ5As/lQ6ttc3hKi EYrqSVVIDOFAR5XmiuRnIGKlsKWCDOYbhnsZB/x7+xcwzKD7sggpJlEKHQlSrUforJK0q2 ypVGWFQcnOQVB7jXM4wnC9sO6ZGLNrU= Received: from mx-prod-mc-05.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-440-kiwGh7fGOVaZIADhHrh5rw-1; Mon, 23 Mar 2026 12:53:07 -0400 X-MC-Unique: kiwGh7fGOVaZIADhHrh5rw-1 X-Mimecast-MFC-AGG-ID: kiwGh7fGOVaZIADhHrh5rw_1774284786 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 81ACB1954B20 for ; Mon, 23 Mar 2026 16:53:06 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.44.32.96]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8BCE4300019F; Mon, 23 Mar 2026 16:53:05 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH 3/7] tcp_vu: Use iov_tail helpers to build headers in tcp_vu_prepare() Date: Mon, 23 Mar 2026 17:52:55 +0100 Message-ID: <20260323165259.1253482-4-lvivier@redhat.com> In-Reply-To: <20260323165259.1253482-1-lvivier@redhat.com> References: <20260323165259.1253482-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: B7xSs0BM-KUQsQHj75c759aoVQTKE7N0Rwv2hvGEgZU_1774284786 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: 6DEBW5JN5FH7JSXMHWBRNIQKYHY453CG X-Message-ID-Hash: 6DEBW5JN5FH7JSXMHWBRNIQKYHY453CG 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: Replace direct pointer arithmetic using vu_eth(), vu_ip(), vu_payloadv4() and vu_payloadv6() with the iov_tail abstraction to build Ethernet, IP and TCP headers in tcp_vu_prepare(). This removes the assumption that all headers reside in a single contiguous iov entry. Signed-off-by: Laurent Vivier --- tcp_vu.c | 61 ++++++++++++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/tcp_vu.c b/tcp_vu.c index c6206b7a689c..a39f6ea018e9 100644 --- a/tcp_vu.c +++ b/tcp_vu.c @@ -222,6 +222,7 @@ static ssize_t tcp_vu_sock_recv(const struct ctx *c, struct vu_virtq *vq, /* reserve space for headers in iov */ iov = &elem[elem_cnt].in_sg[0]; assert(iov->iov_len >= hdrlen); + iov->iov_base = (char *)iov->iov_base + hdrlen; iov->iov_len -= hdrlen; head[(*head_cnt)++] = elem_cnt; @@ -285,51 +286,45 @@ static void tcp_vu_prepare(const struct ctx *c, struct tcp_tap_conn *conn, int *check, bool no_tcp_csum, bool push) { const struct flowside *toside = TAPFLOW(conn); - bool v6 = !(inany_v4(&toside->eaddr) && inany_v4(&toside->oaddr)); - size_t hdrlen = tcp_vu_hdrlen(v6); - char *base = iov[0].iov_base; - struct ipv6hdr *ip6h = NULL; - struct iphdr *ip4h = NULL; + bool ipv4 = inany_v4(&toside->eaddr) && inany_v4(&toside->oaddr); struct iov_tail payload; - struct tcphdr *th; - struct ethhdr *eh; - - /* we guess the first iovec provided by the guest can embed - * all the headers needed by L2 frame, including any padding - */ - assert(iov[0].iov_len >= hdrlen); - - eh = vu_eth(base); - memcpy(eh->h_dest, c->guest_mac, sizeof(eh->h_dest)); + payload = IOV_TAIL(iov, iov_cnt, VNET_HLEN); + with_header(struct ethhdr, eh, &payload) + memcpy(eh->h_dest, c->guest_mac, sizeof(eh->h_dest)); + IOV_DROP_HEADER(&payload, struct ethhdr); /* initialize header */ - if (!v6) { - eh->h_proto = htons(ETH_P_IP); - - ip4h = vu_ip(base); - *ip4h = (struct iphdr)L2_BUF_IP4_INIT(IPPROTO_TCP); - th = vu_payloadv4(base); + if (ipv4) { + with_header(struct iphdr, ip4h, &payload) + *ip4h = (struct iphdr)L2_BUF_IP4_INIT(IPPROTO_TCP); + IOV_DROP_HEADER(&payload, struct iphdr); } else { - eh->h_proto = htons(ETH_P_IPV6); - - ip6h = vu_ip(base); - *ip6h = (struct ipv6hdr)L2_BUF_IP6_INIT(IPPROTO_TCP); - - th = vu_payloadv6(base); + with_header(struct ipv6hdr, ip6h, &payload) + *ip6h = (struct ipv6hdr)L2_BUF_IP6_INIT(IPPROTO_TCP); + IOV_DROP_HEADER(&payload, struct ipv6hdr); } - memset(th, 0, sizeof(*th)); - th->doff = sizeof(*th) / 4; - th->ack = 1; - th->psh = push; + with_header(struct tcphdr, th, &payload) { + memset(th, 0, sizeof(*th)); + th->doff = sizeof(*th) / 4; + th->ack = 1; + th->psh = push; + } payload = IOV_TAIL(iov, iov_cnt, VNET_HLEN); - tcp_fill_headers(c, conn, !v6, &payload, *check, conn->seq_to_tap, + tcp_fill_headers(c, conn, ipv4, &payload, *check, conn->seq_to_tap, no_tcp_csum); - if (ip4h) + if (ipv4) { + struct iphdr ip4h_storage; + const struct iphdr *ip4h; + + IOV_DROP_HEADER(&payload, struct ethhdr); + ip4h = IOV_PEEK_HEADER(&payload, ip4h_storage); + *check = ip4h->check; + } } /** -- 2.53.0