Add VIRTIO_NET_F_MTU flag support for the bhyve virtio-net device.
The flag can be enabled using the new 'mtu' option: bhyve -s X:Y:Z,virtio-net,[tapN|valeX:N],mtu=9000 Reported by: vmaffione, jhb Approved by: vmaffione (mentor) Differential Revision: https://reviews.freebsd.org/D23971
This commit is contained in:
parent
8eb1a0ce56
commit
1ff57e3a25
@ -59,6 +59,7 @@ void netbe_rx_enable(net_backend_t *be);
|
||||
*/
|
||||
#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 @@ void netbe_rx_enable(net_backend_t *be);
|
||||
#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
|
||||
|
@ -31,9 +31,12 @@ __FBSDID("$FreeBSD$");
|
||||
#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"
|
||||
@ -61,6 +64,37 @@ net_parsemac(char *mac_str, uint8_t *mac_addr)
|
||||
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
|
||||
net_genmac(struct pci_devinst *pi, uint8_t *macaddr)
|
||||
{
|
||||
|
@ -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_ */
|
||||
|
@ -67,6 +67,9 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#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 @@ __FBSDID("$FreeBSD$");
|
||||
struct virtio_net_config {
|
||||
uint8_t mac[6];
|
||||
uint16_t status;
|
||||
uint16_t max_virtqueue_pairs;
|
||||
uint16_t mtu;
|
||||
} __packed;
|
||||
|
||||
/*
|
||||
@ -532,6 +537,8 @@ pci_vtnet_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts)
|
||||
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 @@ pci_vtnet_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts)
|
||||
* if specified.
|
||||
*/
|
||||
mac_provided = 0;
|
||||
mtu_provided = 0;
|
||||
if (opts != NULL) {
|
||||
char *devname;
|
||||
char *vtopts;
|
||||
@ -585,6 +593,17 @@ pci_vtnet_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts)
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -609,6 +628,17 @@ pci_vtnet_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts)
|
||||
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);
|
||||
pci_set_cfgdata16(pi, PCIR_VENDOR, VIRTIO_VENDOR);
|
||||
|
Loading…
Reference in New Issue
Block a user