From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by passt.top (Postfix, from userid 1000) id AAAEC5A095E; Sat, 06 Dec 2025 02:26:57 +0100 (CET) From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH v3 1/5] tap: Pad non-batched frames to 802.3 minimum (60 bytes) if needed Date: Sat, 6 Dec 2025 02:26:53 +0100 Message-ID: <20251206012657.553742-2-sbrivio@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251206012657.553742-1-sbrivio@redhat.com> References: <20251206012657.553742-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: F4ZNSJCDIKJ4TY7XTEAF5HDC2PFB4BAE X-Message-ID-Hash: F4ZNSJCDIKJ4TY7XTEAF5HDC2PFB4BAE X-MailFrom: sbrivio@passt.top 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: David Gibson , 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: IEEE 802.3 requires a minimum frame payload of 46 bytes, without a 802.1Q tag. Add padding for the simple tap_send_single() case using a zero-filled 60-byte buffer and copying data to it if needed. In theory, we could add a further element in the iovec array, say: uint8_t padding[ETH_ZLEN] = { 0 }; struct iovec iov[3]; ... if (l2len < ETH_ZLEN) { iov[iovcnt].iov_base = (void *)padding; iov[iovcnt].iov_len = ETH_ZLEN - l2len; iovcnt++; } and avoid a copy, but that would substantially complicate the vhost-user path, and it's questionable whether passing a reference to a further buffer actually causes lower overhead than the simple copy. Link: https://bugs.passt.top/show_bug.cgi?id=166 Signed-off-by: Stefano Brivio Reviewed-by: Laurent Vivier Reviewed-by: David Gibson --- tap.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tap.c b/tap.c index 44b0644..e3ea61c 100644 --- a/tap.c +++ b/tap.c @@ -130,9 +130,18 @@ unsigned long tap_l2_max_len(const struct ctx *c) */ void tap_send_single(const struct ctx *c, const void *data, size_t l2len) { - uint32_t vnet_len = htonl(l2len); + uint8_t padded[ETH_ZLEN] = { 0 }; struct iovec iov[2]; size_t iovcnt = 0; + uint32_t vnet_len; + + if (l2len < ETH_ZLEN) { + memcpy(padded, data, l2len); + data = padded; + l2len = ETH_ZLEN; + } + + vnet_len = htonl(l2len); switch (c->mode) { case MODE_PASST: -- 2.43.0