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;
115 if (clib_net_to_host_u16 (eth->
type) == ETHERNET_TYPE_IP4)
119 b->
flags |= VNET_BUFFER_F_IS_IP4;
120 if (ip4->
protocol == IP_PROTOCOL_TCP)
122 b->
flags |= VNET_BUFFER_F_OFFLOAD_TCP_CKSUM;
128 else if (ip4->
protocol == IP_PROTOCOL_UDP)
130 b->
flags |= VNET_BUFFER_F_OFFLOAD_UDP_CKSUM;
140 else if (clib_net_to_host_u16 (eth->
type) == ETHERNET_TYPE_IP6)
144 b->
flags |= VNET_BUFFER_F_IS_IP6;
148 ip6_ext_header_t *p = (
void *) (ip6 + 1);
156 if (ip6->
protocol == IP_PROTOCOL_TCP)
158 b->
flags |= VNET_BUFFER_F_OFFLOAD_TCP_CKSUM;
163 else if (ip6->
protocol == IP_PROTOCOL_UDP)
165 b->
flags |= VNET_BUFFER_F_OFFLOAD_UDP_CKSUM;
181 struct tpacket2_hdr *tph;
186 u32 n_rx_packets = 0;
189 u32 block_size = apif->
rx_req->tp_block_size;
190 u32 frame_size = apif->
rx_req->tp_frame_size;
191 u32 frame_num = apif->
rx_req->tp_frame_nr;
192 u8 *block_start = apif->
rx_ring + block * block_size;
196 u32 min_bufs = apif->
rx_req->tp_frame_size / n_buffer_bytes;
206 _vec_len (apm->
rx_buffers[thread_index]) = n_free_bufs;
210 tph = (
struct tpacket2_hdr *) (block_start + rx_frame * frame_size);
211 while ((tph->tp_status & TP_STATUS_USER) && (n_free_bufs > min_bufs))
214 u32 next0 = next_index;
218 while ((tph->tp_status & TP_STATUS_USER) && (n_free_bufs > min_bufs) &&
221 u32 data_len = tph->tp_snaplen;
223 u32 bi0 = 0, first_bi0 = 0, prev_bi0;
228 u32 last_empty_buffer =
231 bi0 = apm->
rx_buffers[thread_index][last_empty_buffer];
233 _vec_len (apm->
rx_buffers[thread_index]) = last_empty_buffer;
238 data_len > n_buffer_bytes ? n_buffer_bytes : data_len;
240 u32 bytes_copied = 0;
248 (
u8 *) tph + tph->tp_mac,
254 clib_host_to_net_u16 (tph->tp_vlan_tci);
256 eth->
type = clib_host_to_net_u16 (ETHERNET_TYPE_VLAN);
262 bytes_copied + vlan_len,
263 (
u8 *) tph + tph->tp_mac + offset +
264 bytes_copied, (bytes_to_copy - bytes_copied));
272 b0->
flags = VLIB_BUFFER_TOTAL_LENGTH_VALID;
277 if (tph->tp_status & TP_STATUS_CSUMNOTREADY)
283 offset += bytes_to_copy;
284 data_len -= bytes_to_copy;
287 n_rx_bytes += tph->tp_snaplen;
288 to_next[0] = first_bi0;
297 node->
errors[AF_PACKET_INPUT_ERROR_PARTIAL_PKT];
327 n_left_to_next, first_bi0, next0);
330 tph->tp_status = TP_STATUS_KERNEL;
331 rx_frame = (rx_frame + 1) % frame_num;
332 tph = (
struct tpacket2_hdr *) (block_start + rx_frame * frame_size);
353 u32 n_rx_packets = 0;
371 .name =
"af-packet-input",
373 .sibling_of =
"device-input",
376 .state = VLIB_NODE_STATE_INTERRUPT,
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
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 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.
vnet_main_t * vnet_get_main(void)
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
#define clib_memcpy_fast(a, b, c)
#define VLIB_NODE_FLAG_TRACE_SUPPORTED
u16 current_length
Nbytes between current data and the end of this buffer.
static void * ip6_ext_next_header(ip6_ext_header_t *ext_hdr)
struct tpacket_req * rx_req
#define VLIB_NODE_FN(node)
vlib_node_registration_t af_packet_input_node
(constructor) VLIB_REGISTER_NODE (af_packet_input_node)
vlib_error_t * errors
Vector of errors for this node.
struct _tcp_header tcp_header_t
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 static_always_inline
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
#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_always_inline u32 vlib_buffer_get_default_data_size(vlib_main_t *vm)
#define VLIB_REGISTER_NODE(x,...)
static u8 * format_af_packet_input_trace(u8 *s, va_list *args)
static_always_inline uword vlib_get_thread_index(void)
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.
vlib_main_t vlib_node_runtime_t * node
static u8 ip6_ext_hdr(u8 nexthdr)
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)
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)
u32 next_buffer
Next buffer for this linked-list of buffers.
u8 * format_ethernet_vlan_tci(u8 *s, va_list *va)
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
VLIB buffer representation.
static_always_inline void vnet_feature_start_device_input_x1(u32 sw_if_index, u32 *next0, vlib_buffer_t *b0)
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
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.
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.