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_test.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_test.c')
-rw-r--r-- | src/plugins/memif/memif_test.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/plugins/memif/memif_test.c b/src/plugins/memif/memif_test.c index 98c9354a95e..07d68924b86 100644 --- a/src/plugins/memif/memif_test.c +++ b/src/plugins/memif/memif_test.c @@ -121,6 +121,86 @@ api_memif_socket_filename_add_del (vat_main_t * vam) return ret; } +/* memif_socket_filename_add_del API */ +static int +api_memif_socket_filename_add_del_v2 (vat_main_t *vam) +{ + unformat_input_t *i = vam->input; + vl_api_memif_socket_filename_add_del_v2_t *mp; + u8 is_add; + u32 socket_id; + u8 *socket_filename; + int ret; + + is_add = 1; + socket_id = ~0; + socket_filename = 0; + + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "id %u", &socket_id)) + ; + else if (unformat (i, "filename %s", &socket_filename)) + ; + else if (unformat (i, "del")) + is_add = 0; + else if (unformat (i, "add")) + is_add = 1; + else + { + vec_free (socket_filename); + clib_warning ("unknown input `%U'", format_unformat_error, i); + return -99; + } + } + + if (socket_id == 0 || socket_id == ~0) + { + vec_free (socket_filename); + errmsg ("Invalid socket id"); + return -99; + } + + if (is_add && (!socket_filename || *socket_filename == 0)) + { + vec_free (socket_filename); + errmsg ("Invalid socket filename"); + return -99; + } + + M2 (MEMIF_SOCKET_FILENAME_ADD_DEL_V2, mp, strlen ((char *) socket_filename)); + + mp->is_add = is_add; + mp->socket_id = htonl (socket_id); + char *p = (char *) &mp->socket_filename; + p += vl_api_vec_to_api_string (socket_filename, (vl_api_string_t *) p); + + vec_free (socket_filename); + + S (mp); + W (ret); + + return ret; +} + +/* memif socket-create reply handler */ +static void +vl_api_memif_socket_filename_add_del_v2_reply_t_handler ( + vl_api_memif_socket_filename_add_del_v2_reply_t *mp) +{ + vat_main_t *vam = memif_test_main.vat_main; + i32 retval = ntohl (mp->retval); + + if (retval == 0) + { + fformat (vam->ofp, "created memif socket with socket_id %d\n", + ntohl (mp->socket_id)); + } + + vam->retval = retval; + vam->result_ready = 1; +} + /* memif_socket_filename_add_del reply handler */ #define VL_API_MEMIF_SOCKET_FILENAME_ADD_DEL_REPLY_T_HANDLER static void vl_api_memif_socket_filename_add_del_reply_t_handler |