From: Laurent Vivier <lvivier@redhat.com>
To: passt-dev@passt.top
Cc: Laurent Vivier <lvivier@redhat.com>
Subject: [PATCH] tcp: Move tap header update out of tcp_fill_headers()
Date: Tue, 10 Feb 2026 17:08:21 +0100 [thread overview]
Message-ID: <20260210160821.8248-1-lvivier@redhat.com> (raw)
tcp_fill_headers() currently calls tap_hdr_update() to set the frame
length in the tap-specific header. This is backend-specific: the tap
backend needs this for its frame length header, but the vhost-user
backend passes NULL for the tap header and doesn't use it at all.
Remove the tap_hdr parameter from tcp_fill_headers() and instead return
the computed L2 frame length. The tap backend caller,
tcp_l2_buf_fill_headers(), now calls tap_hdr_update() itself with the
returned length. The vhost-user callers, tcp_vu_send_flag() and
tcp_vu_prepare(), no longer need to pass a NULL tap header.
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
tap.h | 3 +--
tcp.c | 16 +++++++++-------
tcp_buf.c | 6 ++++--
tcp_internal.h | 11 ++++++-----
tcp_vu.c | 4 ++--
5 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/tap.h b/tap.h
index ee22a9d78c44..cc780d168941 100644
--- a/tap.h
+++ b/tap.h
@@ -65,8 +65,7 @@ static inline struct iovec tap_hdr_iov(const struct ctx *c,
*/
static inline void tap_hdr_update(struct tap_hdr *thdr, size_t l2len)
{
- if (thdr)
- thdr->vnet_len = htonl(l2len);
+ thdr->vnet_len = htonl(l2len);
}
unsigned long tap_l2_max_len(const struct ctx *c);
diff --git a/tcp.c b/tcp.c
index 0a64892afbaf..048da2ab59bc 100644
--- a/tcp.c
+++ b/tcp.c
@@ -924,7 +924,6 @@ static void tcp_fill_header(struct tcphdr *th,
* tcp_fill_headers() - Fill 802.3, IP, TCP headers
* @c: Execution context
* @conn: Connection pointer
- * @taph: tap backend specific header
* @eh: Pointer to Ethernet header
* @ip4h: Pointer to IPv4 header, or NULL
* @ip6h: Pointer to IPv6 header, or NULL
@@ -933,12 +932,15 @@ static void tcp_fill_header(struct tcphdr *th,
* @ip4_check: IPv4 checksum, if already known
* @seq: Sequence number for this segment
* @no_tcp_csum: Do not set TCP checksum
+ *
+ * Return: frame length (including L2 headers)
*/
-void tcp_fill_headers(const struct ctx *c, struct tcp_tap_conn *conn,
- struct tap_hdr *taph, struct ethhdr *eh,
- struct iphdr *ip4h, struct ipv6hdr *ip6h,
- struct tcphdr *th, struct iov_tail *payload,
- const uint16_t *ip4_check, uint32_t seq, bool no_tcp_csum)
+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,
+ bool no_tcp_csum)
{
const struct flowside *tapside = TAPFLOW(conn);
size_t l4len = iov_tail_size(payload) + sizeof(*th);
@@ -1004,7 +1006,7 @@ void tcp_fill_headers(const struct ctx *c, struct tcp_tap_conn *conn,
else
tcp_update_csum(psum, th, payload);
- tap_hdr_update(taph, MAX(l3len + sizeof(struct ethhdr), ETH_ZLEN));
+ return MAX(l3len + sizeof(struct ethhdr), ETH_ZLEN);
}
/**
diff --git a/tcp_buf.c b/tcp_buf.c
index d29254103364..675ec138c460 100644
--- a/tcp_buf.c
+++ b/tcp_buf.c
@@ -183,14 +183,16 @@ static void tcp_l2_buf_fill_headers(const struct ctx *c,
struct ethhdr *eh = iov[TCP_IOV_ETH].iov_base;
struct ipv6hdr *ip6h = NULL;
struct iphdr *ip4h = NULL;
+ size_t l2len;
if (a4)
ip4h = iov[TCP_IOV_IP].iov_base;
else
ip6h = iov[TCP_IOV_IP].iov_base;
- tcp_fill_headers(c, conn, taph, eh, ip4h, ip6h, th, &tail,
- check, seq, no_tcp_csum);
+ l2len = tcp_fill_headers(c, conn, eh, ip4h, ip6h, th, &tail, check, seq,
+ no_tcp_csum);
+ tap_hdr_update(taph, l2len);
}
/**
diff --git a/tcp_internal.h b/tcp_internal.h
index 5f8fb3584355..518913b5bc03 100644
--- a/tcp_internal.h
+++ b/tcp_internal.h
@@ -176,11 +176,12 @@ void tcp_rst_do(const struct ctx *c, struct tcp_tap_conn *conn);
struct tcp_info_linux;
-void tcp_fill_headers(const struct ctx *c, struct tcp_tap_conn *conn,
- struct tap_hdr *taph, struct ethhdr *eh,
- struct iphdr *ip4h, struct ipv6hdr *ip6h,
- struct tcphdr *th, struct iov_tail *payload,
- const uint16_t *ip4_check, uint32_t seq, bool no_tcp_csum);
+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,
+ bool no_tcp_csum);
int tcp_update_seqack_wnd(const struct ctx *c, struct tcp_tap_conn *conn,
bool force_seq, struct tcp_info_linux *tinfo);
diff --git a/tcp_vu.c b/tcp_vu.c
index b9e9b55ed3d3..f654f3193bd7 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)
flags_elem[0].in_sg[0].iov_len = hdrlen + optlen;
payload = IOV_TAIL(flags_elem[0].in_sg, 1, hdrlen);
- tcp_fill_headers(c, conn, NULL, eh, ip4h, ip6h, th, &payload,
+ tcp_fill_headers(c, conn, eh, ip4h, ip6h, th, &payload,
NULL, seq, !*c->pcap);
vu_pad(&flags_elem[0].in_sg[0], hdrlen + optlen);
@@ -335,7 +335,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, NULL, eh, ip4h, ip6h, th, &payload,
+ tcp_fill_headers(c, conn, eh, ip4h, ip6h, th, &payload,
*check, conn->seq_to_tap, no_tcp_csum);
if (ip4h)
*check = &ip4h->check;
--
2.52.0
reply other threads:[~2026-02-10 16:08 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260210160821.8248-1-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).