Changeset View
Changeset View
Standalone View
Standalone View
head/usr.sbin/bhyve/pci_virtio_net.c
Show All 24 Lines | |||||
* | * | ||||
* $FreeBSD$ | * $FreeBSD$ | ||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#ifndef WITHOUT_CAPSICUM | |||||
#include <sys/capsicum.h> | |||||
#endif | |||||
#include <sys/linker_set.h> | #include <sys/linker_set.h> | ||||
#include <sys/select.h> | #include <sys/select.h> | ||||
#include <sys/uio.h> | #include <sys/uio.h> | ||||
#include <sys/ioctl.h> | #include <sys/ioctl.h> | ||||
#include <machine/atomic.h> | #include <machine/atomic.h> | ||||
#include <net/ethernet.h> | #include <net/ethernet.h> | ||||
#ifndef NETMAP_WITH_LIBS | #ifndef NETMAP_WITH_LIBS | ||||
#define NETMAP_WITH_LIBS | #define NETMAP_WITH_LIBS | ||||
#endif | #endif | ||||
#include <net/netmap_user.h> | #include <net/netmap_user.h> | ||||
#include <err.h> | |||||
#include <errno.h> | #include <errno.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <stdint.h> | #include <stdint.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <strings.h> | #include <strings.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <assert.h> | #include <assert.h> | ||||
#include <md5.h> | #include <md5.h> | ||||
#include <pthread.h> | #include <pthread.h> | ||||
#include <pthread_np.h> | #include <pthread_np.h> | ||||
#include <sysexits.h> | |||||
#include "bhyverun.h" | #include "bhyverun.h" | ||||
#include "pci_emul.h" | #include "pci_emul.h" | ||||
#include "mevent.h" | #include "mevent.h" | ||||
#include "virtio.h" | #include "virtio.h" | ||||
#define VTNET_RINGSZ 1024 | #define VTNET_RINGSZ 1024 | ||||
▲ Show 20 Lines • Show All 674 Lines • ▼ Show 20 Lines | pci_vtnet_parsemac(char *mac_str, uint8_t *mac_addr) | ||||
return (0); | return (0); | ||||
} | } | ||||
static void | static void | ||||
pci_vtnet_tap_setup(struct pci_vtnet_softc *sc, char *devname) | pci_vtnet_tap_setup(struct pci_vtnet_softc *sc, char *devname) | ||||
{ | { | ||||
char tbuf[80]; | char tbuf[80]; | ||||
#ifndef WITHOUT_CAPSICUM | |||||
cap_rights_t rights; | |||||
#endif | |||||
strcpy(tbuf, "/dev/"); | strcpy(tbuf, "/dev/"); | ||||
strlcat(tbuf, devname, sizeof(tbuf)); | strlcat(tbuf, devname, sizeof(tbuf)); | ||||
sc->pci_vtnet_rx = pci_vtnet_tap_rx; | sc->pci_vtnet_rx = pci_vtnet_tap_rx; | ||||
sc->pci_vtnet_tx = pci_vtnet_tap_tx; | sc->pci_vtnet_tx = pci_vtnet_tap_tx; | ||||
sc->vsc_tapfd = open(tbuf, O_RDWR); | sc->vsc_tapfd = open(tbuf, O_RDWR); | ||||
if (sc->vsc_tapfd == -1) { | if (sc->vsc_tapfd == -1) { | ||||
WPRINTF(("open of tap device %s failed\n", tbuf)); | WPRINTF(("open of tap device %s failed\n", tbuf)); | ||||
return; | return; | ||||
} | } | ||||
/* | /* | ||||
* Set non-blocking and register for read | * Set non-blocking and register for read | ||||
* notifications with the event loop | * notifications with the event loop | ||||
*/ | */ | ||||
int opt = 1; | int opt = 1; | ||||
if (ioctl(sc->vsc_tapfd, FIONBIO, &opt) < 0) { | if (ioctl(sc->vsc_tapfd, FIONBIO, &opt) < 0) { | ||||
WPRINTF(("tap device O_NONBLOCK failed\n")); | WPRINTF(("tap device O_NONBLOCK failed\n")); | ||||
close(sc->vsc_tapfd); | close(sc->vsc_tapfd); | ||||
sc->vsc_tapfd = -1; | sc->vsc_tapfd = -1; | ||||
} | } | ||||
#ifndef WITHOUT_CAPSICUM | |||||
cap_rights_init(&rights, CAP_EVENT, CAP_READ, CAP_WRITE); | |||||
if (cap_rights_limit(sc->vsc_tapfd, &rights) == -1 && errno != ENOSYS) | |||||
errx(EX_OSERR, "Unable to apply rights for sandbox"); | |||||
#endif | |||||
sc->vsc_mevp = mevent_add(sc->vsc_tapfd, | sc->vsc_mevp = mevent_add(sc->vsc_tapfd, | ||||
EVF_READ, | EVF_READ, | ||||
pci_vtnet_rx_callback, | pci_vtnet_rx_callback, | ||||
sc); | sc); | ||||
if (sc->vsc_mevp == NULL) { | if (sc->vsc_mevp == NULL) { | ||||
WPRINTF(("Could not register event\n")); | WPRINTF(("Could not register event\n")); | ||||
close(sc->vsc_tapfd); | close(sc->vsc_tapfd); | ||||
▲ Show 20 Lines • Show All 200 Lines • Show Last 20 Lines |