Code Review
/
vpp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
session: cleanup use of api_client_index
[vpp.git]
/
src
/
vnet
/
session
/
application_interface.c
diff --git
a/src/vnet/session/application_interface.c
b/src/vnet/session/application_interface.c
index
1f094ef
..
2a09909
100644
(file)
--- a/
src/vnet/session/application_interface.c
+++ b/
src/vnet/session/application_interface.c
@@
-81,6
+81,13
@@
const char test_srv_key_rsa[] =
"oEjPLVNtx8SOj/M4rhaPT3I=\r\n" "-----END PRIVATE KEY-----\r\n";
const u32 test_srv_key_rsa_len = sizeof (test_srv_key_rsa);
"oEjPLVNtx8SOj/M4rhaPT3I=\r\n" "-----END PRIVATE KEY-----\r\n";
const u32 test_srv_key_rsa_len = sizeof (test_srv_key_rsa);
+#define app_interface_check_thread_and_barrier(_fn, _arg) \
+ if (PREDICT_FALSE (!vlib_thread_is_main_w_barrier ())) \
+ { \
+ vlib_rpc_call_main_thread (_fn, (u8 *) _arg, sizeof(*_arg)); \
+ return 0; \
+ }
+
static u8
session_endpoint_is_local (session_endpoint_t * sep)
{
static u8
session_endpoint_is_local (session_endpoint_t * sep)
{
@@
-118,10
+125,10
@@
api_parse_session_handle (u64 handle, u32 * session_index, u32 * thread_index)
*thread_index = handle & 0xFFFFFFFF;
*session_index = handle >> 32;
*thread_index = handle & 0xFFFFFFFF;
*session_index = handle >> 32;
- if (*thread_index >= vec_len (smm->
sessions
))
+ if (*thread_index >= vec_len (smm->
wrk
))
return VNET_API_ERROR_INVALID_VALUE;
return VNET_API_ERROR_INVALID_VALUE;
- pool = smm->
sessions[*thread_index]
;
+ pool = smm->
wrk[*thread_index].sessions
;
if (pool_is_free_index (pool, *session_index))
return VNET_API_ERROR_INVALID_VALUE_2;
if (pool_is_free_index (pool, *session_index))
return VNET_API_ERROR_INVALID_VALUE_2;
@@
-130,11
+137,11
@@
api_parse_session_handle (u64 handle, u32 * session_index, u32 * thread_index)
}
static void
}
static void
-session_endpoint_update_for_app (session_endpoint_
extended
_t * sep,
- application_t * app)
+session_endpoint_update_for_app (session_endpoint_
cfg
_t * sep,
+ application_t * app
, u8 is_connect
)
{
app_namespace_t *app_ns;
{
app_namespace_t *app_ns;
- u32 ns_index;
+ u32 ns_index
, fib_index
;
ns_index = app->ns_index;
ns_index = app->ns_index;
@@
-149,15
+156,29
@@
session_endpoint_update_for_app (session_endpoint_extended_t * sep,
ns_index = owner_app->ns_index;
}
app_ns = app_namespace_get (ns_index);
ns_index = owner_app->ns_index;
}
app_ns = app_namespace_get (ns_index);
- if (app_ns)
+ if (!app_ns)
+ return;
+
+ /* Ask transport and network to bind to/connect using local interface
+ * that "supports" app's namespace. This will fix our local connection
+ * endpoint.
+ */
+ fib_index = sep->is_ip4 ? app_ns->ip4_fib_index : app_ns->ip6_fib_index;
+ sep->peer.fib_index = fib_index;
+ sep->fib_index = fib_index;
+
+ if (!is_connect)
{
{
- /* Ask transport and network to bind to/connect using local interface
- * that "supports" app's namespace. This will fix our local connection
- * endpoint.
- */
sep->sw_if_index = app_ns->sw_if_index;
sep->sw_if_index = app_ns->sw_if_index;
- sep->fib_index =
- sep->is_ip4 ? app_ns->ip4_fib_index : app_ns->ip6_fib_index;
+ }
+ else
+ {
+ if (app_ns->sw_if_index != APP_NAMESPACE_INVALID_INDEX
+ && sep->peer.sw_if_index != ENDPOINT_INVALID_INDEX
+ && sep->peer.sw_if_index != app_ns->sw_if_index)
+ clib_warning ("Local sw_if_index different from app ns sw_if_index");
+
+ sep->peer.sw_if_index = app_ns->sw_if_index;
}
}
}
}
@@
-178,7
+199,7
@@
vnet_bind_inline (vnet_bind_args_t * a)
app_wrk = application_get_worker (app, a->wrk_map_index);
a->sep_ext.app_wrk_index = app_wrk->wrk_index;
app_wrk = application_get_worker (app, a->wrk_map_index);
a->sep_ext.app_wrk_index = app_wrk->wrk_index;
- session_endpoint_update_for_app (&a->sep_ext, app);
+ session_endpoint_update_for_app (&a->sep_ext, app
, 0 /* is_connect */
);
if (!session_endpoint_in_ns (&a->sep))
return VNET_API_ERROR_INVALID_VALUE_2;
if (!session_endpoint_in_ns (&a->sep))
return VNET_API_ERROR_INVALID_VALUE_2;
@@
-271,7
+292,7
@@
application_connect (vnet_connect_args_t * a)
return VNET_API_ERROR_INVALID_VALUE;
client = application_get (a->app_index);
return VNET_API_ERROR_INVALID_VALUE;
client = application_get (a->app_index);
- session_endpoint_update_for_app (&a->sep_ext, client);
+ session_endpoint_update_for_app (&a->sep_ext, client
, 1 /* is_connect */
);
client_wrk = application_get_worker (client, a->wrk_map_index);
/*
client_wrk = application_get_worker (client, a->wrk_map_index);
/*
@@
-361,8
+382,7
@@
global_scope:
uword
unformat_vnet_uri (unformat_input_t * input, va_list * args)
{
uword
unformat_vnet_uri (unformat_input_t * input, va_list * args)
{
- session_endpoint_extended_t *sep = va_arg (*args,
- session_endpoint_extended_t *);
+ session_endpoint_cfg_t *sep = va_arg (*args, session_endpoint_cfg_t *);
u32 transport_proto = 0, port;
if (unformat (input, "%U://%U/%d", unformat_transport_proto,
u32 transport_proto = 0, port;
if (unformat (input, "%U://%U/%d", unformat_transport_proto,
@@
-404,10
+424,10
@@
unformat_vnet_uri (unformat_input_t * input, va_list * args)
}
static u8 *cache_uri;
}
static u8 *cache_uri;
-static session_endpoint_
extended
_t *cache_sep;
+static session_endpoint_
cfg
_t *cache_sep;
int
int
-parse_uri (char *uri, session_endpoint_
extended
_t * sep)
+parse_uri (char *uri, session_endpoint_
cfg
_t * sep)
{
unformat_input_t _input, *input = &_input;
{
unformat_input_t _input, *input = &_input;
@@
-476,11
+496,21
@@
vnet_application_attach (vnet_app_attach_args_t * a)
app_worker_t *app_wrk;
segment_manager_t *sm;
u32 app_ns_index = 0;
app_worker_t *app_wrk;
segment_manager_t *sm;
u32 app_ns_index = 0;
+ u8 *app_name = 0;
u64 secret;
int rv;
if (a->api_client_index != APP_INVALID_INDEX)
u64 secret;
int rv;
if (a->api_client_index != APP_INVALID_INDEX)
- app = application_lookup (a->api_client_index);
+ {
+ app = application_lookup (a->api_client_index);
+ if (!app)
+ {
+ vl_api_registration_t *regp;
+ regp = vl_api_client_index_to_registration (a->api_client_index);
+ app_name = format (0, "%s%c", regp->name, 0);
+ a->name = app_name;
+ }
+ }
else if (a->name)
app = application_lookup_name (a->name);
else
else if (a->name)
app = application_lookup_name (a->name);
else
@@
-504,6
+534,7
@@
vnet_application_attach (vnet_app_attach_args_t * a)
return clib_error_return_code (0, rv, 0, "app default wrk init: %d", rv);
a->app_evt_q = app_wrk->event_queue;
return clib_error_return_code (0, rv, 0, "app default wrk init: %d", rv);
a->app_evt_q = app_wrk->event_queue;
+ app_wrk->api_client_index = a->api_client_index;
sm = segment_manager_get (app_wrk->first_segment_manager);
fs = segment_manager_get_segment_w_lock (sm, 0);
sm = segment_manager_get (app_wrk->first_segment_manager);
fs = segment_manager_get_segment_w_lock (sm, 0);
@@
-514,7
+545,7
@@
vnet_application_attach (vnet_app_attach_args_t * a)
a->segment = &fs->ssvm;
segment_manager_segment_reader_unlock (sm);
a->segment = &fs->ssvm;
segment_manager_segment_reader_unlock (sm);
-
+ vec_free (app_name);
return 0;
}
return 0;
}
@@
-525,22
+556,23
@@
int
vnet_application_detach (vnet_app_detach_args_t * a)
{
application_t *app;
vnet_application_detach (vnet_app_detach_args_t * a)
{
application_t *app;
- app = application_get_if_valid (a->app_index);
+ app = application_get_if_valid (a->app_index);
if (!app)
{
clib_warning ("app not attached");
return VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
}
if (!app)
{
clib_warning ("app not attached");
return VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
}
- application_free (app);
+ app_interface_check_thread_and_barrier (vnet_application_detach, a);
+ application_detach_process (app, a->api_client_index);
return 0;
}
int
vnet_bind_uri (vnet_bind_args_t * a)
{
return 0;
}
int
vnet_bind_uri (vnet_bind_args_t * a)
{
- session_endpoint_
extended_t sep = SESSION_ENDPOINT_EXT
_NULL;
+ session_endpoint_
cfg_t sep = SESSION_ENDPOINT_CFG
_NULL;
int rv;
rv = parse_uri (a->uri, &sep);
int rv;
rv = parse_uri (a->uri, &sep);
@@
-554,7
+586,7
@@
vnet_bind_uri (vnet_bind_args_t * a)
int
vnet_unbind_uri (vnet_unbind_args_t * a)
{
int
vnet_unbind_uri (vnet_unbind_args_t * a)
{
- session_endpoint_
extended_t sep = SESSION_ENDPOINT_EXT
_NULL;
+ session_endpoint_
cfg_t sep = SESSION_ENDPOINT_CFG
_NULL;
stream_session_t *listener;
u32 table_index;
int rv;
stream_session_t *listener;
u32 table_index;
int rv;
@@
-577,7
+609,7
@@
vnet_unbind_uri (vnet_unbind_args_t * a)
clib_error_t *
vnet_connect_uri (vnet_connect_args_t * a)
{
clib_error_t *
vnet_connect_uri (vnet_connect_args_t * a)
{
- session_endpoint_
extended_t sep = SESSION_ENDPOINT_EXT
_NULL;
+ session_endpoint_
cfg_t sep = SESSION_ENDPOINT_CFG
_NULL;
int rv;
/* Parse uri */
int rv;
/* Parse uri */
@@
-599,12
+631,7
@@
vnet_disconnect_session (vnet_disconnect_args_t * a)
local_session_t *ls;
/* Disconnect reply came to worker 1 not main thread */
local_session_t *ls;
/* Disconnect reply came to worker 1 not main thread */
- if (vlib_get_thread_index () == 1)
- {
- vlib_rpc_call_main_thread (vnet_disconnect_session, (u8 *) a,
- sizeof (*a));
- return 0;
- }
+ app_interface_check_thread_and_barrier (vnet_disconnect_session, a);
if (!(ls = application_get_local_session_from_handle (a->handle)))
return 0;
if (!(ls = application_get_local_session_from_handle (a->handle)))
return 0;