2 * SPDX-License-Identifier: BSD-2-Clause
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.
29 * This file implements multiple network backends (tap, netmap, ...),
30 * to be used by network frontends such as virtio-net and e1000.
31 * The API to access the backend (e.g. send/receive packets, negotiate
32 * features) is exported by net_backends.h.
35 #include <sys/cdefs.h>
36 #include <sys/types.h> /* u_short etc */
37 #ifndef WITHOUT_CAPSICUM
38 #include <sys/capsicum.h>
40 #include <sys/ioctl.h>
45 #include <net/if_tap.h>
46 #include <net/netmap.h>
47 #include <net/netmap_virt.h>
48 #define NETMAP_WITH_LIBS
49 #include <net/netmap_user.h>
51 #ifndef WITHOUT_CAPSICUM
52 #include <capsicum_helpers.h>
65 #include <pthread_np.h>
70 #include <sys/param.h>
71 #include <sys/sysctl.h>
79 #include "net_backends.h"
82 #include <sys/linker_set.h>
85 * Each network backend registers a set of function pointers that are
86 * used to implement the net backends API.
87 * This might need to be exposed if we implement backends in separate files.
90 const char *prefix; /* prefix matching this backend */
93 * Routines used to initialize and cleanup the resources needed
94 * by a backend. The cleanup function is used internally,
95 * and should not be called by the frontend.
97 int (*init)(struct net_backend *be, const char *devname,
98 nvlist_t *nvl, net_be_rxeof_t cb, void *param);
99 void (*cleanup)(struct net_backend *be);
102 * Called to serve a guest transmit request. The scatter-gather
103 * vector provided by the caller has 'iovcnt' elements and contains
104 * the packet to send.
106 ssize_t (*send)(struct net_backend *be, const struct iovec *iov,
110 * Get the length of the next packet that can be received from
111 * the backend. If no packets are currently available, this
112 * function returns 0.
114 ssize_t (*peek_recvlen)(struct net_backend *be);
117 * Called to receive a packet from the backend. When the function
118 * returns a positive value 'len', the scatter-gather vector
119 * provided by the caller contains a packet with such length.
120 * The function returns 0 if the backend doesn't have a new packet to
123 ssize_t (*recv)(struct net_backend *be, const struct iovec *iov,
127 * Ask the backend to enable or disable receive operation in the
128 * backend. On return from a disable operation, it is guaranteed
129 * that the receive callback won't be called until receive is
130 * enabled again. Note however that it is up to the caller to make
131 * sure that netbe_recv() is not currently being executed by another
134 void (*recv_enable)(struct net_backend *be);
135 void (*recv_disable)(struct net_backend *be);
138 * Ask the backend for the virtio-net features it is able to
139 * support. Possible features are TSO, UFO and checksum offloading
140 * in both rx and tx direction and for both IPv4 and IPv6.
142 uint64_t (*get_cap)(struct net_backend *be);
145 * Tell the backend to enable/disable the specified virtio-net
146 * features (capabilities).
148 int (*set_cap)(struct net_backend *be, uint64_t features,
149 unsigned int vnet_hdr_len);
151 struct pci_vtnet_softc *sc;
155 * Length of the virtio-net header used by the backend and the
156 * frontend, respectively. A zero value means that the header
159 unsigned int be_vnet_hdr_len;
160 unsigned int fe_vnet_hdr_len;
162 /* Size of backend-specific private data. */
165 /* Backend-specific private data follows. */
168 #define NET_BE_PRIV(be) ((void *)((be) + 1))
169 #define NET_BE_SIZE(be) (sizeof(*be) + (be)->priv_size)
171 SET_DECLARE(net_backend_set, struct net_backend);
173 #define VNET_HDR_LEN sizeof(struct virtio_net_rxhdr)
175 #define WPRINTF(params) PRINTLN params
184 * A bounce buffer that allows us to implement the peek_recvlen
185 * callback. In the future we may get the same information from
193 tap_cleanup(struct net_backend *be)
195 struct tap_priv *priv = NET_BE_PRIV(be);
198 mevent_delete(priv->mevp);
207 tap_init(struct net_backend *be, const char *devname,
208 nvlist_t *nvl __unused, net_be_rxeof_t cb, void *param)
210 struct tap_priv *priv = NET_BE_PRIV(be);
212 int opt = 1, up = IFF_UP;
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 if (ioctl(be->fd, VMIO_SIOCSIFFLAGS, up)) {
242 WPRINTF(("tap device link up failed"));
246 #ifndef WITHOUT_CAPSICUM
247 cap_rights_init(&rights, CAP_EVENT, CAP_READ, CAP_WRITE);
248 if (caph_rights_limit(be->fd, &rights) == -1)
249 errx(EX_OSERR, "Unable to apply rights for sandbox");
252 memset(priv->bbuf, 0, sizeof(priv->bbuf));
255 priv->mevp = mevent_add_disabled(be->fd, EVF_READ, cb, param);
256 if (priv->mevp == NULL) {
257 WPRINTF(("Could not register event"));
269 * Called to send a buffer chain out to the tap device
272 tap_send(struct net_backend *be, const struct iovec *iov, int iovcnt)
274 return (writev(be->fd, iov, iovcnt));
278 tap_peek_recvlen(struct net_backend *be)
280 struct tap_priv *priv = NET_BE_PRIV(be);
283 if (priv->bbuflen > 0) {
285 * We already have a packet in the bounce buffer.
286 * Just return its length.
288 return priv->bbuflen;
292 * Read the next packet (if any) into the bounce buffer, so
293 * that we get to know its length and we can return that
296 ret = read(be->fd, priv->bbuf, sizeof(priv->bbuf));
297 if (ret < 0 && errno == EWOULDBLOCK) {
308 tap_recv(struct net_backend *be, const struct iovec *iov, int iovcnt)
310 struct tap_priv *priv = NET_BE_PRIV(be);
313 if (priv->bbuflen > 0) {
315 * A packet is available in the bounce buffer, so
316 * we read it from there.
318 ret = buf_to_iov(priv->bbuf, priv->bbuflen,
321 /* Mark the bounce buffer as empty. */
327 ret = readv(be->fd, iov, iovcnt);
328 if (ret < 0 && errno == EWOULDBLOCK) {
336 tap_recv_enable(struct net_backend *be)
338 struct tap_priv *priv = NET_BE_PRIV(be);
340 mevent_enable(priv->mevp);
344 tap_recv_disable(struct net_backend *be)
346 struct tap_priv *priv = NET_BE_PRIV(be);
348 mevent_disable(priv->mevp);
352 tap_get_cap(struct net_backend *be __unused)
355 return (0); /* no capabilities for now */
359 tap_set_cap(struct net_backend *be __unused, uint64_t features,
360 unsigned vnet_hdr_len)
363 return ((features || vnet_hdr_len) ? -1 : 0);
366 static struct net_backend tap_backend = {
368 .priv_size = sizeof(struct tap_priv),
370 .cleanup = tap_cleanup,
372 .peek_recvlen = tap_peek_recvlen,
374 .recv_enable = tap_recv_enable,
375 .recv_disable = tap_recv_disable,
376 .get_cap = tap_get_cap,
377 .set_cap = tap_set_cap,
380 /* A clone of the tap backend, with a different prefix. */
381 static struct net_backend vmnet_backend = {
383 .priv_size = sizeof(struct tap_priv),
385 .cleanup = tap_cleanup,
387 .peek_recvlen = tap_peek_recvlen,
389 .recv_enable = tap_recv_enable,
390 .recv_disable = tap_recv_disable,
391 .get_cap = tap_get_cap,
392 .set_cap = tap_set_cap,
395 DATA_SET(net_backend_set, tap_backend);
396 DATA_SET(net_backend_set, vmnet_backend);
404 #define NG_SBUF_MAX_SIZE (4 * 1024 * 1024)
407 ng_init(struct net_backend *be, const char *devname __unused,
408 nvlist_t *nvl, net_be_rxeof_t cb, void *param)
410 struct tap_priv *p = NET_BE_PRIV(be);
411 struct ngm_connect ngc;
412 const char *value, *nodename;
416 unsigned long maxsbsz;
418 #ifndef WITHOUT_CAPSICUM
423 WPRINTF(("Netgraph backend requires non-NULL callback"));
429 memset(&ngc, 0, sizeof(ngc));
431 value = get_config_value_node(nvl, "path");
433 WPRINTF(("path must be provided"));
436 strncpy(ngc.path, value, NG_PATHSIZ - 1);
438 value = get_config_value_node(nvl, "hook");
441 strncpy(ngc.ourhook, value, NG_HOOKSIZ - 1);
443 value = get_config_value_node(nvl, "peerhook");
445 WPRINTF(("peer hook must be provided"));
448 strncpy(ngc.peerhook, value, NG_HOOKSIZ - 1);
450 nodename = get_config_value_node(nvl, "socket");
451 if (NgMkSockNode(nodename,
452 &ctrl_sock, &be->fd) < 0) {
453 WPRINTF(("can't get Netgraph sockets"));
457 if (NgSendMsg(ctrl_sock, ".",
459 NGM_CONNECT, &ngc, sizeof(ngc)) < 0) {
460 WPRINTF(("can't connect to node"));
467 flags = fcntl(be->fd, F_GETFL);
470 WPRINTF(("can't get socket flags"));
474 if (fcntl(be->fd, F_SETFL, flags | O_NONBLOCK) < 0) {
475 WPRINTF(("can't set O_NONBLOCK flag"));
480 * The default ng_socket(4) buffer's size is too low.
481 * Calculate the minimum value between NG_SBUF_MAX_SIZE
482 * and kern.ipc.maxsockbuf.
484 msbsz = sizeof(maxsbsz);
485 if (sysctlbyname("kern.ipc.maxsockbuf", &maxsbsz, &msbsz,
487 WPRINTF(("can't get 'kern.ipc.maxsockbuf' value"));
492 * We can't set the socket buffer size to kern.ipc.maxsockbuf value,
493 * as it takes into account the mbuf(9) overhead.
495 maxsbsz = maxsbsz * MCLBYTES / (MSIZE + MCLBYTES);
497 sbsz = MIN(NG_SBUF_MAX_SIZE, maxsbsz);
499 if (setsockopt(be->fd, SOL_SOCKET, SO_SNDBUF, &sbsz,
501 WPRINTF(("can't set TX buffer size"));
505 if (setsockopt(be->fd, SOL_SOCKET, SO_RCVBUF, &sbsz,
507 WPRINTF(("can't set RX buffer size"));
511 #ifndef WITHOUT_CAPSICUM
512 cap_rights_init(&rights, CAP_EVENT, CAP_READ, CAP_WRITE);
513 if (caph_rights_limit(be->fd, &rights) == -1)
514 errx(EX_OSERR, "Unable to apply rights for sandbox");
517 memset(p->bbuf, 0, sizeof(p->bbuf));
520 p->mevp = mevent_add_disabled(be->fd, EVF_READ, cb, param);
521 if (p->mevp == NULL) {
522 WPRINTF(("Could not register event"));
533 static struct net_backend ng_backend = {
534 .prefix = "netgraph",
535 .priv_size = sizeof(struct tap_priv),
537 .cleanup = tap_cleanup,
539 .peek_recvlen = tap_peek_recvlen,
541 .recv_enable = tap_recv_enable,
542 .recv_disable = tap_recv_disable,
543 .get_cap = tap_get_cap,
544 .set_cap = tap_set_cap,
547 DATA_SET(net_backend_set, ng_backend);
549 #endif /* NETGRAPH */
555 /* The virtio-net features supported by netmap. */
556 #define NETMAP_FEATURES (VIRTIO_NET_F_CSUM | VIRTIO_NET_F_HOST_TSO4 | \
557 VIRTIO_NET_F_HOST_TSO6 | VIRTIO_NET_F_HOST_UFO | \
558 VIRTIO_NET_F_GUEST_CSUM | VIRTIO_NET_F_GUEST_TSO4 | \
559 VIRTIO_NET_F_GUEST_TSO6 | VIRTIO_NET_F_GUEST_UFO)
562 char ifname[IFNAMSIZ];
565 struct netmap_ring *rx;
566 struct netmap_ring *tx;
573 nmreq_init(struct nmreq *req, char *ifname)
576 memset(req, 0, sizeof(*req));
577 strlcpy(req->nr_name, ifname, sizeof(req->nr_name));
578 req->nr_version = NETMAP_API;
582 netmap_set_vnet_hdr_len(struct net_backend *be, int vnet_hdr_len)
586 struct netmap_priv *priv = NET_BE_PRIV(be);
588 nmreq_init(&req, priv->ifname);
589 req.nr_cmd = NETMAP_BDG_VNET_HDR;
590 req.nr_arg1 = vnet_hdr_len;
591 err = ioctl(be->fd, NIOCREGIF, &req);
593 WPRINTF(("Unable to set vnet header length %d",
598 be->be_vnet_hdr_len = vnet_hdr_len;
604 netmap_has_vnet_hdr_len(struct net_backend *be, unsigned vnet_hdr_len)
606 unsigned prev_hdr_len = be->be_vnet_hdr_len;
609 if (vnet_hdr_len == prev_hdr_len) {
613 ret = netmap_set_vnet_hdr_len(be, vnet_hdr_len);
618 netmap_set_vnet_hdr_len(be, prev_hdr_len);
624 netmap_get_cap(struct net_backend *be)
627 return (netmap_has_vnet_hdr_len(be, VNET_HDR_LEN) ?
628 NETMAP_FEATURES : 0);
632 netmap_set_cap(struct net_backend *be, uint64_t features __unused,
633 unsigned vnet_hdr_len)
636 return (netmap_set_vnet_hdr_len(be, vnet_hdr_len));
640 netmap_init(struct net_backend *be, const char *devname,
641 nvlist_t *nvl __unused, net_be_rxeof_t cb, void *param)
643 struct netmap_priv *priv = NET_BE_PRIV(be);
645 strlcpy(priv->ifname, devname, sizeof(priv->ifname));
646 priv->ifname[sizeof(priv->ifname) - 1] = '\0';
648 priv->nmd = nm_open(priv->ifname, NULL, NETMAP_NO_TX_POLL, NULL);
649 if (priv->nmd == NULL) {
650 WPRINTF(("Unable to nm_open(): interface '%s', errno (%s)",
651 devname, strerror(errno)));
655 priv->memid = priv->nmd->req.nr_arg2;
656 priv->tx = NETMAP_TXRING(priv->nmd->nifp, 0);
657 priv->rx = NETMAP_RXRING(priv->nmd->nifp, 0);
659 priv->cb_param = param;
660 be->fd = priv->nmd->fd;
662 priv->mevp = mevent_add_disabled(be->fd, EVF_READ, cb, param);
663 if (priv->mevp == NULL) {
664 WPRINTF(("Could not register event"));
672 netmap_cleanup(struct net_backend *be)
674 struct netmap_priv *priv = NET_BE_PRIV(be);
677 mevent_delete(priv->mevp);
686 netmap_send(struct net_backend *be, const struct iovec *iov,
689 struct netmap_priv *priv = NET_BE_PRIV(be);
690 struct netmap_ring *ring;
700 if (head == ring->tail) {
701 WPRINTF(("No space, drop %zu bytes", count_iov(iov, iovcnt)));
704 nm_buf = NETMAP_BUF(ring, ring->slot[head].buf_idx);
705 nm_buf_size = ring->nr_buf_size;
708 for (j = 0; j < iovcnt; j++) {
709 uint8_t *iov_frag_buf = iov[j].iov_base;
710 int iov_frag_size = iov[j].iov_len;
712 totlen += iov_frag_size;
715 * Split each iovec fragment over more netmap slots, if
721 copylen = iov_frag_size < nm_buf_size ? iov_frag_size : nm_buf_size;
722 memcpy(nm_buf, iov_frag_buf, copylen);
724 iov_frag_buf += copylen;
725 iov_frag_size -= copylen;
727 nm_buf_size -= copylen;
728 nm_buf_len += copylen;
730 if (iov_frag_size == 0) {
734 ring->slot[head].len = nm_buf_len;
735 ring->slot[head].flags = NS_MOREFRAG;
736 head = nm_ring_next(ring, head);
737 if (head == ring->tail) {
739 * We ran out of netmap slots while
740 * splitting the iovec fragments.
742 WPRINTF(("No space, drop %zu bytes",
743 count_iov(iov, iovcnt)));
746 nm_buf = NETMAP_BUF(ring, ring->slot[head].buf_idx);
747 nm_buf_size = ring->nr_buf_size;
752 /* Complete the last slot, which must not have NS_MOREFRAG set. */
753 ring->slot[head].len = nm_buf_len;
754 ring->slot[head].flags = 0;
755 head = nm_ring_next(ring, head);
757 /* Now update ring->head and ring->cur. */
758 ring->head = ring->cur = head;
760 ioctl(be->fd, NIOCTXSYNC, NULL);
766 netmap_peek_recvlen(struct net_backend *be)
768 struct netmap_priv *priv = NET_BE_PRIV(be);
769 struct netmap_ring *ring = priv->rx;
770 uint32_t head = ring->head;
773 while (head != ring->tail) {
774 struct netmap_slot *slot = ring->slot + head;
777 if ((slot->flags & NS_MOREFRAG) == 0)
779 head = nm_ring_next(ring, head);
786 netmap_recv(struct net_backend *be, const struct iovec *iov, int iovcnt)
788 struct netmap_priv *priv = NET_BE_PRIV(be);
789 struct netmap_slot *slot = NULL;
790 struct netmap_ring *ring;
791 uint8_t *iov_frag_buf;
800 iov_frag_buf = iov->iov_base;
801 iov_frag_size = iov->iov_len;
807 if (head == ring->tail) {
811 slot = ring->slot + head;
812 nm_buf = NETMAP_BUF(ring, slot->buf_idx);
813 nm_buf_len = slot->len;
816 int copylen = nm_buf_len < iov_frag_size ?
817 nm_buf_len : iov_frag_size;
819 memcpy(iov_frag_buf, nm_buf, copylen);
821 nm_buf_len -= copylen;
822 iov_frag_buf += copylen;
823 iov_frag_size -= copylen;
826 if (nm_buf_len == 0) {
833 /* No space to receive. */
834 WPRINTF(("Short iov, drop %zd bytes",
838 iov_frag_buf = iov->iov_base;
839 iov_frag_size = iov->iov_len;
842 head = nm_ring_next(ring, head);
844 } while (slot->flags & NS_MOREFRAG);
846 /* Release slots to netmap. */
847 ring->head = ring->cur = head;
853 netmap_recv_enable(struct net_backend *be)
855 struct netmap_priv *priv = NET_BE_PRIV(be);
857 mevent_enable(priv->mevp);
861 netmap_recv_disable(struct net_backend *be)
863 struct netmap_priv *priv = NET_BE_PRIV(be);
865 mevent_disable(priv->mevp);
868 static struct net_backend netmap_backend = {
870 .priv_size = sizeof(struct netmap_priv),
872 .cleanup = netmap_cleanup,
874 .peek_recvlen = netmap_peek_recvlen,
876 .recv_enable = netmap_recv_enable,
877 .recv_disable = netmap_recv_disable,
878 .get_cap = netmap_get_cap,
879 .set_cap = netmap_set_cap,
882 /* A clone of the netmap backend, with a different prefix. */
883 static struct net_backend vale_backend = {
885 .priv_size = sizeof(struct netmap_priv),
887 .cleanup = netmap_cleanup,
889 .peek_recvlen = netmap_peek_recvlen,
891 .recv_enable = netmap_recv_enable,
892 .recv_disable = netmap_recv_disable,
893 .get_cap = netmap_get_cap,
894 .set_cap = netmap_set_cap,
897 DATA_SET(net_backend_set, netmap_backend);
898 DATA_SET(net_backend_set, vale_backend);
901 netbe_legacy_config(nvlist_t *nvl, const char *opts)
908 cp = strchr(opts, ',');
910 set_config_value_node(nvl, "backend", opts);
913 backend = strndup(opts, cp - opts);
914 set_config_value_node(nvl, "backend", backend);
916 return (pci_parse_legacy_config(nvl, cp + 1));
920 * Initialize a backend and attach to the frontend.
921 * This is called during frontend initialization.
922 * @ret is a pointer to the backend to be initialized
923 * @devname is the backend-name as supplied on the command line,
924 * e.g. -s 2:0,frontend-name,backend-name[,other-args]
925 * @cb is the receive callback supplied by the frontend,
926 * and it is invoked in the event loop when a receive
927 * event is generated in the hypervisor,
928 * @param is a pointer to the frontend, and normally used as
929 * the argument for the callback.
932 netbe_init(struct net_backend **ret, nvlist_t *nvl, net_be_rxeof_t cb,
935 struct net_backend **pbe, *nbe, *tbe = NULL;
936 const char *value, *type;
940 value = get_config_value_node(nvl, "backend");
944 devname = strdup(value);
947 * Use the type given by configuration if exists; otherwise
948 * use the prefix of the backend as the type.
950 type = get_config_value_node(nvl, "type");
955 * Find the network backend that matches the user-provided
956 * device name. net_backend_set is built using a linker set.
958 SET_FOREACH(pbe, net_backend_set) {
959 if (strncmp(type, (*pbe)->prefix,
960 strlen((*pbe)->prefix)) == 0) {
962 assert(tbe->init != NULL);
963 assert(tbe->cleanup != NULL);
964 assert(tbe->send != NULL);
965 assert(tbe->recv != NULL);
966 assert(tbe->get_cap != NULL);
967 assert(tbe->set_cap != NULL);
978 nbe = calloc(1, NET_BE_SIZE(tbe));
979 *nbe = *tbe; /* copy the template */
982 nbe->be_vnet_hdr_len = 0;
983 nbe->fe_vnet_hdr_len = 0;
985 /* Initialize the backend. */
986 err = nbe->init(nbe, devname, nvl, cb, param);
1000 netbe_cleanup(struct net_backend *be)
1010 netbe_get_cap(struct net_backend *be)
1014 return (be->get_cap(be));
1018 netbe_set_cap(struct net_backend *be, uint64_t features,
1019 unsigned vnet_hdr_len)
1025 /* There are only three valid lengths, i.e., 0, 10 and 12. */
1026 if (vnet_hdr_len && vnet_hdr_len != VNET_HDR_LEN
1027 && vnet_hdr_len != (VNET_HDR_LEN - sizeof(uint16_t)))
1030 be->fe_vnet_hdr_len = vnet_hdr_len;
1032 ret = be->set_cap(be, features, vnet_hdr_len);
1033 assert(be->be_vnet_hdr_len == 0 ||
1034 be->be_vnet_hdr_len == be->fe_vnet_hdr_len);
1040 netbe_send(struct net_backend *be, const struct iovec *iov, int iovcnt)
1043 return (be->send(be, iov, iovcnt));
1047 netbe_peek_recvlen(struct net_backend *be)
1050 return (be->peek_recvlen(be));
1054 * Try to read a packet from the backend, without blocking.
1055 * If no packets are available, return 0. In case of success, return
1056 * the length of the packet just read. Return -1 in case of errors.
1059 netbe_recv(struct net_backend *be, const struct iovec *iov, int iovcnt)
1062 return (be->recv(be, iov, iovcnt));
1066 * Read a packet from the backend and discard it.
1067 * Returns the size of the discarded packet or zero if no packet was available.
1068 * A negative error code is returned in case of read error.
1071 netbe_rx_discard(struct net_backend *be)
1074 * MP note: the dummybuf is only used to discard frames,
1075 * so there is no need for it to be per-vtnet or locked.
1076 * We only make it large enough for TSO-sized segment.
1078 static uint8_t dummybuf[65536 + 64];
1081 iov.iov_base = dummybuf;
1082 iov.iov_len = sizeof(dummybuf);
1084 return netbe_recv(be, &iov, 1);
1088 netbe_rx_disable(struct net_backend *be)
1091 return be->recv_disable(be);
1095 netbe_rx_enable(struct net_backend *be)
1098 return be->recv_enable(be);
1102 netbe_get_vnet_hdr_len(struct net_backend *be)
1105 return (be->be_vnet_hdr_len);