The branch main has been updated by bryanv:

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

commit c3187190c71f6850a8d8a058d78a671a45e2871c
Author:     Bryan Venteicher <bry...@freebsd.org>
AuthorDate: 2021-01-19 04:55:25 +0000
Commit:     Bryan Venteicher <bry...@freebsd.org>
CommitDate: 2021-01-19 04:55:25 +0000

    if_vtnet: Disable F_MTU feature if MTU is invalid
    
    Reviewed by: grehan (mentor)
    Differential Revision: https://reviews.freebsd.org/D27931
---
 sys/dev/virtio/network/if_vtnet.c    | 14 ++++++++++++++
 sys/dev/virtio/network/if_vtnetvar.h |  1 +
 2 files changed, 15 insertions(+)

diff --git a/sys/dev/virtio/network/if_vtnet.c 
b/sys/dev/virtio/network/if_vtnet.c
index a9dc3fad96a5..e3a42413d5cd 100644
--- a/sys/dev/virtio/network/if_vtnet.c
+++ b/sys/dev/virtio/network/if_vtnet.c
@@ -657,6 +657,20 @@ vtnet_negotiate_features(struct vtnet_softc *sc)
 
        negotiated_features = virtio_negotiate_features(dev, features);
 
+       if (virtio_with_feature(dev, VIRTIO_NET_F_MTU)) {
+               uint16_t mtu;
+
+               mtu = virtio_read_dev_config_2(dev,
+                   offsetof(struct virtio_net_config, mtu));
+               if (mtu < VTNET_MIN_MTU /* || mtu > VTNET_MAX_MTU */) {
+                       device_printf(dev, "Invalid MTU value: %d. "
+                           "MTU feature disabled.\n", mtu);
+                       features &= ~VIRTIO_NET_F_MTU;
+                       negotiated_features =
+                           virtio_negotiate_features(dev, features);
+               }
+       }
+
        if (virtio_with_feature(dev, VIRTIO_NET_F_MQ)) {
                uint16_t npairs;
 
diff --git a/sys/dev/virtio/network/if_vtnetvar.h 
b/sys/dev/virtio/network/if_vtnetvar.h
index 96cd68abba82..7781e1c9b398 100644
--- a/sys/dev/virtio/network/if_vtnetvar.h
+++ b/sys/dev/virtio/network/if_vtnetvar.h
@@ -340,6 +340,7 @@ CTASSERT(sizeof(struct vtnet_mac_filter) <= PAGE_SIZE);
 #define VTNET_LRO_FEATURES (VIRTIO_NET_F_GUEST_TSO4 | \
     VIRTIO_NET_F_GUEST_TSO6 | VIRTIO_NET_F_GUEST_ECN)
 
+#define VTNET_MIN_MTU          68
 #define VTNET_MAX_MTU          65536
 #define VTNET_MAX_RX_SIZE      65550
 
_______________________________________________
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"

Reply via email to