summaryrefslogtreecommitdiffstats
path: root/vlib-api
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2015-12-14 11:13:29 -0500
committerDave Barach <dave@barachs.net>2015-12-14 11:16:02 -0500
commit4e281a48e2afd258188c9ad996c46f166d4cfd9f (patch)
tree4abdf46defcf566c98ead3e075ce80e490a2da2e /vlib-api
parentcd9752ce4f27dcad68ae085b519654ad5b10731a (diff)
Move rpc handler where it belongs, related cleanup
Change-Id: I393df100558a85fe676f4a4c8c9b546fa549ecc9 Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'vlib-api')
-rw-r--r--vlib-api/vlibmemory/api.h4
-rw-r--r--vlib-api/vlibmemory/memclnt.api20
-rw-r--r--vlib-api/vlibmemory/memory_vlib.c85
3 files changed, 87 insertions, 22 deletions
diff --git a/vlib-api/vlibmemory/api.h b/vlib-api/vlibmemory/api.h
index 7f2f6fa6588..117bf433651 100644
--- a/vlib-api/vlibmemory/api.h
+++ b/vlib-api/vlibmemory/api.h
@@ -109,8 +109,6 @@ static inline u32 vl_msg_api_handle_from_index_and_epoch (u32 index, u32 epoch)
return handle;
}
-
-
void *vl_msg_api_alloc(int nbytes);
void *vl_msg_api_alloc_as_if_client (int nbytes);
void vl_msg_api_free(void *a);
@@ -136,4 +134,6 @@ int vl_client_connect_to_vlib_no_rx_pthread (char *svm_name, char *client_name,
int rx_queue_size);
u16 vl_client_get_first_plugin_msg_id (char * plugin_name);
+void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length);
+
#endif /* included_vlibmemory_api_h */
diff --git a/vlib-api/vlibmemory/memclnt.api b/vlib-api/vlibmemory/memclnt.api
index 6a108b81b08..c2758238a96 100644
--- a/vlib-api/vlibmemory/memclnt.api
+++ b/vlib-api/vlibmemory/memclnt.api
@@ -14,26 +14,6 @@
* limitations under the License.
*/
-/*
- *------------------------------------------------------------------
- * memclnt.api - API message(s) to hook up clients, pass traffic
- * to client processes on the same system element
- *
- * Copyright (c) 2009 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *------------------------------------------------------------------
- */
-
/*
* Create a client registration
*/
diff --git a/vlib-api/vlibmemory/memory_vlib.c b/vlib-api/vlibmemory/memory_vlib.c
index 165cdf30f20..57cb8f74012 100644
--- a/vlib-api/vlibmemory/memory_vlib.c
+++ b/vlib-api/vlibmemory/memory_vlib.c
@@ -1122,3 +1122,88 @@ VLIB_CLI_COMMAND (cli_show_api_plugin_command, static) = {
.short_help = "show api plugin",
.function = vl_api_show_plugin_command,
};
+
+static void vl_api_rpc_call_t_handler (vl_api_rpc_call_t * mp)
+{
+ vl_api_rpc_reply_t * rmp;
+ int (*fp)(void *);
+ i32 rv = 0;
+ vlib_main_t * vm = vlib_get_main();
+
+ if (mp->function == 0)
+ {
+ rv = -1;
+ clib_warning ("rpc NULL function pointer");
+ }
+
+ else
+ {
+ if (mp->need_barrier_sync)
+ vlib_worker_thread_barrier_sync (vm);
+
+ fp = (void *)(mp->function);
+ rv = (*fp)(mp->data);
+
+ if (mp->need_barrier_sync)
+ vlib_worker_thread_barrier_release (vm);
+ }
+
+ if (mp->send_reply)
+ {
+ unix_shared_memory_queue_t * q =
+ vl_api_client_index_to_input_queue (mp->client_index);
+ if (q)
+ {
+ rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp));
+ rmp->_vl_msg_id = ntohs (VL_API_RPC_REPLY);
+ rmp->context = mp->context;
+ rmp->retval = rv;
+ vl_msg_api_send_shmem (q, (u8 *)&rmp);
+ }
+ }
+ if (mp->multicast)
+ {
+ clib_warning ("multicast not yet implemented...");
+ }
+}
+
+static void vl_api_rpc_reply_t_handler (vl_api_rpc_reply_t * mp)
+{ clib_warning ("unimplemented"); }
+
+void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length)
+{
+ vl_api_rpc_call_t * mp;
+ api_main_t *am = &api_main;
+ vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr;
+
+ mp = vl_msg_api_alloc_as_if_client (sizeof (*mp) + data_length);
+ memset (mp, 0, sizeof (*mp));
+ memcpy (mp->data, data, data_length);
+ mp->_vl_msg_id = ntohs (VL_API_RPC_CALL);
+ mp->function = (u64)fp;
+ mp->need_barrier_sync = 1;
+
+ /* Use the "normal" control-plane mechanism for the main thread */
+ vl_msg_api_send_shmem (shmem_hdr->vl_input_queue, (u8 *)&mp);
+}
+
+#define foreach_rpc_api_msg \
+_(RPC_CALL,rpc_call) \
+_(RPC_REPLY,rpc_reply)
+
+static clib_error_t *
+rpc_api_hookup (vlib_main_t *vm)
+{
+#define _(N,n) \
+ vl_msg_api_set_handlers(VL_API_##N, #n, \
+ vl_api_##n##_t_handler, \
+ vl_noop_handler, \
+ vl_noop_handler, \
+ vl_api_##n##_t_print, \
+ sizeof(vl_api_##n##_t), 0 /* do not trace */);
+ foreach_rpc_api_msg;
+#undef _
+ return 0;
+}
+
+VLIB_API_INIT_FUNCTION(rpc_api_hookup);