20 #include <linux/if_packet.h> 29 #define foreach_af_packet_tx_func_error \ 30 _(FRAME_NOT_READY, "tx frame not ready") 33 #define _(f,s) AF_PACKET_TX_ERROR_##f, 58 s =
format (s,
"Linux PACKET socket interface");
64 s =
format (s,
"Unimplemented...");
80 u32 block_size = apif->tx_req->tp_block_size;
81 u32 frame_size = apif->tx_req->tp_frame_size;
82 u32 frame_num = apif->tx_req->tp_frame_nr;
83 u8 * block_start = apif->tx_ring + block * block_size;
84 u32 tx_frame = apif->next_tx_frame;
85 struct tpacket2_hdr * tph;
86 u32 frame_not_ready = 0;
97 tph = (
struct tpacket2_hdr *) (block_start + tx_frame * frame_size);
99 if(tph->tp_status & (TP_STATUS_SEND_REQUEST | TP_STATUS_SENDING))
109 clib_memcpy((
u8 *) tph + TPACKET_ALIGN(
sizeof(
struct tpacket2_hdr)) + offset,
115 tph->tp_len = tph->tp_snaplen = offset;
116 tph->tp_status = TP_STATUS_SEND_REQUEST;
119 tx_frame = (tx_frame + 1) % frame_num;
126 apif->next_tx_frame = tx_frame;
127 if (sendto(apif->fd,
NULL, 0, MSG_DONTWAIT,
NULL, 0) == -1)
148 if (node_index == ~0)
205 .no_flatten_output_chains = 1,
static void af_packet_clear_hw_interface_counters(u32 instance)
always_inline void vlib_error_count(vlib_main_t *vm, uword node_index, uword counter, uword increment)
sll srl srl sll sra u16x4 i
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
static u8 * format_af_packet_tx_trace(u8 *s, va_list *args)
#define VNET_HW_INTERFACE_FLAG_LINK_UP
always_inline void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
always_inline vlib_main_t * vlib_get_main(void)
#define foreach_af_packet_tx_func_error
static u8 * format_af_packet_device(u8 *s, va_list *args)
VNET_DEVICE_CLASS(af_packet_device_class)
af_packet_if_t * interfaces
static uword af_packet_interface_tx(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static void af_packet_set_interface_next_node(vnet_main_t *vnm, u32 hw_if_index, u32 node_index)
#define pool_elt_at_index(p, i)
void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
u16 current_length
Nbytes between current data and the end of this buffer.
static clib_error_t * af_packet_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
static u8 * format_af_packet_device_name(u8 *s, va_list *args)
af_packet_tx_func_error_t
always_inline void * vlib_frame_args(vlib_frame_t *f)
static clib_error_t * af_packet_subif_add_del_function(vnet_main_t *vnm, u32 hw_if_index, struct vnet_sw_interface_t *st, int is_add)
#define clib_memcpy(a, b, c)
u32 per_interface_next_index
vlib_node_registration_t af_packet_input_node
(constructor) VLIB_REGISTER_NODE (af_packet_input_node)
always_inline vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
#define VNET_SW_INTERFACE_FLAG_ADMIN_UP
u32 next_buffer
Next buffer for this linked-list of buffers.
af_packet_main_t af_packet_main
#define clib_unix_error(format, args...)
always_inline uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
vnet_device_class_t af_packet_device_class
#define CLIB_MEMORY_BARRIER()
uword runtime_data[(128-1 *sizeof(vlib_node_function_t *)-1 *sizeof(vlib_error_t *)-11 *sizeof(u32)-5 *sizeof(u16))/sizeof(uword)]
always_inline vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
static char * af_packet_tx_func_error_strings[]