summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2019-12-06 17:05:08 -0800
committerDave Barach <openvpp@barachs.net>2019-12-09 15:50:02 +0000
commit5224b5cbd51ed48d1d2ce2a412998d8a944c480b (patch)
tree470bd8dda83ecb91f251f563e721acee306a6dec
parent4505f0154eaba59c432c869b65e2dc493837032a (diff)
api: fix sock reg passing on read event
Type: fix Change-Id: I383242e04a114b69fe247d912842be3560e96c10 Signed-off-by: Florin Coras <fcoras@cisco.com>
-rw-r--r--src/vlibmemory/socket_api.c23
-rw-r--r--src/vlibmemory/socket_api.h15
-rw-r--r--src/vlibmemory/vlib_api.c12
3 files changed, 24 insertions, 26 deletions
diff --git a/src/vlibmemory/socket_api.c b/src/vlibmemory/socket_api.c
index a07d717e1d1..32d1e704bd8 100644
--- a/src/vlibmemory/socket_api.c
+++ b/src/vlibmemory/socket_api.c
@@ -190,16 +190,13 @@ vl_socket_free_registration_index (u32 pool_index)
}
void
-vl_socket_process_api_msg (clib_file_t * uf, vl_api_registration_t * rp,
- i8 * input_v)
+vl_socket_process_api_msg (vl_api_registration_t * rp, i8 * input_v)
{
msgbuf_t *mbp = (msgbuf_t *) input_v;
u8 *the_msg = (u8 *) (mbp->data);
- socket_main.current_uf = uf;
socket_main.current_rp = rp;
vl_msg_api_socket_handler (the_msg);
- socket_main.current_uf = 0;
socket_main.current_rp = 0;
}
@@ -235,8 +232,9 @@ vl_socket_read_ready (clib_file_t * uf)
u32 msgbuf_len;
u32 save_input_buffer_length = vec_len (socket_main.input_buffer);
vl_socket_args_for_process_t *a;
+ u32 reg_index = uf->private_data;
- rp = pool_elt_at_index (socket_main.registration_pool, uf->private_data);
+ rp = vl_socket_get_registration (reg_index);
/* Ignore unprocessed_input for now, n describes input_buffer for now. */
n = read (uf->file_descriptor, socket_main.input_buffer,
@@ -248,17 +246,7 @@ vl_socket_read_ready (clib_file_t * uf)
{
/* Severe error, close the file. */
clib_file_del (fm, uf);
-
- if (!pool_is_free (socket_main.registration_pool, rp))
- {
- u32 index = rp - socket_main.registration_pool;
- vl_socket_free_registration_index (index);
- }
- else
- {
- clib_warning ("client index %d already free?",
- rp->vl_api_registration_pool_index);
- }
+ vl_socket_free_registration_index (reg_index);
}
/* EAGAIN means we do not close the file, but no data to process anyway. */
return 0;
@@ -326,8 +314,7 @@ vl_socket_read_ready (clib_file_t * uf)
_vec_len (data_for_process) = msgbuf_len;
/* Everything is ready to signal the SOCKET_READ_EVENT. */
pool_get (socket_main.process_args, a);
- a->clib_file = uf;
- a->regp = rp;
+ a->reg_index = reg_index;
a->data = data_for_process;
vlib_process_signal_event (vm, vl_api_clnt_node.index,
diff --git a/src/vlibmemory/socket_api.h b/src/vlibmemory/socket_api.h
index 7192e0fcacc..41835e3050b 100644
--- a/src/vlibmemory/socket_api.h
+++ b/src/vlibmemory/socket_api.h
@@ -29,8 +29,7 @@
typedef struct
{
- clib_file_t *clib_file;
- vl_api_registration_t *regp;
+ u32 reg_index;
u8 *data;
} vl_socket_args_for_process_t;
@@ -53,7 +52,6 @@ typedef struct
* or to a shared-memory connection.
*/
vl_api_registration_t *current_rp;
- clib_file_t *current_uf;
/* One input buffer, shared across all sockets */
i8 *input_buffer;
@@ -66,12 +64,19 @@ typedef struct
extern socket_main_t socket_main;
+always_inline vl_api_registration_t *
+vl_socket_get_registration (u32 reg_index)
+{
+ if (pool_is_free_index (socket_main.registration_pool, reg_index))
+ return 0;
+ return pool_elt_at_index (socket_main.registration_pool, reg_index);
+}
+
void vl_socket_free_registration_index (u32 pool_index);
clib_error_t *vl_socket_read_ready (struct clib_file *uf);
clib_error_t *vl_socket_write_ready (struct clib_file *uf);
void vl_socket_api_send (vl_api_registration_t * rp, u8 * elem);
-void vl_socket_process_api_msg (clib_file_t * uf, vl_api_registration_t * rp,
- i8 * input_v);
+void vl_socket_process_api_msg (vl_api_registration_t * rp, i8 * input_v);
void vl_sock_api_dump_clients (vlib_main_t * vm, api_main_t * am);
clib_error_t *vl_sock_api_init (vlib_main_t * vm);
clib_error_t *vl_sock_api_send_fd_msg (int socket_fd, int fds[], int n_fds);
diff --git a/src/vlibmemory/vlib_api.c b/src/vlibmemory/vlib_api.c
index 05652fa2244..5494da3d1fb 100644
--- a/src/vlibmemory/vlib_api.c
+++ b/src/vlibmemory/vlib_api.c
@@ -385,10 +385,16 @@ vl_api_clnt_process (vlib_main_t * vm, vlib_node_runtime_t * node,
case SOCKET_READ_EVENT:
for (i = 0; i < vec_len (event_data); i++)
{
+ vl_api_registration_t *regp;
+
a = pool_elt_at_index (socket_main.process_args, event_data[i]);
- vl_socket_process_api_msg (a->clib_file, a->regp,
- (i8 *) a->data);
- a = pool_elt_at_index (socket_main.process_args, event_data[i]);
+ regp = vl_socket_get_registration (a->reg_index);
+ if (regp)
+ {
+ vl_socket_process_api_msg (regp, (i8 *) a->data);
+ a = pool_elt_at_index (socket_main.process_args,
+ event_data[i]);
+ }
vec_free (a->data);
pool_put (socket_main.process_args, a);
}