2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2019 Vincenzo Maffione <vmaffione@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
19 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
20 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
24 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
25 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * This file implements multiple network backends (tap, netmap, ...),
32 * to be used by network frontends such as virtio-net and e1000.
33 * The API to access the backend (e.g. send/receive packets, negotiate
34 * features) is exported by net_backends.h.
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
40 #include <sys/types.h> /* u_short etc */
41 #ifndef WITHOUT_CAPSICUM
42 #include <sys/capsicum.h>
44 #include <sys/ioctl.h>
49 #include <net/netmap.h>
50 #include <net/netmap_virt.h>
51 #define NETMAP_WITH_LIBS
52 #include <net/netmap_user.h>
54 #ifndef WITHOUT_CAPSICUM
55 #include <capsicum_helpers.h>
68 #include <pthread_np.h>
73 #include <sys/param.h>
74 #include <sys/sysctl.h>
82 #include "net_backends.h"
85 #include <sys/linker_set.h>
88 * Each network backend registers a set of function pointers that are
89 * used to implement the net backends API.
90 * This might need to be exposed if we implement backends in separate files.
93 const char *prefix; /* prefix matching this backend */
96 * Routines used to initialize and cleanup the resources needed
97 * by a backend. The cleanup function is used internally,
98 * and should not be called by the frontend.
100 int (*init)(struct net_backend *be, const char *devname,
101 nvlist_t *nvl, net_be_rxeof_t cb, void *param);
102 void (*cleanup)(struct net_backend *be);
105 * Called to serve a guest transmit request. The scatter-gather
106 * vector provided by the caller has 'iovcnt' elements and contains
107 * the packet to send.
109 ssize_t (*send)(struct net_backend *be, const struct iovec *iov,
113 * Get the length of the next packet that can be received from
114 * the backend. If no packets are currently available, this
115 * function returns 0.
117 ssize_t (*peek_recvlen)(struct net_backend *be);
120 * Called to receive a packet from the backend. When the function
121 * returns a positive value 'len', the scatter-gather vector
122 * provided by the caller contains a packet with such length.
123 * The function returns 0 if the backend doesn't have a new packet to
126 ssize_t (*recv)(struct net_backend *be, const struct iovec *iov,
130 * Ask the backend to enable or disable receive operation in the
131 * backend. On return from a disable operation, it is guaranteed
132 * that the receive callback won't be called until receive is
133 * enabled again. Note however that it is up to the caller to make
134 * sure that netbe_recv() is not currently being executed by another
137 void (*recv_enable)(struct net_backend *be);
138 void (*recv_disable)(struct net_backend *be);
141 * Ask the backend for the virtio-net features it is able to
142 * support. Possible features are TSO, UFO and checksum offloading
143 * in both rx and tx direction and for both IPv4 and IPv6.
145 uint64_t (*get_cap)(struct net_backend *be);
148 * Tell the backend to enable/disable the specified virtio-net
149 * features (capabilities).
151 int (*set_cap)(struct net_backend *be, uint64_t features,
152 unsigned int vnet_hdr_len);
154 struct pci_vtnet_softc *sc;
158 * Length of the virtio-net header used by the backend and the
159 * frontend, respectively. A zero value means that the header
162 unsigned int be_vnet_hdr_len;
163 unsigned int fe_vnet_hdr_len;
165 /* Size of backend-specific private data. */
168 /* Room for backend-specific data. */
172 SET_DECLARE(net_backend_set, struct net_backend);
174 #define VNET_HDR_LEN sizeof(struct virtio_net_rxhdr)
176 #define WPRINTF(params) PRINTLN params
185 * A bounce buffer that allows us to implement the peek_recvlen
186 * callback. In the future we may get the same information from
194 tap_cleanup(struct net_backend *be)
196 struct tap_priv *priv = (struct tap_priv *)be->opaque;
199 mevent_delete(priv->mevp);
208 tap_init(struct net_backend *be, const char *devname,
209 nvlist_t *nvl, net_be_rxeof_t cb, void *param)
211 struct tap_priv *priv = (struct tap_priv *)be->opaque;
214 #ifndef WITHOUT_CAPSICUM
219 WPRINTF(("TAP backend requires non-NULL callback"));
223 strcpy(tbuf, "/dev/");
224 strlcat(tbuf, devname, sizeof(tbuf));
226 be->fd = open(tbuf, O_RDWR);
228 WPRINTF(("open of tap device %s failed", tbuf));
233 * Set non-blocking and register for read
234 * notifications with the event loop
236 if (ioctl(be->fd, FIONBIO, &opt) < 0) {
237 WPRINTF(("tap device O_NONBLOCK failed"));
241 #ifndef WITHOUT_CAPSICUM
242 cap_rights_init(&rights, CAP_EVENT, CAP_READ, CAP_WRITE);
243 if (caph_rights_limit(be->fd, &rights) == -1)
244 errx(EX_OSERR, "Unable to apply rights for sandbox");
247 memset(priv->bbuf, 0, sizeof(priv->bbuf));
250 priv->mevp = mevent_add_disabled(be->fd, EVF_READ, cb, param);
251 if (priv->mevp == NULL) {
252 WPRINTF(("Could not register event"));
264 * Called to send a buffer chain out to the tap device
267 tap_send(struct net_backend *be, const struct iovec *iov, int iovcnt)
269 return (writev(be->fd, iov, iovcnt));
273 tap_peek_recvlen(struct net_backend *be)
275 struct tap_priv *priv = (struct tap_priv *)be->opaque;
278 if (priv->bbuflen > 0) {
280 * We already have a packet in the bounce buffer.
281 * Just return its length.
283 return priv->bbuflen;
287 * Read the next packet (if any) into the bounce buffer, so
288 * that we get to know its length and we can return that
291 ret = read(be->fd, priv->bbuf, sizeof(priv->bbuf));
292 if (ret < 0 && errno == EWOULDBLOCK) {
303 tap_recv(struct net_backend *be, const struct iovec *iov, int iovcnt)
305 struct tap_priv *priv = (struct tap_priv *)be->opaque;
308 if (priv->bbuflen > 0) {
310 * A packet is available in the bounce buffer, so
311 * we read it from there.
313 ret = buf_to_iov(priv->bbuf, priv->bbuflen,
316 /* Mark the bounce buffer as empty. */
322 ret = readv(be->fd, iov, iovcnt);
323 if (ret < 0 && errno == EWOULDBLOCK) {
331 tap_recv_enable(struct net_backend *be)
333 struct tap_priv *priv = (struct tap_priv *)be->opaque;
335 mevent_enable(priv->mevp);
339 tap_recv_disable(struct net_backend *be)
341 struct tap_priv *priv = (struct tap_priv *)be->opaque;
343 mevent_disable(priv->mevp);
347 tap_get_cap(struct net_backend *be)
350 return (0); /* no capabilities for now */
354 tap_set_cap(struct net_backend *be, uint64_t features,
355 unsigned vnet_hdr_len)
358 return ((features || vnet_hdr_len) ? -1 : 0);
361 static struct net_backend tap_backend = {
363 .priv_size = sizeof(struct tap_priv),
365 .cleanup = tap_cleanup,
367 .peek_recvlen = tap_peek_recvlen,
369 .recv_enable = tap_recv_enable,
370 .recv_disable = tap_recv_disable,
371 .get_cap = tap_get_cap,
372 .set_cap = tap_set_cap,
375 /* A clone of the tap backend, with a different prefix. */
376 static struct net_backend vmnet_backend = {
378 .priv_size = sizeof(struct tap_priv),
380 .cleanup = tap_cleanup,
382 .peek_recvlen = tap_peek_recvlen,
384 .recv_enable = tap_recv_enable,
385 .recv_disable = tap_recv_disable,
386 .get_cap = tap_get_cap,
387 .set_cap = tap_set_cap,
390 DATA_SET(net_backend_set, tap_backend);
391 DATA_SET(net_backend_set, vmnet_backend);
399 #define NG_SBUF_MAX_SIZE (4 * 1024 * 1024)
402 ng_init(struct net_backend *be, const char *devname,
403 nvlist_t *nvl, net_be_rxeof_t cb, void *param)
405 struct tap_priv *p = (struct tap_priv *)be->opaque;
406 struct ngm_connect ngc;
407 const char *value, *nodename;
411 unsigned long maxsbsz;
413 #ifndef WITHOUT_CAPSICUM
418 WPRINTF(("Netgraph backend requires non-NULL callback"));
424 memset(&ngc, 0, sizeof(ngc));
426 value = get_config_value_node(nvl, "path");
428 WPRINTF(("path must be provided"));
431 strncpy(ngc.path, value, NG_PATHSIZ - 1);
433 value = get_config_value_node(nvl, "hook");
436 strncpy(ngc.ourhook, value, NG_HOOKSIZ - 1);
438 value = get_config_value_node(nvl, "peerhook");
440 WPRINTF(("peer hook must be provided"));
443 strncpy(ngc.peerhook, value, NG_HOOKSIZ - 1);
445 nodename = get_config_value_node(nvl, "socket");
446 if (NgMkSockNode(nodename,
447 &ctrl_sock, &be->fd) < 0) {
448 WPRINTF(("can't get Netgraph sockets"));
452 if (NgSendMsg(ctrl_sock, ".",
454 NGM_CONNECT, &ngc, sizeof(ngc)) < 0) {
455 WPRINTF(("can't connect to node"));
462 flags = fcntl(be->fd, F_GETFL);
465 WPRINTF(("can't get socket flags"));
469 if (fcntl(be->fd, F_SETFL, flags | O_NONBLOCK) < 0) {
470 WPRINTF(("can't set O_NONBLOCK flag"));
475 * The default ng_socket(4) buffer's size is too low.
476 * Calculate the minimum value between NG_SBUF_MAX_SIZE
477 * and kern.ipc.maxsockbuf.
479 msbsz = sizeof(maxsbsz);
480 if (sysctlbyname("kern.ipc.maxsockbuf", &maxsbsz, &msbsz,
482 WPRINTF(("can't get 'kern.ipc.maxsockbuf' value"));
487 * We can't set the socket buffer size to kern.ipc.maxsockbuf value,
488 * as it takes into account the mbuf(9) overhead.
490 maxsbsz = maxsbsz * MCLBYTES / (MSIZE + MCLBYTES);
492 sbsz = MIN(NG_SBUF_MAX_SIZE, maxsbsz);
494 if (setsockopt(be->fd, SOL_SOCKET, SO_SNDBUF, &sbsz,
496 WPRINTF(("can't set TX buffer size"));
500 if (setsockopt(be->fd, SOL_SOCKET, SO_RCVBUF, &sbsz,
502 WPRINTF(("can't set RX buffer size"));
506 #ifndef WITHOUT_CAPSICUM
507 cap_rights_init(&rights, CAP_EVENT, CAP_READ, CAP_WRITE);
508 if (caph_rights_limit(be->fd, &rights) == -1)
509 errx(EX_OSERR, "Unable to apply rights for sandbox");
512 memset(p->bbuf, 0, sizeof(p->bbuf));
515 p->mevp = mevent_add_disabled(be->fd, EVF_READ, cb, param);
516 if (p->mevp == NULL) {
517 WPRINTF(("Could not register event"));
528 static struct net_backend ng_backend = {
529 .prefix = "netgraph",
530 .priv_size = sizeof(struct tap_priv),
532 .cleanup = tap_cleanup,
534 .peek_recvlen = tap_peek_recvlen,
536 .recv_enable = tap_recv_enable,
537 .recv_disable = tap_recv_disable,
538 .get_cap = tap_get_cap,
539 .set_cap = tap_set_cap,
542 DATA_SET(net_backend_set, ng_backend);
544 #endif /* NETGRAPH */
550 /* The virtio-net features supported by netmap. */
551 #define NETMAP_FEATURES (VIRTIO_NET_F_CSUM | VIRTIO_NET_F_HOST_TSO4 | \
552 VIRTIO_NET_F_HOST_TSO6 | VIRTIO_NET_F_HOST_UFO | \
553 VIRTIO_NET_F_GUEST_CSUM | VIRTIO_NET_F_GUEST_TSO4 | \
554 VIRTIO_NET_F_GUEST_TSO6 | VIRTIO_NET_F_GUEST_UFO)
557 char ifname[IFNAMSIZ];
560 struct netmap_ring *rx;
561 struct netmap_ring *tx;
568 nmreq_init(struct nmreq *req, char *ifname)
571 memset(req, 0, sizeof(*req));
572 strlcpy(req->nr_name, ifname, sizeof(req->nr_name));
573 req->nr_version = NETMAP_API;
577 netmap_set_vnet_hdr_len(struct net_backend *be, int vnet_hdr_len)
581 struct netmap_priv *priv = (struct netmap_priv *)be->opaque;
583 nmreq_init(&req, priv->ifname);
584 req.nr_cmd = NETMAP_BDG_VNET_HDR;
585 req.nr_arg1 = vnet_hdr_len;
586 err = ioctl(be->fd, NIOCREGIF, &req);
588 WPRINTF(("Unable to set vnet header length %d",
593 be->be_vnet_hdr_len = vnet_hdr_len;
599 netmap_has_vnet_hdr_len(struct net_backend *be, unsigned vnet_hdr_len)
601 int prev_hdr_len = be->be_vnet_hdr_len;
604 if (vnet_hdr_len == prev_hdr_len) {
608 ret = netmap_set_vnet_hdr_len(be, vnet_hdr_len);
613 netmap_set_vnet_hdr_len(be, prev_hdr_len);
619 netmap_get_cap(struct net_backend *be)
622 return (netmap_has_vnet_hdr_len(be, VNET_HDR_LEN) ?
623 NETMAP_FEATURES : 0);
627 netmap_set_cap(struct net_backend *be, uint64_t features,
628 unsigned vnet_hdr_len)
631 return (netmap_set_vnet_hdr_len(be, vnet_hdr_len));
635 netmap_init(struct net_backend *be, const char *devname,
636 nvlist_t *nvl, net_be_rxeof_t cb, void *param)
638 struct netmap_priv *priv = (struct netmap_priv *)be->opaque;
640 strlcpy(priv->ifname, devname, sizeof(priv->ifname));
641 priv->ifname[sizeof(priv->ifname) - 1] = '\0';
643 priv->nmd = nm_open(priv->ifname, NULL, NETMAP_NO_TX_POLL, NULL);
644 if (priv->nmd == NULL) {
645 WPRINTF(("Unable to nm_open(): interface '%s', errno (%s)",
646 devname, strerror(errno)));
651 priv->memid = priv->nmd->req.nr_arg2;
652 priv->tx = NETMAP_TXRING(priv->nmd->nifp, 0);
653 priv->rx = NETMAP_RXRING(priv->nmd->nifp, 0);
655 priv->cb_param = param;
656 be->fd = priv->nmd->fd;
658 priv->mevp = mevent_add_disabled(be->fd, EVF_READ, cb, param);
659 if (priv->mevp == NULL) {
660 WPRINTF(("Could not register event"));
668 netmap_cleanup(struct net_backend *be)
670 struct netmap_priv *priv = (struct netmap_priv *)be->opaque;
673 mevent_delete(priv->mevp);
682 netmap_send(struct net_backend *be, const struct iovec *iov,
685 struct netmap_priv *priv = (struct netmap_priv *)be->opaque;
686 struct netmap_ring *ring;
696 if (head == ring->tail) {
697 WPRINTF(("No space, drop %zu bytes", count_iov(iov, iovcnt)));
700 nm_buf = NETMAP_BUF(ring, ring->slot[head].buf_idx);
701 nm_buf_size = ring->nr_buf_size;
704 for (j = 0; j < iovcnt; j++) {
705 int iov_frag_size = iov[j].iov_len;
706 void *iov_frag_buf = iov[j].iov_base;
708 totlen += iov_frag_size;
711 * Split each iovec fragment over more netmap slots, if
717 copylen = iov_frag_size < nm_buf_size ? iov_frag_size : nm_buf_size;
718 memcpy(nm_buf, iov_frag_buf, copylen);
720 iov_frag_buf += copylen;
721 iov_frag_size -= copylen;
723 nm_buf_size -= copylen;
724 nm_buf_len += copylen;
726 if (iov_frag_size == 0) {
730 ring->slot[head].len = nm_buf_len;
731 ring->slot[head].flags = NS_MOREFRAG;
732 head = nm_ring_next(ring, head);
733 if (head == ring->tail) {
735 * We ran out of netmap slots while
736 * splitting the iovec fragments.
738 WPRINTF(("No space, drop %zu bytes",
739 count_iov(iov, iovcnt)));
742 nm_buf = NETMAP_BUF(ring, ring->slot[head].buf_idx);
743 nm_buf_size = ring->nr_buf_size;
748 /* Complete the last slot, which must not have NS_MOREFRAG set. */
749 ring->slot[head].len = nm_buf_len;
750 ring->slot[head].flags = 0;
751 head = nm_ring_next(ring, head);
753 /* Now update ring->head and ring->cur. */
754 ring->head = ring->cur = head;
756 ioctl(be->fd, NIOCTXSYNC, NULL);
762 netmap_peek_recvlen(struct net_backend *be)
764 struct netmap_priv *priv = (struct netmap_priv *)be->opaque;
765 struct netmap_ring *ring = priv->rx;
766 uint32_t head = ring->head;
769 while (head != ring->tail) {
770 struct netmap_slot *slot = ring->slot + head;
773 if ((slot->flags & NS_MOREFRAG) == 0)
775 head = nm_ring_next(ring, head);
782 netmap_recv(struct net_backend *be, const struct iovec *iov, int iovcnt)
784 struct netmap_priv *priv = (struct netmap_priv *)be->opaque;
785 struct netmap_slot *slot = NULL;
786 struct netmap_ring *ring;
796 iov_frag_buf = iov->iov_base;
797 iov_frag_size = iov->iov_len;
803 if (head == ring->tail) {
807 slot = ring->slot + head;
808 nm_buf = NETMAP_BUF(ring, slot->buf_idx);
809 nm_buf_len = slot->len;
812 int copylen = nm_buf_len < iov_frag_size ?
813 nm_buf_len : iov_frag_size;
815 memcpy(iov_frag_buf, nm_buf, copylen);
817 nm_buf_len -= copylen;
818 iov_frag_buf += copylen;
819 iov_frag_size -= copylen;
822 if (nm_buf_len == 0) {
829 /* No space to receive. */
830 WPRINTF(("Short iov, drop %zd bytes",
834 iov_frag_buf = iov->iov_base;
835 iov_frag_size = iov->iov_len;
838 head = nm_ring_next(ring, head);
840 } while (slot->flags & NS_MOREFRAG);
842 /* Release slots to netmap. */
843 ring->head = ring->cur = head;
849 netmap_recv_enable(struct net_backend *be)
851 struct netmap_priv *priv = (struct netmap_priv *)be->opaque;
853 mevent_enable(priv->mevp);
857 netmap_recv_disable(struct net_backend *be)
859 struct netmap_priv *priv = (struct netmap_priv *)be->opaque;
861 mevent_disable(priv->mevp);
864 static struct net_backend netmap_backend = {
866 .priv_size = sizeof(struct netmap_priv),
868 .cleanup = netmap_cleanup,
870 .peek_recvlen = netmap_peek_recvlen,
872 .recv_enable = netmap_recv_enable,
873 .recv_disable = netmap_recv_disable,
874 .get_cap = netmap_get_cap,
875 .set_cap = netmap_set_cap,
878 /* A clone of the netmap backend, with a different prefix. */
879 static struct net_backend vale_backend = {
881 .priv_size = sizeof(struct netmap_priv),
883 .cleanup = netmap_cleanup,
885 .peek_recvlen = netmap_peek_recvlen,
887 .recv_enable = netmap_recv_enable,
888 .recv_disable = netmap_recv_disable,
889 .get_cap = netmap_get_cap,
890 .set_cap = netmap_set_cap,
893 DATA_SET(net_backend_set, netmap_backend);
894 DATA_SET(net_backend_set, vale_backend);
897 netbe_legacy_config(nvlist_t *nvl, const char *opts)
904 cp = strchr(opts, ',');
906 set_config_value_node(nvl, "backend", opts);
909 backend = strndup(opts, cp - opts);
910 set_config_value_node(nvl, "backend", backend);
912 return (pci_parse_legacy_config(nvl, cp + 1));
916 * Initialize a backend and attach to the frontend.
917 * This is called during frontend initialization.
918 * @ret is a pointer to the backend to be initialized
919 * @devname is the backend-name as supplied on the command line,
920 * e.g. -s 2:0,frontend-name,backend-name[,other-args]
921 * @cb is the receive callback supplied by the frontend,
922 * and it is invoked in the event loop when a receive
923 * event is generated in the hypervisor,
924 * @param is a pointer to the frontend, and normally used as
925 * the argument for the callback.
928 netbe_init(struct net_backend **ret, nvlist_t *nvl, net_be_rxeof_t cb,
931 struct net_backend **pbe, *nbe, *tbe = NULL;
936 value = get_config_value_node(nvl, "backend");
940 devname = strdup(value);
943 * Find the network backend that matches the user-provided
944 * device name. net_backend_set is built using a linker set.
946 SET_FOREACH(pbe, net_backend_set) {
947 if (strncmp(devname, (*pbe)->prefix,
948 strlen((*pbe)->prefix)) == 0) {
950 assert(tbe->init != NULL);
951 assert(tbe->cleanup != NULL);
952 assert(tbe->send != NULL);
953 assert(tbe->recv != NULL);
954 assert(tbe->get_cap != NULL);
955 assert(tbe->set_cap != NULL);
966 nbe = calloc(1, sizeof(*nbe) + tbe->priv_size);
967 *nbe = *tbe; /* copy the template */
970 nbe->be_vnet_hdr_len = 0;
971 nbe->fe_vnet_hdr_len = 0;
973 /* Initialize the backend. */
974 err = nbe->init(nbe, devname, nvl, cb, param);
988 netbe_cleanup(struct net_backend *be)
998 netbe_get_cap(struct net_backend *be)
1002 return (be->get_cap(be));
1006 netbe_set_cap(struct net_backend *be, uint64_t features,
1007 unsigned vnet_hdr_len)
1013 /* There are only three valid lengths, i.e., 0, 10 and 12. */
1014 if (vnet_hdr_len && vnet_hdr_len != VNET_HDR_LEN
1015 && vnet_hdr_len != (VNET_HDR_LEN - sizeof(uint16_t)))
1018 be->fe_vnet_hdr_len = vnet_hdr_len;
1020 ret = be->set_cap(be, features, vnet_hdr_len);
1021 assert(be->be_vnet_hdr_len == 0 ||
1022 be->be_vnet_hdr_len == be->fe_vnet_hdr_len);
1028 netbe_send(struct net_backend *be, const struct iovec *iov, int iovcnt)
1031 return (be->send(be, iov, iovcnt));
1035 netbe_peek_recvlen(struct net_backend *be)
1038 return (be->peek_recvlen(be));
1042 * Try to read a packet from the backend, without blocking.
1043 * If no packets are available, return 0. In case of success, return
1044 * the length of the packet just read. Return -1 in case of errors.
1047 netbe_recv(struct net_backend *be, const struct iovec *iov, int iovcnt)
1050 return (be->recv(be, iov, iovcnt));
1054 * Read a packet from the backend and discard it.
1055 * Returns the size of the discarded packet or zero if no packet was available.
1056 * A negative error code is returned in case of read error.
1059 netbe_rx_discard(struct net_backend *be)
1062 * MP note: the dummybuf is only used to discard frames,
1063 * so there is no need for it to be per-vtnet or locked.
1064 * We only make it large enough for TSO-sized segment.
1066 static uint8_t dummybuf[65536 + 64];
1069 iov.iov_base = dummybuf;
1070 iov.iov_len = sizeof(dummybuf);
1072 return netbe_recv(be, &iov, 1);
1076 netbe_rx_disable(struct net_backend *be)
1079 return be->recv_disable(be);
1083 netbe_rx_enable(struct net_backend *be)
1086 return be->recv_enable(be);
1090 netbe_get_vnet_hdr_len(struct net_backend *be)
1093 return (be->be_vnet_hdr_len);