git: 0974ef03b43f - main - vtnet: honor the advertised MTU limit on attach

From: Roman Bogorodskiy <novel_at_FreeBSD.org>
Date: Fri, 30 Oct 2026 09:56:10 UTC
The branch main has been updated by novel:

URL: https://cgit.FreeBSD.org/src/commit/?id=0974ef03b43f279f16289ad4d5be3a03923983ea

commit 0974ef03b43f279f16289ad4d5be3a03923983ea
Author:     Roman Bogorodskiy <novel@FreeBSD.org>
AuthorDate: 2026-10-29 18:24:15 +0000
Commit:     Roman Bogorodskiy <novel@FreeBSD.org>
CommitDate: 2026-10-30 09:48:14 +0000

    vtnet: honor the advertised MTU limit on attach
    
    When VIRTIO_NET_F_MTU is negotiated, virtio_net_config.mtu specifies
    the maximum MTU the driver may use. vtnet_ioctl_mtu() enforces this
    limit for subsequent MTU changes, but ether_ifattach() unconditionally
    initializes the interface MTU to ETHERMTU (1500).
    
    So a device advertising a maximum below 1500 starts with an MTU above
    its limit. So make sure to set the initial MTU no larger than
    vtnet_max_mtu. That is, for vtnet_max_mtu less than 1500
    interface MTU will be set to this value, otherwise the current behaviour
    is preserved, MTU will be set to 1500.
    
    Reviewed by:    kfv, tuexen
    Sponsored by:   The FreeBSD Foundation
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D60980
---
 sys/dev/virtio/network/if_vtnet.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sys/dev/virtio/network/if_vtnet.c b/sys/dev/virtio/network/if_vtnet.c
index f85b02fe18aa..58b762a598fb 100644
--- a/sys/dev/virtio/network/if_vtnet.c
+++ b/sys/dev/virtio/network/if_vtnet.c
@@ -1314,6 +1314,8 @@ vtnet_setup_interface(struct vtnet_softc *sc)
 	}
 
 	ether_ifattach(ifp, sc->vtnet_hwaddr);
+	if (if_getmtu(ifp) > sc->vtnet_max_mtu)
+		if_setmtu(ifp, sc->vtnet_max_mtu);
 
 	/* Tell the upper layer(s) we support long frames. */
 	if_setifheaderlen(ifp, sizeof(struct ether_vlan_header));