20 #include <linux/if_packet.h> 32 #define foreach_af_packet_input_error 36 #define _(f,s) AF_PACKET_INPUT_ERROR_##f, 53 struct tpacket2_hdr tph;
64 s =
format (s,
"af_packet: hw_if_index %d next-index %d",
69 "\n%Utpacket2_hdr:\n%Ustatus 0x%x len %u snaplen %u mac %u net %u" 70 "\n%Usec 0x%x nsec 0x%x vlan %U" 71 #ifdef TP_STATUS_VLAN_TPID_VALID
85 #ifdef TP_STATUS_VLAN_TPID_VALID
114 if (clib_net_to_host_u16 (eth->
type) == ETHERNET_TYPE_IP4)
118 b->
flags |= VNET_BUFFER_F_IS_IP4;
119 if (ip4->
protocol == IP_PROTOCOL_TCP)
121 b->
flags |= VNET_BUFFER_F_OFFLOAD_TCP_CKSUM;
127 else if (ip4->
protocol == IP_PROTOCOL_UDP)
129 b->
flags |= VNET_BUFFER_F_OFFLOAD_UDP_CKSUM;
139 else if (clib_net_to_host_u16 (eth->
type) == ETHERNET_TYPE_IP6)
143 b->
flags |= VNET_BUFFER_F_IS_IP6;
147 ip6_ext_header_t *p = (
void *) (ip6 + 1);
155 if (ip6->
protocol == IP_PROTOCOL_TCP)
157 b->
flags |= VNET_BUFFER_F_OFFLOAD_TCP_CKSUM;
162 else if (ip6->
protocol == IP_PROTOCOL_UDP)
164 b->
flags |= VNET_BUFFER_F_OFFLOAD_UDP_CKSUM;
180 struct tpacket2_hdr *tph;
185 u32 n_rx_packets = 0;
188 u32 block_size = apif->
rx_req->tp_block_size;
189 u32 frame_size = apif->
rx_req->tp_frame_size;
190 u32 frame_num = apif->
rx_req->tp_frame_nr;
191 u8 *block_start = apif->
rx_ring + block * block_size;
196 u32 min_bufs = apif->
rx_req->tp_frame_size / n_buffer_bytes;
209 _vec_len (apm->
rx_buffers[thread_index]) = n_free_bufs;
213 tph = (
struct tpacket2_hdr *) (block_start + rx_frame * frame_size);
214 while ((tph->tp_status & TP_STATUS_USER) && (n_free_bufs > min_bufs))
217 u32 next0 = next_index;
221 while ((tph->tp_status & TP_STATUS_USER) && (n_free_bufs > min_bufs) &&
224 u32 data_len = tph->tp_snaplen;
226 u32 bi0 = 0, first_bi0 = 0, prev_bi0;
231 u32 last_empty_buffer =
234 bi0 = apm->
rx_buffers[thread_index][last_empty_buffer];
236 _vec_len (apm->
rx_buffers[thread_index]) = last_empty_buffer;
241 data_len > n_buffer_bytes ? n_buffer_bytes : data_len;
243 u32 bytes_copied = 0;
251 (
u8 *) tph + tph->tp_mac,
257 clib_host_to_net_u16 (tph->tp_vlan_tci);
259 eth->
type = clib_host_to_net_u16 (ETHERNET_TYPE_VLAN);
265 bytes_copied + vlan_len,
266 (
u8 *) tph + tph->tp_mac + offset + bytes_copied,
267 (bytes_to_copy - bytes_copied));
280 if (tph->tp_status & TP_STATUS_CSUMNOTREADY)
286 offset += bytes_to_copy;
287 data_len -= bytes_to_copy;
290 n_rx_bytes += tph->tp_snaplen;
291 to_next[0] = first_bi0;
314 n_left_to_next, first_bi0, next0);
317 tph->tp_status = TP_STATUS_KERNEL;
318 rx_frame = (rx_frame + 1) % frame_num;
319 tph = (
struct tpacket2_hdr *) (block_start + rx_frame * frame_size);
340 u32 n_rx_packets = 0;
359 .name =
"af-packet-input",
360 .sibling_of =
"device-input",
363 .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_always_inline void mark_tcp_udp_cksum_calc(vlib_buffer_t *b)
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)
static int ip4_header_bytes(ip4_header_t *i)
static void * ip6_ext_next_header(ip6_ext_header_t *ext_hdr)
struct tpacket_req * rx_req
vlib_node_registration_t af_packet_input_node
(constructor) VLIB_REGISTER_NODE (af_packet_input_node)
struct _tcp_header tcp_header_t
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 static_always_inline
#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 ip6_ext_header_len(p)
#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.
static u8 ip6_ext_hdr(u8 nexthdr)
af_packet_main_t af_packet_main
u32 next_buffer
Next buffer for this linked-list of buffers.
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)