From: Laurent Vivier <lvivier@redhat.com>
To: passt-dev@passt.top
Cc: Laurent Vivier <lvivier@redhat.com>
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 [thread overview]
Message-ID: <20260323165259.1253482-4-lvivier@redhat.com> (raw)
In-Reply-To: <20260323165259.1253482-1-lvivier@redhat.com>
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 <lvivier@redhat.com>
---
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
next prev parent reply other threads:[~2026-03-23 16:53 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-23 16:52 [PATCH 0/7] vhost-user,tcp: Handle multiple iovec entries per virtqueue element Laurent Vivier
2026-03-23 16:52 ` [PATCH 1/7] tcp: pass ipv4h checksum, not a pointer to the checksum Laurent Vivier
2026-03-24 3:53 ` David Gibson
2026-03-24 7:56 ` Laurent Vivier
2026-03-24 23:49 ` David Gibson
2026-03-23 16:52 ` [PATCH 2/7] tcp: use iov_tail to access headers in tcp_fill_headers() Laurent Vivier
2026-03-24 3:58 ` David Gibson
2026-03-23 16:52 ` Laurent Vivier [this message]
2026-03-25 4:46 ` [PATCH 3/7] tcp_vu: Use iov_tail helpers to build headers in tcp_vu_prepare() David Gibson
2026-03-23 16:52 ` [PATCH 4/7] tcp_vu: Support multibuffer frames in tcp_vu_sock_recv() Laurent Vivier
2026-03-25 5:06 ` David Gibson
2026-03-23 16:52 ` [PATCH 5/7] tcp: Use iov_tail to access headers in tcp_prepare_flags() Laurent Vivier
2026-03-23 16:52 ` [PATCH 6/7] iov: introduce iov_memcopy() Laurent Vivier
2026-03-23 16:52 ` [PATCH 7/7] tcp_vu: Use iov_tail helpers to build headers in tcp_vu_send_flag() Laurent Vivier
2026-03-25 5:07 ` [PATCH 0/7] vhost-user,tcp: Handle multiple iovec entries per virtqueue element David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260323165259.1253482-4-lvivier@redhat.com \
--to=lvivier@redhat.com \
--cc=passt-dev@passt.top \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).