20 #include <linux/if_packet.h> 31 #define foreach_af_packet_input_error 35 #define _(f,s) AF_PACKET_INPUT_ERROR_##f, 52 struct tpacket2_hdr tph;
63 s =
format (s,
"af_packet: hw_if_index %d next-index %d",
68 "\n%Utpacket2_hdr:\n%Ustatus 0x%x len %u snaplen %u mac %u net %u" 69 "\n%Usec 0x%x nsec 0x%x vlan %U" 70 #ifdef TP_STATUS_VLAN_TPID_VALID
84 #ifdef TP_STATUS_VLAN_TPID_VALID
115 struct tpacket2_hdr *tph;
120 u32 n_rx_packets = 0;
123 u32 block_size = apif->
rx_req->tp_block_size;
124 u32 frame_size = apif->
rx_req->tp_frame_size;
125 u32 frame_num = apif->
rx_req->tp_frame_nr;
126 u8 *block_start = apif->
rx_ring + block * block_size;
130 u32 min_bufs = apif->
rx_req->tp_frame_size / n_buffer_bytes;
144 _vec_len (apm->
rx_buffers[cpu_index]) = n_free_bufs;
148 tph = (
struct tpacket2_hdr *) (block_start + rx_frame * frame_size);
149 while ((tph->tp_status & TP_STATUS_USER) && (n_free_bufs > min_bufs))
152 u32 next0 = next_index;
156 while ((tph->tp_status & TP_STATUS_USER) && (n_free_bufs > min_bufs) &&
159 u32 data_len = tph->tp_snaplen;
161 u32 bi0 = 0, first_bi0 = 0, prev_bi0;
166 u32 last_empty_buffer =
169 bi0 = apm->
rx_buffers[cpu_index][last_empty_buffer];
171 _vec_len (apm->
rx_buffers[cpu_index]) = last_empty_buffer;
176 data_len > n_buffer_bytes ? n_buffer_bytes : data_len;
179 (
u8 *) tph + tph->tp_mac + offset, bytes_to_copy);
196 offset += bytes_to_copy;
197 data_len -= bytes_to_copy;
200 n_rx_bytes += tph->tp_snaplen;
201 to_next[0] = first_bi0;
225 n_left_to_next, first_bi0, next0);
228 tph->tp_status = TP_STATUS_KERNEL;
229 rx_frame = (rx_frame + 1) % frame_num;
230 tph = (
struct tpacket2_hdr *) (block_start + rx_frame * frame_size);
251 u32 n_rx_packets = 0;
258 clib_bitmap_set (apm->pending_input_bitmap, i, 0);
259 n_rx_packets += af_packet_device_input_fn(vm, node, frame, i);
269 .name =
"af-packet-input",
270 .sibling_of =
"device-input",
273 .state = VLIB_NODE_STATE_INTERRUPT,
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
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.
sll srl srl sll sra u16x4 i
static u32 vlib_get_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt)
uword * pending_input_bitmap
static uword af_packet_device_input_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, u32 device_idx)
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
static uword af_packet_input_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static_always_inline void vnet_feature_start_device_input_x1(u32 sw_if_index, u32 *next0, vlib_buffer_t *b0, u16 buffer_advanced0)
struct tpacket_req * rx_req
#define foreach_af_packet_input_error
static void vlib_trace_buffer(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, vlib_buffer_t *b, int follow_chain)
af_packet_if_t * interfaces
vnet_main_t * vnet_get_main(void)
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
#define VLIB_BUFFER_NEXT_PRESENT
#define clib_bitmap_foreach(i, ai, body)
Macro to iterate across set bits in a bitmap.
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
u16 current_length
Nbytes between current data and the end of this buffer.
uword os_get_cpu_number(void)
static char * af_packet_input_error_strings[]
static u32 vlib_buffer_free_list_buffer_size(vlib_main_t *vm, u32 free_list_index)
vlib_node_registration_t af_packet_input_node
(constructor) VLIB_REGISTER_NODE (af_packet_input_node)
#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 clib_memcpy(a, b, c)
#define VLIB_BUFFER_TOTAL_LENGTH_VALID
u32 per_interface_next_index
#define VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX
static void vlib_increment_combined_counter(vlib_combined_counter_main_t *cm, u32 cpu_index, u32 index, u32 packet_increment, u32 byte_increment)
Increment a combined counter.
VLIB_NODE_FUNCTION_MULTIARCH(dpdk_input_node, dpdk_input)
u32 next_buffer
Next buffer for this linked-list of buffers.
af_packet_main_t af_packet_main
u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
template key/value backing page structure
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u8 * format_ethernet_vlan_tci(u8 *s, va_list *va)
#define VLIB_REGISTER_NODE(x,...)
static void vlib_set_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt, u32 count)
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
static void buffer_add_to_chain(vlib_main_t *vm, u32 bi, u32 first_bi, u32 prev_bi)
static u8 * format_af_packet_input_trace(u8 *s, va_list *args)