18 #include <sys/types.h> 22 #include <linux/if_tun.h> 23 #include <sys/ioctl.h> 24 #include <sys/eventfd.h> 38 #define foreach_virtio_input_error \ 39 _(BUFFER_ALLOC, "buffer alloc error") \ 44 #define _(f,s) VIRTIO_INPUT_ERROR_##f, 62 virtio_net_hdr_v1_t
hdr;
73 s =
format (s,
"virtio: hw_if_index %d next-index %d vring %u len %u",
75 s =
format (s,
"\n%Uhdr: flags 0x%02x gso_type 0x%02x hdr_len %u " 76 "gso_size %u csum_start %u csum_offset %u num_buffers %u",
78 t->
hdr.flags, t->
hdr.gso_type, t->
hdr.hdr_len, t->
hdr.gso_size,
79 t->
hdr.csum_start, t->
hdr.csum_offset, t->
hdr.num_buffers);
86 const int hdr_sz,
u32 node_index)
88 u16 used, next, avail, n_slots, n_refill;
95 if (sz - used < sz / 8)
105 vring->
size, n_refill,
111 VIRTIO_INPUT_ERROR_BUFFER_ALLOC, n_refill - n_slots);
135 next = (next + 1) & mask;
154 const int hdr_sz,
u32 node_index)
156 u16 used, next, n_slots, n_refill,
flags = 0, first_desc_flags;
166 n_refill =
clib_min (sz - used, 64);
178 VIRTIO_INPUT_ERROR_BUFFER_ALLOC, n_refill - n_slots);
185 vring_packed_desc_t *d = &vring->
packed_desc[next];
207 first_desc_flags =
flags;
239 u16 ethertype = 0, l2hdr_sz = 0;
241 if (type == VIRTIO_IF_TYPE_TUN)
243 switch (b0->
data[0] & 0xf0)
246 ethertype = ETHERNET_TYPE_IP4;
249 ethertype = ETHERNET_TYPE_IP6;
257 ethertype = clib_net_to_host_u16 (eh->
type);
265 ethertype = clib_net_to_host_u16 (vlan->
type);
266 l2hdr_sz +=
sizeof (*vlan);
267 if (ethertype == ETHERNET_TYPE_VLAN)
270 ethertype = clib_net_to_host_u16 (vlan->
type);
271 l2hdr_sz +=
sizeof (*vlan);
286 (VNET_BUFFER_F_IS_IP4 | VNET_BUFFER_F_OFFLOAD_IP_CKSUM);
288 (VNET_BUFFER_F_L2_HDR_OFFSET_VALID
289 | VNET_BUFFER_F_L3_HDR_OFFSET_VALID |
290 VNET_BUFFER_F_L4_HDR_OFFSET_VALID);
299 b0->
flags |= (VNET_BUFFER_F_IS_IP6 |
300 VNET_BUFFER_F_L2_HDR_OFFSET_VALID
301 | VNET_BUFFER_F_L3_HDR_OFFSET_VALID |
302 VNET_BUFFER_F_L4_HDR_OFFSET_VALID);
304 if (*l4_proto == IP_PROTOCOL_TCP)
306 b0->
flags |= VNET_BUFFER_F_OFFLOAD_TCP_CKSUM;
309 (b0)->l4_hdr_offset);
312 else if (*l4_proto == IP_PROTOCOL_UDP)
314 b0->
flags |= VNET_BUFFER_F_OFFLOAD_UDP_CKSUM;
317 (b0)->l4_hdr_offset);
318 *l4_hdr_sz =
sizeof (*udp);
325 u8 l4_proto,
u8 l4_hdr_sz)
332 b0->
flags |= VNET_BUFFER_F_GSO | VNET_BUFFER_F_IS_IP4;
339 b0->
flags |= VNET_BUFFER_F_GSO | VNET_BUFFER_F_IS_IP6;
372 #define increment_last(last, packed, vring) \ 375 if (packed && last >= vring->size) \ 378 vring->used_wrap_counter ^= 1; \ 386 int gso_enabled,
int checksum_offload_enabled,
395 u32 n_rx_packets = 0;
405 if (type == VIRTIO_IF_TYPE_TUN)
422 u32 next0 = next_index;
426 while (n_left && n_left_to_next)
441 u8 l4_proto = 0, l4_hdr_sz = 0;
443 virtio_net_hdr_v1_t *hdr;
449 if (hdr_sz ==
sizeof (virtio_net_hdr_v1_t))
450 num_buffers = hdr->num_buffers;
452 b0->
flags = VLIB_BUFFER_TOTAL_LENGTH_VALID;
456 if (checksum_offload_enabled)
471 while (num_buffers > 1)
485 pb->
flags |= VLIB_BUFFER_NEXT_PRESENT;
498 if (type == VIRTIO_IF_TYPE_TUN)
500 switch (b0->
data[0] & 0xf0)
548 if (type == VIRTIO_IF_TYPE_TUN)
550 n_left_to_next, bi0, next0);
649 if (vif->
flags & VIRTIO_IF_FLAG_ADMIN_UP)
651 if (vif->
type == VIRTIO_IF_TYPE_TAP)
655 else if (vif->
type == VIRTIO_IF_TYPE_PCI)
659 else if (vif->
type == VIRTIO_IF_TYPE_TUN)
671 .name =
"virtio-input",
672 .sibling_of =
"device-input",
676 .state = VLIB_NODE_STATE_INTERRUPT,
u32 per_interface_next_index
gro_flow_table_t * flow_table
#define VRING_EVENT_F_DISABLE
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
vlib_node_registration_t virtio_input_node
(constructor) VLIB_REGISTER_NODE (virtio_input_node)
static uword vlib_buffer_get_current_pa(vlib_main_t *vm, vlib_buffer_t *b)
static_always_inline int clib_spinlock_trylock_if_init(clib_spinlock_t *p)
vring_desc_event_t * device_event
static __clib_warn_unused_result u32 vlib_buffer_alloc_to_ring_from_pool(vlib_main_t *vm, u32 *ring, u32 start, u32 ring_size, u32 n_buffers, u8 buffer_pool_index)
Allocate buffers into ring from specific buffer pool.
static_always_inline u16 virtio_get_slot_id(virtio_vring_t *vring, const int packed, u16 last, u16 mask)
static u32 vlib_get_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt)
vl_api_wireguard_peer_flags_t flags
static void vlib_increment_combined_counter(vlib_combined_counter_main_t *cm, u32 thread_index, u32 index, u64 n_packets, u64 n_bytes)
Increment a combined counter.
#define VIRTIO_NET_HDR_F_NEEDS_CSUM
vnet_main_t * vnet_get_main(void)
vnet_interface_main_t interface_main
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
#define CLIB_MEMORY_STORE_BARRIER()
static void vlib_error_count(vlib_main_t *vm, uword node_index, uword counter, uword increment)
#define clib_memcpy_fast(a, b, c)
vring_used_elem_t ring[0]
#define VLIB_NODE_FLAG_TRACE_SUPPORTED
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
static_always_inline u16 virtio_get_len(virtio_vring_t *vring, const int packed, const int hdr_sz, u16 last, u16 mask)
u16 current_length
Nbytes between current data and the end of this buffer.
static heap_elt_t * last(heap_header_t *h)
#define VLIB_NODE_FN(node)
static u8 * format_virtio_input_trace(u8 *s, va_list *args)
struct _tcp_header tcp_header_t
static_always_inline void virtio_refill_vring_split(vlib_main_t *vm, virtio_if_t *vif, virtio_if_type_t type, virtio_vring_t *vring, const int hdr_sz, u32 node_index)
#define foreach_virtio_input_error
#define static_always_inline
vlib_combined_counter_main_t * combined_sw_if_counters
description fragment has unexpected format
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static char * virtio_input_error_strings[]
vl_api_fib_path_type_t type
#define increment_last(last, packed, vring)
#define VRING_USED_F_NO_NOTIFY
static_always_inline uword virtio_device_input_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, virtio_if_t *vif, u16 qid, virtio_if_type_t type)
static __clib_warn_unused_result int vlib_trace_buffer(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, vlib_buffer_t *b, int follow_chain)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
static_always_inline void vnet_gro_flow_table_schedule_node_on_dispatcher(vlib_main_t *vm, gro_flow_table_t *flow_table)
u32 node_index
Node index.
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
#define VIRTIO_NET_HDR_GSO_TCPV4
static_always_inline u32 vlib_buffer_get_default_data_size(vlib_main_t *vm)
virtio_vring_t * rxq_vrings
#define VLIB_REGISTER_NODE(x,...)
static_always_inline void fill_gso_buffer_flags(vlib_buffer_t *b0, virtio_net_hdr_v1_t *hdr, u8 l4_proto, u8 l4_hdr_sz)
u32 current_config_index
Used by feature subgraph arcs to visit enabled feature nodes.
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
static_always_inline void virtio_vring_buffering_schedule_node_on_dispatcher(vlib_main_t *vm, virtio_vring_buffering_t *buffering)
static_always_inline u16 virtio_n_left_to_process(virtio_vring_t *vring, const int packed)
vlib_main_t vlib_node_runtime_t * node
vring_packed_desc_t * packed_desc
static_always_inline int ethernet_frame_is_tagged(u16 type)
static uword pointer_to_uword(const void *p)
virtio_main_t virtio_main
static_always_inline void virtio_needs_csum(vlib_buffer_t *b0, virtio_net_hdr_v1_t *hdr, u8 *l4_proto, u8 *l4_hdr_sz, virtio_if_type_t type)
virtio_vring_buffering_t * buffering
#define foreach_device_and_queue(var, vec)
u32 next_buffer
Next buffer for this linked-list of buffers.
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
VLIB buffer representation.
static_always_inline uword virtio_device_input_gso_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, virtio_if_t *vif, virtio_vring_t *vring, virtio_if_type_t type, int gso_enabled, int checksum_offload_enabled, int packed)
static_always_inline void vnet_feature_start_device_input_x1(u32 sw_if_index, u32 *next0, vlib_buffer_t *b0)
static int tcp_header_bytes(tcp_header_t *t)
#define VRING_DESC_F_USED
#define CLIB_MEMORY_BARRIER()
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
static int ip4_header_bytes(const ip4_header_t *i)
static void vlib_set_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt, u32 count)
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
#define VRING_DESC_F_WRITE
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
static_always_inline void virtio_refill_vring_packed(vlib_main_t *vm, virtio_if_t *vif, virtio_if_type_t type, virtio_vring_t *vring, const int hdr_sz, u32 node_index)
#define VIRTIO_NET_HDR_GSO_TCPV6
virtio_vring_t * txq_vrings
#define VRING_DESC_F_AVAIL
static_always_inline void virtio_kick(vlib_main_t *vm, virtio_vring_t *vring, virtio_if_t *vif)