#include <vlib/vlib.h>
#include <vlib/unix/unix.h>
#include <vnet/ip/ip.h>
+#include <vnet/devices/netlink.h>
#include <vnet/ethernet/ethernet.h>
+#include <vnet/interface/rx_queue_funcs.h>
#include <vnet/devices/af_packet/af_packet.h>
af_packet_main_t af_packet_main;
-#define AF_PACKET_TX_FRAMES_PER_BLOCK 1024
-#define AF_PACKET_TX_FRAME_SIZE (2048 * 5)
+#define AF_PACKET_DEFAULT_TX_FRAMES_PER_BLOCK 1024
+#define AF_PACKET_DEFAULT_TX_FRAME_SIZE (2048 * 5)
#define AF_PACKET_TX_BLOCK_NR 1
-#define AF_PACKET_TX_FRAME_NR (AF_PACKET_TX_BLOCK_NR * \
- AF_PACKET_TX_FRAMES_PER_BLOCK)
-#define AF_PACKET_TX_BLOCK_SIZE (AF_PACKET_TX_FRAME_SIZE * \
- AF_PACKET_TX_FRAMES_PER_BLOCK)
-#define AF_PACKET_RX_FRAMES_PER_BLOCK 1024
-#define AF_PACKET_RX_FRAME_SIZE (2048 * 5)
+#define AF_PACKET_DEFAULT_RX_FRAMES_PER_BLOCK 1024
+#define AF_PACKET_DEFAULT_RX_FRAME_SIZE (2048 * 5)
#define AF_PACKET_RX_BLOCK_NR 1
-#define AF_PACKET_RX_FRAME_NR (AF_PACKET_RX_BLOCK_NR * \
- AF_PACKET_RX_FRAMES_PER_BLOCK)
-#define AF_PACKET_RX_BLOCK_SIZE (AF_PACKET_RX_FRAME_SIZE * \
- AF_PACKET_RX_FRAMES_PER_BLOCK)
/*defined in net/if.h but clashes with dpdk headers */
unsigned int if_nametoindex (const char *ifname);
u32 flags)
{
clib_error_t *error;
- u8 *s;
af_packet_main_t *apm = &af_packet_main;
af_packet_if_t *apif =
pool_elt_at_index (apm->interfaces, hi->dev_instance);
- if (ETHERNET_INTERFACE_FLAG_MTU == (flags & ETHERNET_INTERFACE_FLAG_MTU))
+ if (flags == ETHERNET_INTERFACE_FLAG_MTU)
{
- s = format (0, "/sys/class/net/%s/mtu%c", apif->host_if_name, 0);
-
- error = clib_sysfs_write ((char *) s, "%d", hi->max_packet_bytes);
- vec_free (s);
+ error =
+ vnet_netlink_set_link_mtu (apif->host_if_index, hi->max_packet_bytes);
if (error)
{
- vlib_log_err (apm->log_class,
- "sysfs write failed to change MTU: %U",
+ vlib_log_err (apm->log_class, "netlink failed to change MTU: %U",
format_clib_error, error);
clib_error_free (error);
return VNET_API_ERROR_SYSCALL_ERROR_1;
}
+ else
+ apif->host_mtu = hi->max_packet_bytes;
}
return 0;
}
+static int
+af_packet_read_mtu (af_packet_if_t *apif)
+{
+ af_packet_main_t *apm = &af_packet_main;
+ clib_error_t *error;
+ error = vnet_netlink_get_link_mtu (apif->host_if_index, &apif->host_mtu);
+ if (error)
+ {
+ vlib_log_err (apm->log_class, "netlink failed to get MTU: %U",
+ format_clib_error, error);
+ clib_error_free (error);
+ return VNET_API_ERROR_SYSCALL_ERROR_1;
+ }
+ return 0;
+}
+
static clib_error_t *
af_packet_fd_read_ready (clib_file_t * uf)
{
clib_bitmap_set (apm->pending_input_bitmap, idx, 1);
/* Schedule the rx node */
- vnet_device_input_set_interrupt_pending (vnm, apif->hw_if_index, 0);
-
+ vnet_hw_if_rx_queue_set_int_pending (vnm, apif->queue_index);
return 0;
}
goto error;
}
+ if (setsockopt (*fd, SOL_PACKET, PACKET_QDISC_BYPASS, &opt, sizeof (opt)) <
+ 0)
+ {
+ vlib_log_debug (apm->log_class,
+ "Failed to set qdisc bypass error "
+ "handling option: %s (errno %d)",
+ strerror (errno), errno);
+ }
+
if (setsockopt (*fd, SOL_PACKET, PACKET_RX_RING, rx_req, req_sz) < 0)
{
vlib_log_debug (apm->log_class,
}
int
-af_packet_create_if (vlib_main_t * vm, u8 * host_if_name, u8 * hw_addr_set,
- u32 * sw_if_index)
+af_packet_create_if (af_packet_create_if_arg_t *arg)
{
af_packet_main_t *apm = &af_packet_main;
+ vlib_main_t *vm = vlib_get_main ();
int ret, fd = -1, fd2 = -1;
struct tpacket_req *rx_req = 0;
struct tpacket_req *tx_req = 0;
uword if_index;
u8 *host_if_name_dup = 0;
int host_if_index = -1;
+ u32 rx_frames_per_block, tx_frames_per_block;
+ u32 rx_frame_size, tx_frame_size;
- p = mhash_get (&apm->if_index_by_host_if_name, host_if_name);
+ p = mhash_get (&apm->if_index_by_host_if_name, arg->host_if_name);
if (p)
{
apif = vec_elt_at_index (apm->interfaces, p[0]);
- *sw_if_index = apif->sw_if_index;
+ arg->sw_if_index = apif->sw_if_index;
return VNET_API_ERROR_IF_ALREADY_EXISTS;
}
- host_if_name_dup = vec_dup (host_if_name);
+ host_if_name_dup = vec_dup (arg->host_if_name);
+
+ rx_frames_per_block = arg->rx_frames_per_block ?
+ arg->rx_frames_per_block :
+ AF_PACKET_DEFAULT_RX_FRAMES_PER_BLOCK;
+ tx_frames_per_block = arg->tx_frames_per_block ?
+ arg->tx_frames_per_block :
+ AF_PACKET_DEFAULT_TX_FRAMES_PER_BLOCK;
+ rx_frame_size =
+ arg->rx_frame_size ? arg->rx_frame_size : AF_PACKET_DEFAULT_RX_FRAME_SIZE;
+ tx_frame_size =
+ arg->tx_frame_size ? arg->tx_frame_size : AF_PACKET_DEFAULT_TX_FRAME_SIZE;
vec_validate (rx_req, 0);
- rx_req->tp_block_size = AF_PACKET_RX_BLOCK_SIZE;
- rx_req->tp_frame_size = AF_PACKET_RX_FRAME_SIZE;
+ rx_req->tp_block_size = rx_frame_size * rx_frames_per_block;
+ rx_req->tp_frame_size = rx_frame_size;
rx_req->tp_block_nr = AF_PACKET_RX_BLOCK_NR;
- rx_req->tp_frame_nr = AF_PACKET_RX_FRAME_NR;
+ rx_req->tp_frame_nr = AF_PACKET_RX_BLOCK_NR * rx_frames_per_block;
vec_validate (tx_req, 0);
- tx_req->tp_block_size = AF_PACKET_TX_BLOCK_SIZE;
- tx_req->tp_frame_size = AF_PACKET_TX_FRAME_SIZE;
+ tx_req->tp_block_size = tx_frame_size * tx_frames_per_block;
+ tx_req->tp_frame_size = tx_frame_size;
tx_req->tp_block_nr = AF_PACKET_TX_BLOCK_NR;
- tx_req->tp_frame_nr = AF_PACKET_TX_FRAME_NR;
+ tx_req->tp_frame_nr = AF_PACKET_TX_BLOCK_NR * tx_frames_per_block;
/*
* make sure host side of interface is 'UP' before binding AF_PACKET
goto error;
}
- clib_memcpy (ifr.ifr_name, (const char *) host_if_name,
- vec_len (host_if_name));
+ clib_memcpy (ifr.ifr_name, (const char *) arg->host_if_name,
+ vec_len (arg->host_if_name));
if (ioctl (fd2, SIOCGIFINDEX, &ifr) < 0)
{
- vlib_log_debug (apm->log_class,
- "Failed to retrieve the interface (%s) index: %s (errno %d)",
- host_if_name, strerror (errno), errno);
+ vlib_log_debug (
+ apm->log_class,
+ "Failed to retrieve the interface (%s) index: %s (errno %d)",
+ arg->host_if_name, strerror (errno), errno);
ret = VNET_API_ERROR_INVALID_INTERFACE;
goto error;
}
if (ret != 0)
goto error;
- ret = is_bridge (host_if_name);
+ ret = is_bridge (arg->host_if_name);
if (ret == 0) /* is a bridge, ignore state */
host_if_index = -1;
apif->next_tx_frame = 0;
apif->next_rx_frame = 0;
+ ret = af_packet_read_mtu (apif);
+ if (ret != 0)
+ goto error;
+
if (tm->n_vlib_mains > 1)
clib_spinlock_init (&apif->lockp);
- {
- clib_file_t template = { 0 };
- template.read_function = af_packet_fd_read_ready;
- template.file_descriptor = fd;
- template.private_data = if_index;
- template.flags = UNIX_FILE_EVENT_EDGE_TRIGGERED;
- template.description = format (0, "%U", format_af_packet_device_name,
- if_index);
- apif->clib_file_index = clib_file_add (&file_main, &template);
- }
-
/*use configured or generate random MAC address */
- if (hw_addr_set)
- clib_memcpy (hw_addr, hw_addr_set, 6);
+ if (arg->hw_addr)
+ clib_memcpy (hw_addr, arg->hw_addr, 6);
else
{
f64 now = vlib_time_now (vm);
sw = vnet_get_hw_sw_interface (vnm, apif->hw_if_index);
hw = vnet_get_hw_interface (vnm, apif->hw_if_index);
apif->sw_if_index = sw->sw_if_index;
- vnet_hw_interface_set_input_node (vnm, apif->hw_if_index,
- af_packet_input_node.index);
-
- vnet_hw_interface_assign_rx_thread (vnm, apif->hw_if_index, 0, /* queue */
- ~0 /* any cpu */ );
+ vnet_hw_if_set_input_node (vnm, apif->hw_if_index,
+ af_packet_input_node.index);
+ apif->queue_index = vnet_hw_if_register_rx_queue (vnm, apif->hw_if_index, 0,
+ VNET_HW_IF_RXQ_THREAD_ANY);
- hw->flags |= VNET_HW_INTERFACE_FLAG_SUPPORTS_INT_MODE;
+ hw->caps |= VNET_HW_INTERFACE_CAP_SUPPORTS_INT_MODE;
vnet_hw_interface_set_flags (vnm, apif->hw_if_index,
VNET_HW_INTERFACE_FLAG_LINK_UP);
- vnet_hw_interface_set_rx_mode (vnm, apif->hw_if_index, 0,
- VNET_HW_INTERFACE_RX_MODE_INTERRUPT);
+ vnet_hw_if_set_rx_queue_mode (vnm, apif->queue_index,
+ VNET_HW_IF_RX_MODE_INTERRUPT);
+ vnet_hw_if_update_runtime_data (vnm, apif->hw_if_index);
+ {
+ clib_file_t template = { 0 };
+ template.read_function = af_packet_fd_read_ready;
+ template.file_descriptor = fd;
+ template.private_data = if_index;
+ template.flags = UNIX_FILE_EVENT_EDGE_TRIGGERED;
+ template.description =
+ format (0, "%U", format_af_packet_device_name, if_index);
+ apif->clib_file_index = clib_file_add (&file_main, &template);
+ }
+ vnet_hw_if_set_rx_queue_file_index (vnm, apif->queue_index,
+ apif->clib_file_index);
mhash_set_mem (&apm->if_index_by_host_if_name, host_if_name_dup, &if_index,
0);
- if (sw_if_index)
- *sw_if_index = apif->sw_if_index;
+ arg->sw_if_index = apif->sw_if_index;
return 0;
}
int
-af_packet_delete_if (vlib_main_t * vm, u8 * host_if_name)
+af_packet_delete_if (u8 *host_if_name)
{
vnet_main_t *vnm = vnet_get_main ();
af_packet_main_t *apm = &af_packet_main;
/* bring down the interface */
vnet_hw_interface_set_flags (vnm, apif->hw_if_index, 0);
- vnet_hw_interface_unassign_rx_thread (vnm, apif->hw_if_index, 0);
/* clean up */
if (apif->clib_file_index != ~0)
}
int
-af_packet_set_l4_cksum_offload (vlib_main_t * vm, u32 sw_if_index, u8 set)
+af_packet_set_l4_cksum_offload (u32 sw_if_index, u8 set)
{
vnet_main_t *vnm = vnet_get_main ();
vnet_hw_interface_t *hw;
return VNET_API_ERROR_INVALID_INTERFACE;
if (set)
- hw->flags &= ~VNET_HW_INTERFACE_FLAG_SUPPORTS_TX_L4_CKSUM_OFFLOAD;
+ {
+ hw->caps &= ~(VNET_HW_INTERFACE_CAP_SUPPORTS_TX_TCP_CKSUM |
+ VNET_HW_INTERFACE_CAP_SUPPORTS_TX_UDP_CKSUM);
+ }
else
- hw->flags |= VNET_HW_INTERFACE_FLAG_SUPPORTS_TX_L4_CKSUM_OFFLOAD;
-
+ {
+ hw->caps |= (VNET_HW_INTERFACE_CAP_SUPPORTS_TX_TCP_CKSUM |
+ VNET_HW_INTERFACE_CAP_SUPPORTS_TX_UDP_CKSUM);
+ }
return 0;
}
af_packet_if_detail_t *r_af_packet_ifs = NULL;
af_packet_if_detail_t *af_packet_if = NULL;
- vec_foreach (apif, apm->interfaces)
- {
- vec_add2 (r_af_packet_ifs, af_packet_if, 1);
- af_packet_if->sw_if_index = apif->sw_if_index;
- if (apif->host_if_name)
- {
- clib_memcpy (af_packet_if->host_if_name, apif->host_if_name,
- MIN (ARRAY_LEN (af_packet_if->host_if_name) - 1,
- strlen ((const char *) apif->host_if_name)));
- }
- }
+ pool_foreach (apif, apm->interfaces)
+ {
+ vec_add2 (r_af_packet_ifs, af_packet_if, 1);
+ af_packet_if->sw_if_index = apif->sw_if_index;
+ if (apif->host_if_name)
+ {
+ clib_memcpy (af_packet_if->host_if_name, apif->host_if_name,
+ MIN (ARRAY_LEN (af_packet_if->host_if_name) - 1,
+ strlen ((const char *) apif->host_if_name)));
+ }
+ }
*out_af_packet_ifs = r_af_packet_ifs;