git: 6db2770210b6 - stable/14 - vtnet: honor the advertised MTU limit on attach

From: Roman Bogorodskiy <novel_at_FreeBSD.org>
Date: Fri, 13 Nov 2026 19:15:46 UTC
The branch stable/14 has been updated by novel:

URL: https://cgit.FreeBSD.org/src/commit/?id=6db2770210b6595ae75346eee67042dd5ffc8e81

commit 6db2770210b6595ae75346eee67042dd5ffc8e81
Author:     Roman Bogorodskiy <novel@FreeBSD.org>
AuthorDate: 2026-10-29 18:24:15 +0000
Commit:     Roman Bogorodskiy <novel@FreeBSD.org>
CommitDate: 2026-11-13 19:14:28 +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
    
    (cherry picked from commit 0974ef03b43f279f16289ad4d5be3a03923983ea)
---
 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 28a161ecd924..440879f65893 100644
--- a/sys/dev/virtio/network/if_vtnet.c
+++ b/sys/dev/virtio/network/if_vtnet.c
@@ -1194,6 +1194,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));