|
FD.io VPP
v21.10.1-2-g0a485f517
Vector Packet Processing
|
Go to the documentation of this file.
20 #include <linux/if_packet.h>
21 #include <sys/socket.h>
22 #include <sys/ioctl.h>
24 #include <net/if_arp.h>
33 #define foreach_af_packet_tx_func_error \
34 _(FRAME_NOT_READY, "tx frame not ready") \
35 _(TXRING_EAGAIN, "tx sendto temporary failure") \
36 _(TXRING_FATAL, "tx sendto fatal failure") \
37 _(TXRING_OVERRUN, "tx ring overrun")
41 #define _(f,s) AF_PACKET_TX_ERROR_##f,
54 #ifndef CLIB_MARCH_VARIANT
70 u32 dev_instance = va_arg (*args,
u32);
72 int __clib_unused verbose = va_arg (*args,
int);
78 u32 frame_size = apif->
tx_req->tp_frame_size;
79 u32 frame_num = apif->
tx_req->tp_frame_nr;
83 struct tpacket2_hdr *tph;
85 s =
format (s,
"Linux PACKET socket interface\n");
91 int n_send_req = 0, n_avail = 0, n_sending = 0, n_tot = 0, n_wrong = 0;
94 tph = (
struct tpacket2_hdr *) (block_start + tx_frame * frame_size);
95 tx_frame = (tx_frame + 1) % frame_num;
96 if (tph->tp_status == 0)
98 else if (tph->tp_status & TP_STATUS_SEND_REQUEST)
100 else if (tph->tp_status & TP_STATUS_SENDING)
107 s =
format (s,
"%Uavailable:%d request:%d sending:%d wrong:%d total:%d\n",
118 s =
format (s,
"Unimplemented...");
136 u32 frame_size = apif->tx_req->tp_frame_size;
137 u32 frame_num = apif->tx_req->tp_frame_nr;
139 u32 tx_frame = apif->next_tx_frame;
140 struct tpacket2_hdr *tph;
141 u32 frame_not_ready = 0;
152 tph = (
struct tpacket2_hdr *) (block_start + tx_frame * frame_size);
154 (TP_STATUS_SEND_REQUEST | TP_STATUS_SENDING)))
165 TPACKET_ALIGN (
sizeof (
struct tpacket2_hdr)) +
172 tph->tp_len = tph->tp_snaplen =
offset;
173 tph->tp_status = TP_STATUS_SEND_REQUEST;
176 tx_frame = (tx_frame + 1) % frame_num;
188 apif->next_tx_frame = tx_frame;
190 if (
PREDICT_FALSE (sendto (apif->fd, NULL, 0, MSG_DONTWAIT, NULL, 0) ==
199 AF_PACKET_TX_ERROR_TXRING_FATAL :
200 AF_PACKET_TX_ERROR_TXRING_EAGAIN,
209 AF_PACKET_TX_ERROR_FRAME_NOT_READY, frame_not_ready);
216 return frame->n_vectors;
255 int rv, fd = socket (AF_UNIX, SOCK_DGRAM, 0);
271 if ((
rv = ioctl (fd, SIOCGIFNAME, &ifr)) < 0)
274 "af_packet_%s ioctl could not retrieve eth name",
281 if ((
rv = ioctl (fd, SIOCGIFFLAGS, &ifr)) < 0)
291 ifr.ifr_flags |= IFF_UP;
296 ifr.ifr_flags &= ~IFF_UP;
299 if ((
rv = ioctl (fd, SIOCSIFFLAGS, &ifr)) < 0)
330 int rv, fd = socket (AF_UNIX, SOCK_DGRAM, 0);
346 if ((
rv = ioctl (fd, SIOCGIFNAME, &ifr)) < 0)
350 "af_packet_%s ioctl could not retrieve eth name, error: %d",
356 ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
358 if ((
rv = ioctl (fd, SIOCSIFHWADDR, &ifr)) < 0)
361 "af_packet_%s ioctl could not set mac, error: %d",
u32 next_buffer
Next buffer for this linked-list of buffers.
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
static clib_error_t * af_packet_set_mac_address_function(struct vnet_hw_interface_t *hi, const u8 *old_address, const u8 *address)
static clib_error_t * af_packet_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
struct tpacket_req * tx_req
vlib_node_registration_t af_packet_input_node
(constructor) VLIB_REGISTER_NODE (af_packet_input_node)
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
af_packet_main_t af_packet_main
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
#define clib_memcpy(d, s, n)
static_always_inline void clib_spinlock_lock_if_init(clib_spinlock_t *p)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static word unix_error_is_fatal(word error)
vlib_main_t vlib_node_runtime_t * node
VNET_DEVICE_CLASS(af_xdp_device_class)
#define vlib_log_warn(...)
@ VNET_SW_INTERFACE_FLAG_ADMIN_UP
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
u8 * format_af_packet_device_name(u8 *s, va_list *args)
@ VNET_HW_INTERFACE_FLAG_LINK_UP
static void vlib_error_count(vlib_main_t *vm, uword node_index, uword counter, uword increment)
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
#define VNET_DEVICE_CLASS_TX_FN(devclass)
VNET_DEVICE_CLASS_TX_FN() af_packet_device_class(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
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)
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
struct clib_bihash_value offset
template key/value backing page structure
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
vlib_log_class_t log_class
log class
af_packet_tx_func_error_t
static u8 * format_af_packet_device(u8 *s, va_list *args)
af_packet_if_t * interfaces
manual_print typedef address
static void af_packet_clear_hw_interface_counters(u32 instance)
#define CLIB_MEMORY_BARRIER()
u16 current_length
Nbytes between current data and the end of this buffer.
#define foreach_af_packet_tx_func_error
template key/value backing page structure
description fragment has unexpected format
static char * af_packet_tx_func_error_strings[]
static void af_packet_set_interface_next_node(vnet_main_t *vnm, u32 hw_if_index, u32 node_index)
static vlib_main_t * vlib_get_main(void)
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, vnet_hw_interface_flags_t flags)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
static u8 * format_af_packet_tx_trace(u8 *s, va_list *args)
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
u32 per_interface_next_index
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index,...
VLIB buffer representation.
vl_api_wireguard_peer_flags_t flags