diff options
author | Nathan Skrzypczak <nathan.skrzypczak@gmail.com> | 2021-12-15 19:15:32 +0100 |
---|---|---|
committer | Damjan Marion <dmarion@0xa5.net> | 2023-03-06 13:54:06 +0000 |
commit | 8b213ee652dd69d941865fa59e1f780843016475 (patch) | |
tree | f37774b199588dcace4b1c4277b8398fc3cc0498 /src/plugins/memif/memif_api.c | |
parent | ec5c40b83acae400a8cc1a18ad897b6365774559 (diff) |
memif: autogenerate socket_ids
This patch adds an API memif_socket_filename_add_del_v2
that allows autogenerating memif socket_id when passing
~0 in the socket_id field.
It opportunistically walks the hash to find a free ID
to use, and returns it in the reply.
socket_filename also becomes a variable length string,
to accomodate for longer names (in case a netns gets
passed)
Type: feature
Change-Id: I33fc3e1cf553af27579d6bad8691b22b530531cc
Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
Diffstat (limited to 'src/plugins/memif/memif_api.c')
-rw-r--r-- | src/plugins/memif/memif_api.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/plugins/memif/memif_api.c b/src/plugins/memif/memif_api.c index 9a2f42a5bc7..819350a6795 100644 --- a/src/plugins/memif/memif_api.c +++ b/src/plugins/memif/memif_api.c @@ -72,6 +72,42 @@ reply: REPLY_MACRO (VL_API_MEMIF_SOCKET_FILENAME_ADD_DEL_REPLY); } +/** + * @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_v2_t_handler ( + vl_api_memif_socket_filename_add_del_v2_t *mp) +{ + vl_api_memif_socket_filename_add_del_v2_reply_t *rmp; + memif_main_t *mm = &memif_main; + char *socket_filename = 0; + u32 socket_id; + int rv; + + /* socket_id */ + socket_id = clib_net_to_host_u32 (mp->socket_id); + if (socket_id == 0) + { + rv = VNET_API_ERROR_INVALID_ARGUMENT; + goto reply; + } + + /* socket filename */ + socket_filename = vl_api_from_api_to_new_c_string (&mp->socket_filename); + if (mp->is_add && socket_id == (u32) ~0) + socket_id = memif_get_unused_socket_id (); + + rv = vnet_api_error ( + memif_socket_filename_add_del (mp->is_add, socket_id, socket_filename)); + + vec_free (socket_filename); + +reply: + REPLY_MACRO2 (VL_API_MEMIF_SOCKET_FILENAME_ADD_DEL_V2_REPLY, + ({ rmp->socket_id = htonl (socket_id); })); +} /** * @brief Message handler for memif_create API. |