|
FD.io VPP
v21.10.1-2-g0a485f517
Vector Packet Processing
|
Go to the documentation of this file.
20 #include <linux/if_packet.h>
32 #define foreach_af_packet_input_error \
33 _(PARTIAL_PKT, "partial packet")
37 #define _(f,s) AF_PACKET_INPUT_ERROR_##f,
54 struct tpacket2_hdr tph;
65 s =
format (s,
"af_packet: hw_if_index %d next-index %d",
70 "\n%Utpacket2_hdr:\n%Ustatus 0x%x len %u snaplen %u mac %u net %u"
71 "\n%Usec 0x%x nsec 0x%x vlan %U"
72 #ifdef TP_STATUS_VLAN_TPID_VALID
86 #ifdef TP_STATUS_VLAN_TPID_VALID
105 prev_b->
flags |= VLIB_BUFFER_NEXT_PRESENT;
114 b->
flags |= VNET_BUFFER_F_GSO;
124 if (clib_net_to_host_u16 (eth->
type) == ETHERNET_TYPE_IP4)
128 b->
flags |= VNET_BUFFER_F_IS_IP4;
129 if (
ip4->protocol == IP_PROTOCOL_TCP)
131 oflags |= VNET_BUFFER_OFFLOAD_F_TCP_CKSUM;
138 else if (
ip4->protocol == IP_PROTOCOL_UDP)
140 oflags |= VNET_BUFFER_OFFLOAD_F_UDP_CKSUM;
145 *l4_hdr_sz =
sizeof (*udp);
153 else if (clib_net_to_host_u16 (eth->
type) == ETHERNET_TYPE_IP6)
157 b->
flags |= VNET_BUFFER_F_IS_IP6;
161 ip6_ext_header_t *p = (
void *) (
ip6 + 1);
169 if (
ip6->protocol == IP_PROTOCOL_TCP)
171 oflags |= VNET_BUFFER_OFFLOAD_F_TCP_CKSUM;
178 else if (
ip6->protocol == IP_PROTOCOL_UDP)
180 oflags |= VNET_BUFFER_OFFLOAD_F_UDP_CKSUM;
185 *l4_hdr_sz =
sizeof (*udp);
200 struct tpacket2_hdr *tph;
205 u32 n_rx_packets = 0;
209 u32 frame_size = apif->
rx_req->tp_frame_size;
210 u32 frame_num = apif->
rx_req->tp_frame_nr;
215 u32 min_bufs = apif->
rx_req->tp_frame_size / n_buffer_bytes;
229 tph = (
struct tpacket2_hdr *) (block_start + rx_frame * frame_size);
230 while ((tph->tp_status & TP_STATUS_USER) && (n_free_bufs > min_bufs))
237 while ((tph->tp_status & TP_STATUS_USER) && (n_free_bufs > min_bufs) &&
242 u32 bi0 = 0, first_bi0 = 0, prev_bi0;
248 u32 last_empty_buffer =
260 u32 bytes_copied = 0;
268 (
u8 *) tph + tph->tp_mac,
274 clib_host_to_net_u16 (tph->tp_vlan_tci);
276 eth->
type = clib_host_to_net_u16 (ETHERNET_TYPE_VLAN);
282 bytes_copied + vlan_len,
284 bytes_copied, (bytes_to_copy - bytes_copied));
292 b0->
flags = VLIB_BUFFER_TOTAL_LENGTH_VALID;
297 if (tph->tp_status & TP_STATUS_CSUMNOTREADY)
299 if (tph->tp_snaplen > apif->
host_mtu)
310 n_rx_bytes += tph->tp_snaplen;
311 to_next[0] = first_bi0;
320 node->errors[AF_PACKET_INPUT_ERROR_PARTIAL_PKT];
349 n_left_to_next, first_bi0, next0);
352 tph->tp_status = TP_STATUS_KERNEL;
353 rx_frame = (rx_frame + 1) % frame_num;
354 tph = (
struct tpacket2_hdr *) (block_start + rx_frame * frame_size);
375 u32 n_rx_packets = 0;
392 .name =
"af-packet-input",
394 .sibling_of =
"device-input",
397 .state = VLIB_NODE_STATE_INTERRUPT,
static u8 * format_af_packet_input_trace(u8 *s, va_list *args)
u32 next_buffer
Next buffer for this linked-list of buffers.
static int tcp_header_bytes(tcp_header_t *t)
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
af_packet_main_t af_packet_main
static void buffer_add_to_chain(vlib_main_t *vm, u32 bi, u32 first_bi, u32 prev_bi)
#define foreach_af_packet_input_error
nat44_ei_hairpin_src_next_t next_index
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
struct _tcp_header tcp_header_t
@ AF_PACKET_INPUT_N_ERROR
@ VNET_DEVICE_INPUT_NEXT_DROP
#define ip6_ext_header_len(p)
vlib_main_t vlib_node_runtime_t * node
static_always_inline void vnet_buffer_offload_flags_set(vlib_buffer_t *b, vnet_buffer_oflags_t oflags)
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
static u32 vlib_get_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt)
@ VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
static_always_inline void fill_gso_buffer_flags(vlib_buffer_t *b, u32 gso_size, u8 l4_hdr_sz)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
struct tpacket_req * rx_req
#define VLIB_NODE_FN(node)
u8 * format_ethernet_vlan_tci(u8 *s, va_list *va)
static __clib_warn_unused_result u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
vnet_main_t * vnet_get_main(void)
vlib_node_registration_t af_packet_input_node
(constructor) VLIB_REGISTER_NODE (af_packet_input_node)
static_always_inline uword vlib_get_thread_index(void)
#define static_always_inline
af_packet_if_t * interfaces
#define VLIB_NODE_FLAG_TRACE_SUPPORTED
static uword af_packet_device_input_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, af_packet_if_t *apif)
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
@ VNET_INTERFACE_COUNTER_RX
static void vlib_set_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt, u32 count)
struct _vlib_node_registration vlib_node_registration_t
u16 current_length
Nbytes between current data and the end of this buffer.
#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.
template key/value backing page structure
description fragment has unexpected format
vlib_put_next_frame(vm, node, next_index, 0)
static_always_inline u32 vlib_buffer_get_default_data_size(vlib_main_t *vm)
static u8 ip6_ext_hdr(u8 nexthdr)
static_always_inline vnet_hw_if_rxq_poll_vector_t * vnet_hw_if_get_rxq_poll_vector(vlib_main_t *vm, vlib_node_runtime_t *node)
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
static_always_inline void mark_tcp_udp_cksum_calc(vlib_buffer_t *b, u8 *l4_hdr_sz)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
static_always_inline void vnet_feature_start_device_input_x1(u32 sw_if_index, u32 *next0, vlib_buffer_t *b0)
static int ip4_header_bytes(const ip4_header_t *i)
static void vnet_device_increment_rx_packets(u32 thread_index, u64 count)
static void * ip6_ext_next_header(ip6_ext_header_t *ext_hdr)
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)
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
#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).
u32 per_interface_next_index
vlib_increment_combined_counter(ccm, ti, sw_if_index, n_buffers, n_bytes)
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index,...
static char * af_packet_input_error_strings[]
VLIB buffer representation.
#define VLIB_REGISTER_NODE(x,...)