summaryrefslogtreecommitdiffstats
path: root/src/vnet/devices/af_packet/af_packet.c
diff options
context:
space:
mode:
authorNathan Skrzypczak <nathan.skrzypczak@gmail.com>2021-06-23 11:28:39 +0200
committerDamjan Marion <dmarion@me.com>2021-09-28 14:44:46 +0000
commit7d0e30bc642f9137188e962f3d1fe38303e674ba (patch)
treed9fd5caccf83b1180a50ba5de046bf455f7f27d9 /src/vnet/devices/af_packet/af_packet.c
parent1ae9819908ca2ba78c6fa0c0051bb1d4b2066be8 (diff)
devices: Add queues params in create_if
Type: feature Change-Id: I027ff2c5c905a7ccebd3705a58e35218a94f4880 Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
Diffstat (limited to 'src/vnet/devices/af_packet/af_packet.c')
-rw-r--r--src/vnet/devices/af_packet/af_packet.c77
1 files changed, 40 insertions, 37 deletions
diff --git a/src/vnet/devices/af_packet/af_packet.c b/src/vnet/devices/af_packet/af_packet.c
index cace3450e3e..2dc263046cb 100644
--- a/src/vnet/devices/af_packet/af_packet.c
+++ b/src/vnet/devices/af_packet/af_packet.c
@@ -38,21 +38,13 @@
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);
@@ -241,10 +233,10 @@ error:
}
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;
@@ -261,28 +253,41 @@ af_packet_create_if (vlib_main_t * vm, u8 * host_if_name, u8 * hw_addr_set,
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
@@ -297,13 +302,14 @@ af_packet_create_if (vlib_main_t * vm, u8 * host_if_name, u8 * hw_addr_set,
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;
}
@@ -342,7 +348,7 @@ af_packet_create_if (vlib_main_t * vm, u8 * host_if_name, u8 * hw_addr_set,
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;
@@ -370,8 +376,8 @@ af_packet_create_if (vlib_main_t * vm, u8 * host_if_name, u8 * hw_addr_set,
clib_spinlock_init (&apif->lockp);
/*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);
@@ -429,8 +435,7 @@ af_packet_create_if (vlib_main_t * vm, u8 * host_if_name, u8 * hw_addr_set,
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;
@@ -447,7 +452,7 @@ error:
}
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;
@@ -507,7 +512,7 @@ af_packet_delete_if (vlib_main_t * vm, u8 * host_if_name)
}
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;
@@ -538,7 +543,6 @@ af_packet_dump_ifs (af_packet_if_detail_t ** out_af_packet_ifs)
af_packet_if_detail_t *r_af_packet_ifs = NULL;
af_packet_if_detail_t *af_packet_if = NULL;
- /* *INDENT-OFF* */
pool_foreach (apif, apm->interfaces)
{
vec_add2 (r_af_packet_ifs, af_packet_if, 1);
@@ -550,7 +554,6 @@ af_packet_dump_ifs (af_packet_if_detail_t ** out_af_packet_ifs)
strlen ((const char *) apif->host_if_name)));
}
}
- /* *INDENT-ON* */
*out_af_packet_ifs = r_af_packet_ifs;