summaryrefslogtreecommitdiffstats
path: root/src/plugins/memif/memif_api.c
diff options
context:
space:
mode:
authorJon Loeliger <jdl@netgate.com>2018-01-16 16:37:16 -0600
committerDamjan Marion <damarion@cisco.com>2018-01-29 13:09:57 +0100
commit30349b075cf939549980f2a32e030b32f6d07e9a (patch)
treeebf4a6e10c49cd9657cefeadafbaa44f07c5c021 /src/plugins/memif/memif_api.c
parentb4d43d7901b49bdda4345adb86b4d15a5d72f7ff (diff)
memif: Add new API calls to manage memif socket names.
New API calls and corresponding CLI commands allow the user to manage the socket filenames for memif connections using: vppctl# create memif id <u32> filename <socket-filename> vppctl# delete memif id <u32> and then referencing it later in a memif interface: vppctl# create memif <u32> socket-id <id> mode <mode> <master|slave> ... Corresponding VAT cli entries have also been added. The default memif socket file at id 0 are still always present. The existing memif create/delete CLI commands have been slightly altered into the new syntax: vppctl# create interface memif ... vppctl# delete interface memif ... Change-Id: If2bdc7eac3d81e1d9011a5869747e52fc5e11639 Signed-off-by: Jon Loeliger <jdl@netgate.com> Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/plugins/memif/memif_api.c')
-rw-r--r--src/plugins/memif/memif_api.c144
1 files changed, 118 insertions, 26 deletions
diff --git a/src/plugins/memif/memif_api.c b/src/plugins/memif/memif_api.c
index f9f74ccdcb3..a48cd188f04 100644
--- a/src/plugins/memif/memif_api.c
+++ b/src/plugins/memif/memif_api.c
@@ -88,10 +88,59 @@ do { \
vl_msg_api_send_shmem (q, (u8 *)&rmp); \
} while(0);
-#define foreach_memif_plugin_api_msg \
-_(MEMIF_CREATE, memif_create) \
-_(MEMIF_DELETE, memif_delete) \
-_(MEMIF_DUMP, memif_dump) \
+#define foreach_memif_plugin_api_msg \
+_(MEMIF_SOCKET_FILENAME_ADD_DEL, memif_socket_filename_add_del) \
+_(MEMIF_CREATE, memif_create) \
+_(MEMIF_DELETE, memif_delete) \
+_(MEMIF_SOCKET_FILENAME_DUMP, memif_socket_filename_dump) \
+_(MEMIF_DUMP, memif_dump) \
+
+
+/**
+ * @brief Message handler for memif_socket_filename_add_del API.
+ * @param mp the vl_api_memif_socket_filename_add_del_t API message
+ */
+void
+ vl_api_memif_socket_filename_add_del_t_handler
+ (vl_api_memif_socket_filename_add_del_t * mp)
+{
+ memif_main_t *mm = &memif_main;
+ u8 is_add;
+ u32 socket_id;
+ u32 len;
+ u8 *socket_filename;
+ vl_api_memif_socket_filename_add_del_reply_t *rmp;
+ int rv;
+
+ /* is_add */
+ is_add = mp->is_add;
+
+ /* socket_id */
+ socket_id = clib_net_to_host_u32 (mp->socket_id);
+ if (socket_id == 0 || socket_id == ~0)
+ {
+ rv = VNET_API_ERROR_INVALID_ARGUMENT;
+ goto reply;
+ }
+
+ /* socket filename */
+ socket_filename = 0;
+ mp->socket_filename[ARRAY_LEN (mp->socket_filename) - 1] = 0;
+ len = strlen ((char *) mp->socket_filename);
+ if (len > 0)
+ {
+ vec_validate (socket_filename, len);
+ strncpy ((char *) socket_filename, (char *) mp->socket_filename, len);
+ }
+
+ rv = memif_socket_filename_add_del (is_add, socket_id, socket_filename);
+
+ vec_free (socket_filename);
+
+reply:
+ REPLY_MACRO (VL_API_MEMIF_SOCKET_FILENAME_ADD_DEL_REPLY);
+}
+
/**
* @brief Message handler for memif_create API.
@@ -111,15 +160,8 @@ vl_api_memif_create_t_handler (vl_api_memif_create_t * mp)
/* id */
args.id = clib_net_to_host_u32 (mp->id);
- /* socket filename */
- mp->socket_filename[ARRAY_LEN (mp->socket_filename) - 1] = 0;
- if (strlen ((char *) mp->socket_filename) > 0)
- {
- vec_validate (args.socket_filename,
- strlen ((char *) mp->socket_filename));
- strncpy ((char *) args.socket_filename, (char *) mp->socket_filename,
- vec_len (args.socket_filename));
- }
+ /* socket-id */
+ args.socket_id = clib_net_to_host_u32 (mp->socket_id);
/* secret */
mp->secret[ARRAY_LEN (mp->secret) - 1] = 0;
@@ -179,16 +221,10 @@ vl_api_memif_create_t_handler (vl_api_memif_create_t * mp)
rv = memif_create_if (vm, &args);
- vec_free (args.socket_filename);
vec_free (args.secret);
reply:
- /* *INDENT-OFF* */
- REPLY_MACRO2 (VL_API_MEMIF_CREATE_REPLY,
- ({
- rmp->sw_if_index = htonl (args.sw_if_index);
- }));
- /* *INDENT-ON* */
+ REPLY_MACRO (VL_API_MEMIF_CREATE_REPLY);
}
/**
@@ -227,9 +263,8 @@ send_memif_details (vl_api_registration_t * reg,
vl_api_memif_details_t *mp;
vnet_main_t *vnm = vnet_get_main ();
memif_main_t *mm = &memif_main;
- memif_socket_file_t *msf = vec_elt_at_index (mm->socket_files,
- mif->socket_file_index);
vnet_hw_interface_t *hwif;
+ memif_socket_file_t *msf;
hwif = vnet_get_sup_hw_interface (vnm, swif->sw_if_index);
@@ -242,13 +277,18 @@ send_memif_details (vl_api_registration_t * reg,
mp->sw_if_index = htonl (swif->sw_if_index);
strncpy ((char *) mp->if_name,
(char *) interface_name, ARRAY_LEN (mp->if_name) - 1);
- memcpy (mp->hw_addr, hwif->hw_address, ARRAY_LEN (mp->hw_addr));
+
+ if (hwif->hw_address)
+ {
+ memcpy (mp->hw_addr, hwif->hw_address, ARRAY_LEN (mp->hw_addr));
+ }
mp->id = clib_host_to_net_u32 (mif->id);
- mp->role = (mif->flags & MEMIF_IF_FLAG_IS_SLAVE) ? 1 : 0;
- strncpy ((char *) mp->socket_filename,
- (char *) msf->filename, ARRAY_LEN (mp->socket_filename) - 1);
+ msf = pool_elt_at_index (mm->socket_files, mif->socket_file_index);
+ mp->socket_id = clib_host_to_net_u32 (msf->socket_id);
+
+ mp->role = (mif->flags & MEMIF_IF_FLAG_IS_SLAVE) ? 1 : 0;
mp->ring_size = htonl (1 << mif->run.log2_ring_size);
mp->buffer_size = htons (mif->run.buffer_size);
@@ -293,6 +333,58 @@ vl_api_memif_dump_t_handler (vl_api_memif_dump_t * mp)
vec_free (if_name);
}
+static void
+send_memif_socket_filename_details (vl_api_registration_t * reg,
+ u32 socket_id,
+ u8 * socket_filename, u32 context)
+{
+ vl_api_memif_socket_filename_details_t *mp;
+ memif_main_t *mm = &memif_main;
+
+ mp = vl_msg_api_alloc (sizeof (*mp));
+ memset (mp, 0, sizeof (*mp));
+
+ mp->_vl_msg_id = htons (VL_API_MEMIF_SOCKET_FILENAME_DETAILS
+ + mm->msg_id_base);
+ mp->context = context;
+
+ mp->socket_id = clib_host_to_net_u32 (socket_id);
+ strncpy ((char *) mp->socket_filename,
+ (char *) socket_filename, ARRAY_LEN (mp->socket_filename) - 1);
+
+ vl_api_send_msg (reg, (u8 *) mp);
+}
+
+/**
+ * @brief Message handler for memif_socket_filename_dump API.
+ * @param mp vl_api_memif_socket_filename_dump_t api message
+ */
+void
+ vl_api_memif_socket_filename_dump_t_handler
+ (vl_api_memif_socket_filename_dump_t * mp)
+{
+ memif_main_t *mm = &memif_main;
+ vl_api_registration_t *reg;
+ u32 sock_id;
+ u32 msf_idx;
+
+ reg = vl_api_client_index_to_registration (mp->client_index);
+ if (!reg)
+ return;
+
+ /* *INDENT-OFF* */
+ hash_foreach (sock_id, msf_idx, mm->socket_file_index_by_sock_id,
+ ({
+ memif_socket_file_t *msf;
+ u8 *filename;
+
+ msf = pool_elt_at_index(mm->socket_files, msf_idx);
+ filename = msf->filename;
+ send_memif_socket_filename_details(reg, sock_id, filename, mp->context);
+ }));
+ /* *INDENT-ON* */
+}
+
#define vl_msg_name_crc_list
#include <memif/memif_all_api_h.h>
#undef vl_msg_name_crc_list