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
114 struct tpacket2_hdr *tph;
119 u32 n_rx_packets = 0;
122 u32 block_size = apif->
rx_req->tp_block_size;
123 u32 frame_size = apif->
rx_req->tp_frame_size;
124 u32 frame_num = apif->
rx_req->tp_frame_nr;
125 u8 *block_start = apif->
rx_ring + block * block_size;
130 u32 min_bufs = apif->
rx_req->tp_frame_size / n_buffer_bytes;
143 _vec_len (apm->
rx_buffers[thread_index]) = n_free_bufs;
147 tph = (
struct tpacket2_hdr *) (block_start + rx_frame * frame_size);
148 while ((tph->tp_status & TP_STATUS_USER) && (n_free_bufs > min_bufs))
151 u32 next0 = next_index;
155 while ((tph->tp_status & TP_STATUS_USER) && (n_free_bufs > min_bufs) &&
158 u32 data_len = tph->tp_snaplen;
160 u32 bi0 = 0, first_bi0 = 0, prev_bi0;
165 u32 last_empty_buffer =
168 bi0 = apm->
rx_buffers[thread_index][last_empty_buffer];
170 _vec_len (apm->
rx_buffers[thread_index]) = last_empty_buffer;
175 data_len > n_buffer_bytes ? n_buffer_bytes : data_len;
177 u32 bytes_copied = 0;
185 (
u8 *) tph + tph->tp_mac,
191 clib_host_to_net_u16 (tph->tp_vlan_tci);
193 eth->
type = clib_host_to_net_u16 (ETHERNET_TYPE_VLAN);
199 bytes_copied + vlan_len,
200 (
u8 *) tph + tph->tp_mac + offset + bytes_copied,
201 (bytes_to_copy - bytes_copied));
218 offset += bytes_to_copy;
219 data_len -= bytes_to_copy;
222 n_rx_bytes += tph->tp_snaplen;
223 to_next[0] = first_bi0;
246 n_left_to_next, first_bi0, next0);
249 tph->tp_status = TP_STATUS_KERNEL;
250 rx_frame = (rx_frame + 1) % frame_num;
251 tph = (
struct tpacket2_hdr *) (block_start + rx_frame * frame_size);
272 u32 n_rx_packets = 0;
291 .name =
"af-packet-input",
292 .sibling_of =
"device-input",
295 .state = VLIB_NODE_STATE_INTERRUPT,
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
static void vnet_device_increment_rx_packets(u32 thread_index, u64 count)
static u32 vlib_get_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt)
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.
u8 runtime_data[0]
Function dependent node-runtime data.
vnet_main_t * vnet_get_main(void)
struct tpacket_req * rx_req
vlib_node_registration_t af_packet_input_node
(constructor) VLIB_REGISTER_NODE (af_packet_input_node)
static uword af_packet_input_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
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
#define VLIB_BUFFER_NEXT_PRESENT
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
#define VLIB_BUFFER_TOTAL_LENGTH_VALID
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
u16 current_length
Nbytes between current data and the end of this buffer.
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
#define VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX
static u32 vlib_buffer_free_list_buffer_size(vlib_main_t *vm, u32 free_list_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).
static char * af_packet_input_error_strings[]
#define foreach_af_packet_input_error
static u8 * format_af_packet_input_trace(u8 *s, va_list *args)
static_always_inline uword vlib_get_thread_index(void)
#define clib_memcpy(a, b, c)
u32 per_interface_next_index
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.
u32 next_buffer
Next buffer for this linked-list of buffers.
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)
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)
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 foreach_device_and_queue(var, vec)
#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_BUFFER_TRACE_TRAJECTORY_INIT(b)
static_always_inline void vnet_feature_start_device_input_x1(u32 sw_if_index, u32 *next0, vlib_buffer_t *b0)
#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_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
static u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
VLIB_NODE_FUNCTION_MULTIARCH(ethernet_input_not_l2_node, ethernet_input_not_l2)