git: c3187190c71f - main - if_vtnet: Disable F_MTU feature if MTU is invalid
Bryan Venteicher
bryanv at FreeBSD.org
Tue Jan 19 05:08:36 UTC 2021
The branch main has been updated by bryanv:
URL: https://cgit.FreeBSD.org/src/commit/?id=c3187190c71f6850a8d8a058d78a671a45e2871c
commit c3187190c71f6850a8d8a058d78a671a45e2871c
Author: Bryan Venteicher <bryanv at FreeBSD.org>
AuthorDate: 2021-01-19 04:55:25 +0000
Commit: Bryan Venteicher <bryanv at 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
More information about the dev-commits-src-main
mailing list