aboutsummaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorBryan Venteicher <bryanv@FreeBSD.org>2021-01-19 04:55:25 +0000
committerBryan Venteicher <bryanv@FreeBSD.org>2021-01-19 04:55:25 +0000
commitc3187190c71f6850a8d8a058d78a671a45e2871c (patch)
tree875afafec79ff8e5df2cb2693d7be58292ddcbb8 /sys/dev
parentbd8809df20beff55d28d556d891170290d44b28f (diff)
downloadsrc-c3187190c71f6850a8d8a058d78a671a45e2871c.tar.gz
src-c3187190c71f6850a8d8a058d78a671a45e2871c.zip
if_vtnet: Disable F_MTU feature if MTU is invalid
Reviewed by: grehan (mentor) Differential Revision: https://reviews.freebsd.org/D27931
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/virtio/network/if_vtnet.c14
-rw-r--r--sys/dev/virtio/network/if_vtnetvar.h1
2 files changed, 15 insertions, 0 deletions
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