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;
197 u32 min_bufs = apif->
rx_req->tp_frame_size / n_buffer_bytes;
210 _vec_len (apm->
rx_buffers[thread_index]) = n_free_bufs;
214 tph = (
struct tpacket2_hdr *) (block_start + rx_frame * frame_size);
215 while ((tph->tp_status & TP_STATUS_USER) && (n_free_bufs > min_bufs))
218 u32 next0 = next_index;
222 while ((tph->tp_status & TP_STATUS_USER) && (n_free_bufs > min_bufs) &&
225 u32 data_len = tph->tp_snaplen;
227 u32 bi0 = 0, first_bi0 = 0, prev_bi0;
232 u32 last_empty_buffer =
235 bi0 = apm->
rx_buffers[thread_index][last_empty_buffer];
237 _vec_len (apm->
rx_buffers[thread_index]) = last_empty_buffer;
242 data_len > n_buffer_bytes ? n_buffer_bytes : data_len;
244 u32 bytes_copied = 0;
252 (
u8 *) tph + tph->tp_mac,
258 clib_host_to_net_u16 (tph->tp_vlan_tci);
260 eth->
type = clib_host_to_net_u16 (ETHERNET_TYPE_VLAN);
266 bytes_copied + vlan_len,
267 (
u8 *) tph + tph->tp_mac + offset + bytes_copied,
268 (bytes_to_copy - bytes_copied));
276 b0->
flags = VLIB_BUFFER_TOTAL_LENGTH_VALID;
281 if (tph->tp_status & TP_STATUS_CSUMNOTREADY)
287 offset += bytes_to_copy;
288 data_len -= bytes_to_copy;
291 n_rx_bytes += tph->tp_snaplen;
292 to_next[0] = first_bi0;
301 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;
372 .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) ...
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 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)
vlib_error_t * errors
Vector of errors for this 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
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
#define static_always_inline
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define VLIB_NODE_FUNCTION_MULTIARCH(node, fn)
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
#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
#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)
#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 u32 vlib_buffer_free_list_buffer_size(vlib_main_t *vm, vlib_buffer_free_list_index_t index)
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 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.