/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2019 Vincenzo Maffione <[email protected]>4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS``AS IS'' AND15* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR17* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS18* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,19* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT20* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR21* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,22* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE23* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,24* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.25*/2627#ifndef __NET_BACKENDS_H__28#define __NET_BACKENDS_H__2930#include <sys/nv.h>31#include <sys/time.h>32#include <sys/uio.h>3334#include "mevent.h"3536/* Opaque type representing a network backend. */37typedef struct net_backend net_backend_t;3839/* Interface between network frontends and the network backends. */40typedef void (*net_be_rxeof_t)(int, enum ev_type, void *param);41int netbe_init(net_backend_t **be, nvlist_t *nvl, net_be_rxeof_t cb,42void *param);43int netbe_legacy_config(nvlist_t *nvl, const char *opts);44void netbe_cleanup(net_backend_t *be);45uint64_t netbe_get_cap(net_backend_t *be);46int netbe_set_cap(net_backend_t *be, uint64_t cap,47unsigned vnet_hdr_len);48size_t netbe_get_vnet_hdr_len(net_backend_t *be);49ssize_t netbe_send(net_backend_t *be, const struct iovec *iov, int iovcnt);50ssize_t netbe_peek_recvlen(net_backend_t *be);51ssize_t netbe_recv(net_backend_t *be, const struct iovec *iov, int iovcnt);52ssize_t netbe_rx_discard(net_backend_t *be);53void netbe_rx_disable(net_backend_t *be);54void netbe_rx_enable(net_backend_t *be);555657/*58* Network device capabilities taken from the VirtIO standard.59* Despite the name, these capabilities can be used by different frontends60* (virtio-net, ptnet) and supported by different backends (netmap, tap, ...).61*/62#define VIRTIO_NET_F_CSUM (1 << 0) /* host handles partial cksum */63#define VIRTIO_NET_F_GUEST_CSUM (1 << 1) /* guest handles partial cksum */64#define VIRTIO_NET_F_MTU (1 << 3) /* initial MTU advice */65#define VIRTIO_NET_F_MAC (1 << 5) /* host supplies MAC */66#define VIRTIO_NET_F_GSO_DEPREC (1 << 6) /* deprecated: host handles GSO */67#define VIRTIO_NET_F_GUEST_TSO4 (1 << 7) /* guest can rcv TSOv4 */68#define VIRTIO_NET_F_GUEST_TSO6 (1 << 8) /* guest can rcv TSOv6 */69#define VIRTIO_NET_F_GUEST_ECN (1 << 9) /* guest can rcv TSO with ECN */70#define VIRTIO_NET_F_GUEST_UFO (1 << 10) /* guest can rcv UFO */71#define VIRTIO_NET_F_HOST_TSO4 (1 << 11) /* host can rcv TSOv4 */72#define VIRTIO_NET_F_HOST_TSO6 (1 << 12) /* host can rcv TSOv6 */73#define VIRTIO_NET_F_HOST_ECN (1 << 13) /* host can rcv TSO with ECN */74#define VIRTIO_NET_F_HOST_UFO (1 << 14) /* host can rcv UFO */75#define VIRTIO_NET_F_MRG_RXBUF (1 << 15) /* host can merge RX buffers */76#define VIRTIO_NET_F_STATUS (1 << 16) /* config status field available */77#define VIRTIO_NET_F_CTRL_VQ (1 << 17) /* control channel available */78#define VIRTIO_NET_F_CTRL_RX (1 << 18) /* control channel RX mode support */79#define VIRTIO_NET_F_CTRL_VLAN (1 << 19) /* control channel VLAN filtering */80#define VIRTIO_NET_F_GUEST_ANNOUNCE \81(1 << 21) /* guest can send gratuitous pkts */82#define VIRTIO_NET_F_MQ (1 << 22) /* host supports multiple VQ pairs */8384/*85* Fixed network header size86*/87struct virtio_net_rxhdr {88uint8_t vrh_flags;89uint8_t vrh_gso_type;90uint16_t vrh_hdr_len;91uint16_t vrh_gso_size;92uint16_t vrh_csum_start;93uint16_t vrh_csum_offset;94uint16_t vrh_bufs;95} __packed;96#define VNET_HDR_LEN sizeof(struct virtio_net_rxhdr)9798#endif /* __NET_BACKENDS_H__ */99100101