On Mon, 2 Nov 2026 at 07:48, <[email protected]> wrote: > > > Now that we can rely on do_not_pad being correct for all > > NetClientInfo structs, we can pad short packets in the > > qemu_send_packet() and qemu_sendv_packet() family of functions. > > > > If the callsite is already padding, then this will have no effect, > > but callsites like the socket and dgram backends will now correctly > > add padding. This fixes the bug where when two QEMU instances are > > connected via one of those backends a short ARP packet transmitted by > > one is not correctly padded by the other and gets dropped. > > > > Note that if we pad a packet, our return value on success will > > be the size of the padded packet, not the original. This is OK > > because this function (like the NetQueueDeliverFunc function type > > documented in include/net/queue.h and which we will eventually > > end up calling and returning the return value of) returns > > >0 - success > > 0 - queue packet for future redelivery > > <0 - failure (discard packet) > > and doesn't guarantee to return exactly the size of the packet > > sent. None of the callers try to use the return value as an > > exact size. > > > > Cc: [email protected] > > Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/2362 > > Signed-off-by: Peter Maydell <[email protected]> > > Message-ID: <[email protected]> > > --- > > include/net/eth.h | 22 ++++++++++++++++++++++ > > net/eth.c | 18 ++++++++++++++++++ > > net/net.c | 22 ++++++++++++++++++++++ > > 3 files changed, 62 insertions(+) > > > > diff --git a/include/net/eth.h b/include/net/eth.h > > index 46dc9ed5acd9..042b2fc42db4 100644 > > --- a/include/net/eth.h > > +++ b/include/net/eth.h > > @@ -437,4 +437,26 @@ eth_parse_ipv6_hdr(const struct iovec *pkt, int > > pkt_frags, > > bool eth_pad_short_frame(uint8_t *padded_pkt, size_t *padded_buflen, > > const void *pkt, size_t pkt_size); > > > > +/** > > + * eth_pad_short_frame_iov - pad a short frame, iovec version > > + * > > + * This is equivalent to eth_pad_short_frame(), except that it works > > + * on a packet stored in a struct iovec. > > + * > > + * If the Ethernet frame size is shorter than 60 bytes, it will be padded > > to > > + * 60 bytes at the address @padded_pkt (and the caller will need to handle > > + * it as a not-in-an-iovec packet). > > + * > > + * @padded_pkt: buffer address to hold the padded frame > > + * @padded_buflen: pointer holding length of @padded_pkt. If the frame is > > + * padded, the length will be updated to the padded one. > > + * @iov: iovec holding the original Ethernet frame > > + * @iovcnt: number of elements in @iov > > + * @pkt_size: size of the original Ethernet frame (i.e. iov_size(iov, > > iovcnt)) > > + * @return true if the frame is padded, otherwise false > > + */ > > +bool eth_pad_short_frame_iov(uint8_t *padded_pkt, size_t *padded_buflen, > > + const struct iovec *iov, int iovcnt, > > + size_t pkt_size); > > + > > #endif > > diff --git a/net/eth.c b/net/eth.c > > index 12ec316e240e..14006222d68d 100644 > > --- a/net/eth.c > > +++ b/net/eth.c > > @@ -536,3 +536,21 @@ bool eth_pad_short_frame(uint8_t *padded_pkt, size_t > > *padded_buflen, > > > > return true; > > } > > + > > +bool eth_pad_short_frame_iov(uint8_t *padded_pkt, size_t *padded_buflen, > > + const struct iovec *iov, int iovcnt, > > + size_t pkt_size) > > +{ > > + assert(padded_buflen && *padded_buflen >= ETH_ZLEN); > > + > > + if (pkt_size >= ETH_ZLEN) { > > + return false; > > + } > > + > > + /* pad to minimum Ethernet frame length */ > > + iov_to_buf(iov, iovcnt, 0, padded_pkt, pkt_size); > > + memset(&padded_pkt[pkt_size], 0, ETH_ZLEN - pkt_size); > > + *padded_buflen = ETH_ZLEN; > > + > > + return true; > > assert(pkt_size == iov_size(iov, iovcnt)) or just drop pkt_size > argument and comput it?
The single callsite already computed it, so it seemed better to just pass it in rather than re-run through the whole iov to find it again. I don't expect this function to be called from more callsites in future, so I don't think that the assert that the caller upheld its end of the API requirement is really necessary. thanks -- PMM
