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=B2ptZDM0; 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 05DC95A0775 for ; Thu, 12 Feb 2026 12:39:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770896379; 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=1fP2OSKryLhxgb5eJ5mq0/j6iNTDIwkgn/4MHoHUB3o=; b=B2ptZDM08QBUy8+frVQE2h4loQ9PRPkAKoyZhigxiyF2J4MhKkSRt5H6ILP3P/TZAZyBks tMbLDOhFWHm7YCnpKBI3PiyZHWXDX3mgCAy0c4hc5w+sdc9W40yDA/hkif4msDMIF/gvbs sTNayDUVmgcDz3Ft8/TqloB4+ZnCEQ8= 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-372-D-C7Kd08PvGfudowG1aAmQ-1; Thu, 12 Feb 2026 06:39:37 -0500 X-MC-Unique: D-C7Kd08PvGfudowG1aAmQ-1 X-Mimecast-MFC-AGG-ID: D-C7Kd08PvGfudowG1aAmQ_1770896376 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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A0FD21955D8C for ; Thu, 12 Feb 2026 11:39:36 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.44.33.7]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A94A819560BB; Thu, 12 Feb 2026 11:39:35 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH 1/2] virtio: Introduce VNET_HLEN macro for virtio net header length Date: Thu, 12 Feb 2026 12:39:31 +0100 Message-ID: <20260212113932.1047788-2-lvivier@redhat.com> In-Reply-To: <20260212113932.1047788-1-lvivier@redhat.com> References: <20260212113932.1047788-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: CLyFm5NSruRSfUkSJUwmavKKxnAp2ZxdmSMhXsWn9tw_1770896376 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: OFV6245YSLQW32C237RBFY4XKP2NRDBY X-Message-ID-Hash: OFV6245YSLQW32C237RBFY4XKP2NRDBY 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 all open-coded sizeof(struct virtio_net_hdr_mrg_rxbuf) with a VNET_HLEN macro. Signed-off-by: Laurent Vivier --- tcp_vu.c | 21 +++++++-------------- udp_vu.c | 12 ++++-------- virtio.h | 2 ++ vu_common.c | 13 +++++-------- vu_common.h | 2 +- 5 files changed, 19 insertions(+), 31 deletions(-) diff --git a/tcp_vu.c b/tcp_vu.c index b9e9b55ed3d3..f7bda4943e43 100644 --- a/tcp_vu.c +++ b/tcp_vu.c @@ -49,8 +49,7 @@ static size_t tcp_vu_hdrlen(bool v6) { size_t hdrlen; - hdrlen = sizeof(struct virtio_net_hdr_mrg_rxbuf) + - sizeof(struct ethhdr) + sizeof(struct tcphdr); + hdrlen = VNET_HLEN + sizeof(struct ethhdr) + sizeof(struct tcphdr); if (v6) hdrlen += sizeof(struct ipv6hdr); @@ -140,10 +139,8 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags) vu_pad(&flags_elem[0].in_sg[0], hdrlen + optlen); - if (*c->pcap) { - pcap_iov(&flags_elem[0].in_sg[0], 1, - sizeof(struct virtio_net_hdr_mrg_rxbuf)); - } + if (*c->pcap) + pcap_iov(&flags_elem[0].in_sg[0], 1, VNET_HLEN); nb_ack = 1; if (flags & DUP_ACK) { @@ -159,10 +156,8 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags) flags_elem[0].in_sg[0].iov_len); nb_ack++; - if (*c->pcap) { - pcap_iov(&flags_elem[1].in_sg[0], 1, - sizeof(struct virtio_net_hdr_mrg_rxbuf)); - } + if (*c->pcap) + pcap_iov(&flags_elem[1].in_sg[0], 1, VNET_HLEN); } } @@ -464,10 +459,8 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn) /* Pad first/single buffer only, it's at least ETH_ZLEN long */ vu_pad(iov, dlen + hdrlen); - if (*c->pcap) { - pcap_iov(iov, buf_cnt, - sizeof(struct virtio_net_hdr_mrg_rxbuf)); - } + if (*c->pcap) + pcap_iov(iov, buf_cnt, VNET_HLEN); conn->seq_to_tap += dlen; } diff --git a/udp_vu.c b/udp_vu.c index 3774d538a2d0..4f1eac48d162 100644 --- a/udp_vu.c +++ b/udp_vu.c @@ -46,8 +46,7 @@ static size_t udp_vu_hdrlen(bool v6) { size_t hdrlen; - hdrlen = sizeof(struct virtio_net_hdr_mrg_rxbuf) + - sizeof(struct ethhdr) + sizeof(struct udphdr); + hdrlen = VNET_HLEN + sizeof(struct ethhdr) + sizeof(struct udphdr); if (v6) hdrlen += sizeof(struct ipv6hdr); @@ -93,9 +92,7 @@ static int udp_vu_sock_recv(const struct ctx *c, struct vu_virtq *vq, int s, vu_init_elem(elem, iov_vu, VIRTQUEUE_MAX_SIZE); iov_cnt = vu_collect(vdev, vq, elem, VIRTQUEUE_MAX_SIZE, - IP_MAX_MTU + ETH_HLEN + - sizeof(struct virtio_net_hdr_mrg_rxbuf), - NULL); + IP_MAX_MTU + ETH_HLEN + VNET_HLEN, NULL); if (iov_cnt == 0) return -1; @@ -127,7 +124,7 @@ static int udp_vu_sock_recv(const struct ctx *c, struct vu_virtq *vq, int s, iov_used = idx + !!off; /* pad frame to 60 bytes: first buffer is at least ETH_ZLEN long */ - l2len = *dlen + hdrlen - sizeof(struct virtio_net_hdr_mrg_rxbuf); + l2len = *dlen + hdrlen - VNET_HLEN; vu_pad(&iov_vu[0], l2len); vu_set_vnethdr(vdev, iov_vu[0].iov_base, iov_used); @@ -233,8 +230,7 @@ void udp_vu_sock_to_tap(const struct ctx *c, int s, int n, flow_sidx_t tosidx) udp_vu_prepare(c, toside, dlen); if (*c->pcap) { udp_vu_csum(toside, iov_used); - pcap_iov(iov_vu, iov_used, - sizeof(struct virtio_net_hdr_mrg_rxbuf)); + pcap_iov(iov_vu, iov_used, VNET_HLEN); } vu_flush(vdev, vq, elem, iov_used); } diff --git a/virtio.h b/virtio.h index 12caaa0b6def..d04bbe84e5c4 100644 --- a/virtio.h +++ b/virtio.h @@ -15,6 +15,8 @@ /* Maximum size of a virtqueue */ #define VIRTQUEUE_MAX_SIZE 1024 +#define VNET_HLEN (sizeof(struct virtio_net_hdr_mrg_rxbuf)) + /** * struct vu_ring - Virtqueue rings * @num: Size of the queue diff --git a/vu_common.c b/vu_common.c index c682498fb555..aa14598ea028 100644 --- a/vu_common.c +++ b/vu_common.c @@ -261,7 +261,7 @@ int vu_send_single(const struct ctx *c, const void *buf, size_t size) vu_init_elem(elem, in_sg, VIRTQUEUE_MAX_SIZE); - size += sizeof(struct virtio_net_hdr_mrg_rxbuf); + size += VNET_HLEN; elem_cnt = vu_collect(vdev, vq, elem, VIRTQUEUE_MAX_SIZE, size, &total); if (total < size) { debug("vu_send_single: no space to send the data " @@ -271,16 +271,13 @@ int vu_send_single(const struct ctx *c, const void *buf, size_t size) vu_set_vnethdr(vdev, in_sg[0].iov_base, elem_cnt); - total -= sizeof(struct virtio_net_hdr_mrg_rxbuf); + total -= VNET_HLEN; /* copy data from the buffer to the iovec */ - iov_from_buf(in_sg, elem_cnt, sizeof(struct virtio_net_hdr_mrg_rxbuf), - buf, total); + iov_from_buf(in_sg, elem_cnt, VNET_HLEN, buf, total); - if (*c->pcap) { - pcap_iov(in_sg, elem_cnt, - sizeof(struct virtio_net_hdr_mrg_rxbuf)); - } + if (*c->pcap) + pcap_iov(in_sg, elem_cnt, VNET_HLEN); vu_flush(vdev, vq, elem, elem_cnt); diff --git a/vu_common.h b/vu_common.h index b5112c1e059d..052aff710502 100644 --- a/vu_common.h +++ b/vu_common.h @@ -11,7 +11,7 @@ static inline void *vu_eth(void *base) { - return ((char *)base + sizeof(struct virtio_net_hdr_mrg_rxbuf)); + return ((char *)base + VNET_HLEN); } static inline void *vu_ip(void *base) -- 2.52.0