Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F141187881
D23971.id70309.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D23971.id70309.diff
View Options
Index: head/usr.sbin/bhyve/net_backends.h
===================================================================
--- head/usr.sbin/bhyve/net_backends.h
+++ head/usr.sbin/bhyve/net_backends.h
@@ -59,6 +59,7 @@
*/
#define VIRTIO_NET_F_CSUM (1 << 0) /* host handles partial cksum */
#define VIRTIO_NET_F_GUEST_CSUM (1 << 1) /* guest handles partial cksum */
+#define VIRTIO_NET_F_MTU (1 << 3) /* initial MTU advice */
#define VIRTIO_NET_F_MAC (1 << 5) /* host supplies MAC */
#define VIRTIO_NET_F_GSO_DEPREC (1 << 6) /* deprecated: host handles GSO */
#define VIRTIO_NET_F_GUEST_TSO4 (1 << 7) /* guest can rcv TSOv4 */
@@ -76,6 +77,7 @@
#define VIRTIO_NET_F_CTRL_VLAN (1 << 19) /* control channel VLAN filtering */
#define VIRTIO_NET_F_GUEST_ANNOUNCE \
(1 << 21) /* guest can send gratuitous pkts */
+#define VIRTIO_NET_F_MQ (1 << 22) /* host supports multiple VQ pairs */
/*
* Fixed network header size
Index: head/usr.sbin/bhyve/net_utils.h
===================================================================
--- head/usr.sbin/bhyve/net_utils.h
+++ head/usr.sbin/bhyve/net_utils.h
@@ -35,5 +35,6 @@
void net_genmac(struct pci_devinst *pi, uint8_t *macaddr);
int net_parsemac(char *mac_str, uint8_t *mac_addr);
+int net_parsemtu(const char *mtu_str, unsigned long *mtu);
#endif /* _NET_UTILS_H_ */
Index: head/usr.sbin/bhyve/net_utils.c
===================================================================
--- head/usr.sbin/bhyve/net_utils.c
+++ head/usr.sbin/bhyve/net_utils.c
@@ -31,9 +31,12 @@
#include <sys/types.h>
#include <net/ethernet.h>
+#include <assert.h>
#include <errno.h>
+#include <limits.h>
#include <md5.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "bhyverun.h"
@@ -59,6 +62,37 @@
memcpy(mac_addr, ea->octet, ETHER_ADDR_LEN);
return (0);
+}
+
+int
+net_parsemtu(const char *mtu_str, unsigned long *mtu)
+{
+ char *end;
+ unsigned long val;
+
+ assert(mtu_str != NULL);
+
+ if (*mtu_str == '-')
+ goto err;
+
+ val = strtoul(mtu_str, &end, 0);
+
+ if (*end != '\0')
+ goto err;
+
+ if (val == ULONG_MAX)
+ return (ERANGE);
+
+ if (val == 0 && errno == EINVAL)
+ return (EINVAL);
+
+ *mtu = val;
+
+ return (0);
+
+err:
+ errno = EINVAL;
+ return (EINVAL);
}
void
Index: head/usr.sbin/bhyve/pci_virtio_net.c
===================================================================
--- head/usr.sbin/bhyve/pci_virtio_net.c
+++ head/usr.sbin/bhyve/pci_virtio_net.c
@@ -67,6 +67,9 @@
#define VTNET_MAX_PKT_LEN (65536 + 64)
+#define VTNET_MIN_MTU ETHERMIN
+#define VTNET_MAX_MTU 65535
+
#define VTNET_S_HOSTCAPS \
( VIRTIO_NET_F_MAC | VIRTIO_NET_F_STATUS | \
VIRTIO_F_NOTIFY_ON_EMPTY | VIRTIO_RING_F_INDIRECT_DESC)
@@ -77,6 +80,8 @@
struct virtio_net_config {
uint8_t mac[6];
uint16_t status;
+ uint16_t max_virtqueue_pairs;
+ uint16_t mtu;
} __packed;
/*
@@ -532,6 +537,8 @@
struct pci_vtnet_softc *sc;
char tname[MAXCOMLEN + 1];
int mac_provided;
+ int mtu_provided;
+ unsigned long mtu = ETHERMTU;
/*
* Allocate data structures for further virtio initializations.
@@ -557,6 +564,7 @@
* if specified.
*/
mac_provided = 0;
+ mtu_provided = 0;
if (opts != NULL) {
char *devname;
char *vtopts;
@@ -585,6 +593,17 @@
if (err)
break;
mac_provided = 1;
+ } else if (strcmp(key, "mtu") == 0) {
+ err = net_parsemtu(value, &mtu);
+ if (err)
+ break;
+
+ if (mtu < VTNET_MIN_MTU || mtu > VTNET_MAX_MTU) {
+ err = EINVAL;
+ errno = EINVAL;
+ break;
+ }
+ mtu_provided = 1;
}
}
@@ -608,6 +627,17 @@
if (!mac_provided) {
net_genmac(pi, sc->vsc_config.mac);
}
+
+ sc->vsc_config.mtu = mtu;
+ if (mtu_provided) {
+ sc->vsc_consts.vc_hv_caps |= VIRTIO_NET_F_MTU;
+ }
+
+ /*
+ * Since we do not actually support multiqueue,
+ * set the maximum virtqueue pairs to 1.
+ */
+ sc->vsc_config.max_virtqueue_pairs = 1;
/* initialize config space */
pci_set_cfgdata16(pi, PCIR_DEVICE, VIRTIO_DEV_NET);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jan 3, 2:37 AM (5 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27466722
Default Alt Text
D23971.id70309.diff (3 KB)
Attached To
Mode
D23971: [bhyve][virtio-net] Add MTU advice support
Attached
Detach File
Event Timeline
Log In to Comment