aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2019-02-05 20:55:11 -0800
committerDamjan Marion <dmarion@me.com>2019-02-09 16:17:32 +0000
commitc9940fc20bf248ba10dad10108415219f0f8360f (patch)
treebf18da0d4a869dece31e2dd0f0daa1ce922b3c10 /src/vnet
parent6164e97e0f2fddadea90fd24cd0ea4e629ba9b26 (diff)
session: refactor listen logic
Make app-listener the handle for app listens. Consequently transport and local listen sessions are now associated to the app-listener. Change-Id: I9397a26d42cccb100970b6b4794c15bac2e11465 Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/vnet')
-rw-r--r--src/vnet/sctp/sctp_input.c2
-rw-r--r--src/vnet/session-apps/echo_server.c2
-rw-r--r--src/vnet/session-apps/http_server.c2
-rw-r--r--src/vnet/session-apps/proxy.c2
-rw-r--r--src/vnet/session/application.c600
-rw-r--r--src/vnet/session/application.h39
-rw-r--r--src/vnet/session/application_interface.c157
-rw-r--r--src/vnet/session/application_interface.h10
-rw-r--r--src/vnet/session/application_worker.c114
-rw-r--r--src/vnet/session/session.c6
-rw-r--r--src/vnet/session/session.h105
-rwxr-xr-xsrc/vnet/session/session_api.c65
-rw-r--r--src/vnet/session/session_types.h124
-rw-r--r--src/vnet/tcp/tcp_input.c2
-rw-r--r--src/vnet/tls/tls.c8
-rw-r--r--src/vnet/tls/tls.h3
-rw-r--r--src/vnet/udp/udp_input.c2
17 files changed, 598 insertions, 645 deletions
diff --git a/src/vnet/sctp/sctp_input.c b/src/vnet/sctp/sctp_input.c
index 88e4eab754d..f24e5c7a0a5 100644
--- a/src/vnet/sctp/sctp_input.c
+++ b/src/vnet/sctp/sctp_input.c
@@ -1764,7 +1764,7 @@ sctp46_listen_process_inline (vlib_main_t * vm,
if (error0 == SCTP_ERROR_NONE)
{
- if (stream_session_accept
+ if (session_stream_accept
(&child_conn->
sub_conn[SCTP_PRIMARY_PATH_IDX].connection,
sctp_listener->
diff --git a/src/vnet/session-apps/echo_server.c b/src/vnet/session-apps/echo_server.c
index 0229da35624..c59a2330865 100644
--- a/src/vnet/session-apps/echo_server.c
+++ b/src/vnet/session-apps/echo_server.c
@@ -362,7 +362,7 @@ static int
echo_server_listen ()
{
echo_server_main_t *esm = &echo_server_main;
- vnet_bind_args_t _a, *a = &_a;
+ vnet_listen_args_t _a, *a = &_a;
clib_memset (a, 0, sizeof (*a));
a->app_index = esm->app_index;
a->uri = esm->server_uri;
diff --git a/src/vnet/session-apps/http_server.c b/src/vnet/session-apps/http_server.c
index 25d83214112..ffa1ed85b42 100644
--- a/src/vnet/session-apps/http_server.c
+++ b/src/vnet/session-apps/http_server.c
@@ -727,7 +727,7 @@ static int
http_server_listen ()
{
http_server_main_t *hsm = &http_server_main;
- vnet_bind_args_t _a, *a = &_a;
+ vnet_listen_args_t _a, *a = &_a;
clib_memset (a, 0, sizeof (*a));
a->app_index = hsm->app_index;
a->uri = "tcp://0.0.0.0/80";
diff --git a/src/vnet/session-apps/proxy.c b/src/vnet/session-apps/proxy.c
index 063c13cda35..ba7b05784fa 100644
--- a/src/vnet/session-apps/proxy.c
+++ b/src/vnet/session-apps/proxy.c
@@ -463,7 +463,7 @@ static int
proxy_server_listen ()
{
proxy_main_t *pm = &proxy_main;
- vnet_bind_args_t _a, *a = &_a;
+ vnet_listen_args_t _a, *a = &_a;
clib_memset (a, 0, sizeof (*a));
a->app_index = pm->server_app_index;
a->uri = (char *) pm->server_uri;
diff --git a/src/vnet/session/application.c b/src/vnet/session/application.c
index 3380d0bca4a..763ab351b17 100644
--- a/src/vnet/session/application.c
+++ b/src/vnet/session/application.c
@@ -20,6 +20,16 @@
static app_main_t app_main;
+static void
+application_local_listener_session_endpoint (local_session_t * ll,
+ session_endpoint_t * sep)
+{
+ sep->transport_proto =
+ session_type_transport_proto (ll->listener_session_type);
+ sep->port = ll->port;
+ sep->is_ip4 = ll->listener_session_type & 1;
+}
+
static app_listener_t *
app_listener_alloc (application_t * app)
{
@@ -27,10 +37,13 @@ app_listener_alloc (application_t * app)
pool_get (app->listeners, app_listener);
clib_memset (app_listener, 0, sizeof (*app_listener));
app_listener->al_index = app_listener - app->listeners;
+ app_listener->app_index = app->app_index;
+ app_listener->session_index = SESSION_INVALID_INDEX;
+ app_listener->local_index = SESSION_INVALID_INDEX;
return app_listener;
}
-static app_listener_t *
+app_listener_t *
app_listener_get (application_t * app, u32 app_listener_index)
{
return pool_elt_at_index (app->listeners, app_listener_index);
@@ -45,29 +58,242 @@ app_listener_free (application_t * app, app_listener_t * app_listener)
clib_memset (app_listener, 0xfa, sizeof (*app_listener));
}
+local_session_t *
+application_local_listen_session_alloc (application_t * app)
+{
+ local_session_t *ll;
+ pool_get_zero (app->local_listen_sessions, ll);
+ ll->session_index = ll - app->local_listen_sessions;
+ ll->session_type = session_type_from_proto_and_ip (TRANSPORT_PROTO_NONE, 0);
+ ll->app_index = app->app_index;
+ return ll;
+}
+
+void
+application_local_listen_session_free (application_t * app,
+ local_session_t * ll)
+{
+ pool_put (app->local_listen_sessions, ll);
+ if (CLIB_DEBUG)
+ clib_memset (ll, 0xfb, sizeof (*ll));
+}
+
+static u32
+app_listener_id (app_listener_t * al)
+{
+ ASSERT (al->app_index < 1 << 16 && al->al_index < 1 << 16);
+ return (al->app_index << 16 | al->al_index);
+}
+
+session_handle_t
+app_listener_handle (app_listener_t * al)
+{
+ return ((u64) SESSION_LISTENER_PREFIX << 32 | (u64) app_listener_id (al));
+}
+
+static void
+app_listener_id_parse (u32 listener_id, u32 * app_index,
+ u32 * app_listener_index)
+{
+ *app_index = listener_id >> 16;
+ *app_listener_index = listener_id & 0xFFFF;
+}
+
+void
+app_listener_handle_parse (session_handle_t handle, u32 * app_index,
+ u32 * app_listener_index)
+{
+ app_listener_id_parse (handle & 0xFFFFFFFF, app_index, app_listener_index);
+}
+
static app_listener_t *
-app_local_listener_alloc (application_t * app)
+app_listener_get_w_id (u32 listener_id)
+{
+ u32 app_index, app_listener_index;
+ application_t *app;
+
+ app_listener_id_parse (listener_id, &app_index, &app_listener_index);
+ app = application_get_if_valid (app_index);
+ if (!app)
+ return 0;
+ return app_listener_get (app, app_listener_index);
+}
+
+app_listener_t *
+app_listener_get_w_session (session_t * ls)
+{
+ application_t *app;
+
+ app = application_get_if_valid (ls->app_index);
+ if (!app)
+ return 0;
+ return app_listener_get (app, ls->al_index);
+}
+
+app_listener_t *
+app_listener_get_w_handle (session_handle_t handle)
+{
+
+ if (handle >> 32 != SESSION_LISTENER_PREFIX)
+ return 0;
+
+ return app_listener_get_w_id (handle & 0xFFFFFFFF);
+}
+
+app_listener_t *
+app_listener_lookup (application_t * app, session_endpoint_cfg_t * sep_ext)
+{
+ u32 table_index, fib_proto;
+ session_endpoint_t *sep;
+ session_handle_t handle;
+ local_session_t *ll;
+ session_t *ls;
+
+ sep = (session_endpoint_t *) sep_ext;
+ if (application_has_local_scope (app) && session_endpoint_is_local (sep))
+ {
+ table_index = application_local_session_table (app);
+ handle = session_lookup_endpoint_listener (table_index, sep, 1);
+ if (handle != SESSION_INVALID_HANDLE)
+ {
+ ll = application_get_local_listener_w_handle (handle);
+ return app_listener_get_w_session ((session_t *) ll);
+ }
+ }
+
+ fib_proto = session_endpoint_fib_proto (sep);
+ table_index = application_session_table (app, fib_proto);
+ handle = session_lookup_endpoint_listener (table_index, sep, 1);
+ if (handle != SESSION_INVALID_HANDLE)
+ {
+ ls = listen_session_get_from_handle (handle);
+ return app_listener_get_w_session ((session_t *) ls);
+ }
+
+ return 0;
+}
+
+int
+app_listener_alloc_and_init (application_t * app,
+ session_endpoint_cfg_t * sep,
+ app_listener_t ** listener)
{
app_listener_t *app_listener;
- pool_get (app->local_listeners, app_listener);
- clib_memset (app_listener, 0, sizeof (*app_listener));
- app_listener->al_index = app_listener - app->local_listeners;
- return app_listener;
+ local_session_t *ll = 0;
+ session_handle_t lh;
+ session_type_t st;
+ session_t *ls = 0;
+ int rv;
+
+ app_listener = app_listener_alloc (app);
+ st = session_type_from_proto_and_ip (sep->transport_proto, sep->is_ip4);
+
+ /*
+ * Add session endpoint to local session table. Only binds to "inaddr_any"
+ * (i.e., zero address) are added to local scope table.
+ */
+ if (application_has_local_scope (app)
+ && session_endpoint_is_local ((session_endpoint_t *) sep))
+ {
+ u32 table_index;
+
+ ll = application_local_listen_session_alloc (app);
+ ll->port = sep->port;
+ /* Store the original session type for the unbind */
+ ll->listener_session_type = st;
+ table_index = application_local_session_table (app);
+ lh = application_local_session_handle (ll);
+ session_lookup_add_session_endpoint (table_index,
+ (session_endpoint_t *) sep, lh);
+ app_listener->local_index = ll->session_index;
+ ll->al_index = app_listener->al_index;
+ }
+
+ if (application_has_global_scope (app))
+ {
+ /*
+ * Start listening on local endpoint for requested transport and scope.
+ * Creates a stream session with state LISTENING to be used in session
+ * lookups, prior to establishing connection. Requests transport to
+ * build it's own specific listening connection.
+ */
+ ls = listen_session_new (0, st);
+ ls->app_index = app->app_index;
+ ls->app_wrk_index = sep->app_wrk_index;
+
+ /* Listen pool can be reallocated if the transport is
+ * recursive (tls) */
+ lh = session_handle (ls);
+
+ if ((rv = session_listen (ls, sep)))
+ {
+ ls = session_get_from_handle (lh);
+ session_free (ls);
+ return rv;
+ }
+ app_listener->session_index = ls->session_index;
+ ls->al_index = app_listener->al_index;
+ }
+
+ if (!ll && !ls)
+ {
+ app_listener_free (app, app_listener);
+ return -1;
+ }
+
+ *listener = app_listener;
+ return 0;
}
-static app_listener_t *
-app_local_listener_get (application_t * app, u32 app_listener_index)
+void
+app_listener_cleanup (app_listener_t * al)
+{
+ application_t *app = application_get (al->app_index);
+
+ if (al->session_index != SESSION_INVALID_INDEX)
+ {
+ session_t *ls = session_get (al->session_index, 0);
+ session_stop_listen (ls);
+ listen_session_del (ls);
+ }
+ if (al->local_index != SESSION_INVALID_INDEX)
+ {
+ session_endpoint_t sep = SESSION_ENDPOINT_NULL;
+ local_session_t *ll;
+ u32 table_index;
+
+ table_index = application_local_session_table (app);
+ ll = application_get_local_listen_session (app, al->local_index);
+ application_local_listener_session_endpoint (ll, &sep);
+ session_lookup_del_session_endpoint (table_index, &sep);
+ application_local_listen_session_free (app, ll);
+ }
+ app_listener_free (app, al);
+}
+
+app_worker_t *
+app_listener_select_worker (app_listener_t * al)
{
- return pool_elt_at_index (app->local_listeners, app_listener_index);
+ application_t *app;
+ u32 wrk_index;
+
+ app = application_get (al->app_index);
+ wrk_index = clib_bitmap_next_set (al->workers, al->accept_rotor + 1);
+ if (wrk_index == ~0)
+ wrk_index = clib_bitmap_first_set (al->workers);
+
+ ASSERT (wrk_index != ~0);
+ al->accept_rotor = wrk_index;
+ return application_get_worker (app, wrk_index);
}
-static void
-app_local_listener_free (application_t * app, app_listener_t * app_listener)
+session_t *
+app_listener_get_session (app_listener_t * al)
{
- clib_bitmap_free (app_listener->workers);
- pool_put (app->local_listeners, app_listener);
- if (CLIB_DEBUG)
- clib_memset (app_listener, 0xfa, sizeof (*app_listener));
+ if (al->session_index == SESSION_INVALID_INDEX)
+ return 0;
+
+ return listen_session_get (al->session_index);
}
static app_worker_map_t *
@@ -130,16 +356,6 @@ application_local_session_table (application_t * app)
return app_ns->local_table_index;
}
-static void
-application_local_listener_session_endpoint (local_session_t * ll,
- session_endpoint_t * sep)
-{
- sep->transport_proto =
- session_type_transport_proto (ll->listener_session_type);
- sep->port = ll->port;
- sep->is_ip4 = ll->listener_session_type & 1;
-}
-
/**
* Returns app name for app-index
*/
@@ -475,26 +691,12 @@ application_n_workers (application_t * app)
}
app_worker_t *
-application_listener_select_worker (session_t * ls, u8 is_local)
+application_listener_select_worker (session_t * ls)
{
- app_listener_t *app_listener;
- application_t *app;
- u32 wrk_index;
+ app_listener_t *al;
- app = application_get (ls->app_index);
- if (!is_local)
- app_listener = app_listener_get (app, ls->listener_db_index);
- else
- app_listener = app_local_listener_get (app, ls->listener_db_index);
-
- wrk_index = clib_bitmap_next_set (app_listener->workers,
- app_listener->accept_rotor + 1);
- if (wrk_index == ~0)
- wrk_index = clib_bitmap_first_set (app_listener->workers);
-
- ASSERT (wrk_index != ~0);
- app_listener->accept_rotor = wrk_index;
- return application_get_worker (app, wrk_index);
+ al = app_listener_get_w_session (ls);
+ return app_listener_select_worker (al);
}
int
@@ -545,88 +747,6 @@ application_alloc_worker_and_init (application_t * app, app_worker_t ** wrk)
return 0;
}
-/**
- * Start listening local transport endpoint for requested transport.
- *
- * Creates a 'dummy' stream session with state LISTENING to be used in session
- * lookups, prior to establishing connection. Requests transport to build
- * it's own specific listening connection.
- */
-int
-application_start_listen (application_t * app,
- session_endpoint_cfg_t * sep_ext,
- session_handle_t * res)
-{
- app_listener_t *app_listener;
- u32 table_index, fib_proto;
- session_endpoint_t *sep;
- app_worker_t *app_wrk;
- session_t *ls;
- session_handle_t lh;
- session_type_t sst;
-
- /*
- * Check if sep is already listened on
- */
- sep = (session_endpoint_t *) sep_ext;
- fib_proto = session_endpoint_fib_proto (sep);
- table_index = application_session_table (app, fib_proto);
- lh = session_lookup_endpoint_listener (table_index, sep, 1);
- if (lh != SESSION_INVALID_HANDLE)
- {
- ls = listen_session_get_from_handle (lh);
- if (ls->app_index != app->app_index)
- return VNET_API_ERROR_ADDRESS_IN_USE;
-
- app_wrk = app_worker_get (sep_ext->app_wrk_index);
- if (ls->app_wrk_index == app_wrk->wrk_index)
- return VNET_API_ERROR_ADDRESS_IN_USE;
-
- if (app_worker_start_listen (app_wrk, ls))
- return -1;
-
- app_listener = app_listener_get (app, ls->listener_db_index);
- app_listener->workers = clib_bitmap_set (app_listener->workers,
- app_wrk->wrk_map_index, 1);
-
- *res = listen_session_get_handle (ls);
- return 0;
- }
-
- /*
- * Allocate new listener for application
- */
- sst = session_type_from_proto_and_ip (sep_ext->transport_proto,
- sep_ext->is_ip4);
- ls = listen_session_new (0, sst);
- ls->app_index = app->app_index;
- lh = listen_session_get_handle (ls);
- if (session_listen (ls, sep_ext))
- goto err;
-
-
- ls = listen_session_get_from_handle (lh);
- app_listener = app_listener_alloc (app);
- ls->listener_db_index = app_listener->al_index;
-
- /*
- * Setup app worker as a listener
- */
- app_wrk = app_worker_get (sep_ext->app_wrk_index);
- ls->app_wrk_index = app_wrk->wrk_index;
- if (app_worker_start_listen (app_wrk, ls))
- goto err;
- app_listener->workers = clib_bitmap_set (app_listener->workers,
- app_wrk->wrk_map_index, 1);
-
- *res = lh;
- return 0;
-
-err:
- listen_session_del (ls);
- return -1;
-}
-
int
application_change_listener_owner (session_t * s, app_worker_t * app_wrk)
{
@@ -643,65 +763,20 @@ application_change_listener_owner (session_t * s, app_worker_t * app_wrk)
segment_manager_dealloc_fifos (s->rx_fifo->segment_index, s->rx_fifo,
s->tx_fifo);
- if (app_worker_start_listen (app_wrk, s))
- return -1;
-
- s->app_wrk_index = app_wrk->wrk_index;
-
app = application_get (old_wrk->app_index);
if (!app)
return -1;
- app_listener = app_listener_get (app, s->listener_db_index);
- app_listener->workers = clib_bitmap_set (app_listener->workers,
- app_wrk->wrk_map_index, 1);
+ app_listener = app_listener_get (app, s->al_index);
+
+ /* Only remove from lb for now */
app_listener->workers = clib_bitmap_set (app_listener->workers,
old_wrk->wrk_map_index, 0);
- return 0;
-}
-
-/**
- * Stop listening on session associated to handle
- *
- * @param handle listener handle
- * @param app_index index of the app owning the handle.
- * @param app_wrk_index index of the worker requesting the stop
- */
-int
-application_stop_listen (u32 app_index, u32 app_wrk_index,
- session_handle_t handle)
-{
- app_listener_t *app_listener;
- session_t *listener;
- app_worker_t *app_wrk;
- application_t *app;
-
- listener = listen_session_get_from_handle (handle);
- app = application_get (app_index);
- if (PREDICT_FALSE (!app || app->app_index != listener->app_index))
- {
- clib_warning ("app doesn't own handle %llu!", handle);
- return -1;
- }
- app_listener = app_listener_get (app, listener->listener_db_index);
- if (!clib_bitmap_get (app_listener->workers, app_wrk_index))
- {
- clib_warning ("worker %u not listening on handle %lu", app_wrk_index,
- handle);
- return 0;
- }
-
- app_wrk = application_get_worker (app, app_wrk_index);
- app_worker_stop_listen (app_wrk, handle);
- clib_bitmap_set_no_check (app_listener->workers, app_wrk_index, 0);
+ if (app_worker_start_listen (app_wrk, app_listener))
+ return -1;
- if (clib_bitmap_is_zero (app_listener->workers))
- {
- session_stop_listen (listener);
- app_listener_free (app, app_listener);
- listen_session_del (listener);
- }
+ s->app_wrk_index = app_wrk->wrk_index;
return 0;
}
@@ -803,8 +878,9 @@ application_start_stop_proxy_fib_proto (application_t * app, u8 fib_proto,
session_endpoint_cfg_t sep = SESSION_ENDPOINT_CFG_NULL;
transport_connection_t *tc;
app_worker_t *app_wrk;
+ app_listener_t *al;
session_t *s;
- u64 handle;
+ u32 flags;
/* TODO decide if we want proxy to be enabled for all workers */
app_wrk = application_get_default_worker (app);
@@ -818,8 +894,15 @@ application_start_stop_proxy_fib_proto (application_t * app, u8 fib_proto,
sep.sw_if_index = app_ns->sw_if_index;
sep.transport_proto = transport_proto;
sep.app_wrk_index = app_wrk->wrk_index; /* only default */
- application_start_listen (app, &sep, &handle);
- s = listen_session_get_from_handle (handle);
+
+ /* force global scope listener */
+ flags = app->flags;
+ app->flags &= ~APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
+ app_listener_alloc_and_init (app, &sep, &al);
+ app->flags = flags;
+
+ app_worker_start_listen (app_wrk, al);
+ s = listen_session_get (al->session_index);
s->enqueue_epoch = SESSION_PROXY_LISTENER_INDEX;
}
}
@@ -939,165 +1022,6 @@ application_get_segment_manager_properties (u32 app_index)
return &app->sm_properties;
}
-local_session_t *
-application_local_listen_session_alloc (application_t * app)
-{
- local_session_t *ll;
- pool_get (app->local_listen_sessions, ll);
- clib_memset (ll, 0, sizeof (*ll));
- return ll;
-}
-
-u32
-application_local_listener_index (application_t * app, local_session_t * ll)
-{
- return (ll - app->local_listen_sessions);
-}
-
-void
-application_local_listen_session_free (application_t * app,
- local_session_t * ll)
-{
- pool_put (app->local_listen_sessions, ll);
- if (CLIB_DEBUG)
- clib_memset (ll, 0xfb, sizeof (*ll));
-}
-
-int
-application_start_local_listen (application_t * app,
- session_endpoint_cfg_t * sep_ext,
- session_handle_t * handle)
-{
- app_listener_t *app_listener;
- session_endpoint_t *sep;
- app_worker_t *app_wrk;
- session_handle_t lh;
- local_session_t *ll;
- u32 table_index;
-
- sep = (session_endpoint_t *) sep_ext;
- table_index = application_local_session_table (app);
- app_wrk = app_worker_get (sep_ext->app_wrk_index);
-
- /* An exact sep match, as opposed to session_lookup_local_listener */
- lh = session_lookup_endpoint_listener (table_index, sep, 1);
- if (lh != SESSION_INVALID_HANDLE)
- {
- ll = application_get_local_listener_w_handle (lh);
- if (ll->app_index != app->app_index)
- return VNET_API_ERROR_ADDRESS_IN_USE;
-
- if (ll->app_wrk_index == app_wrk->wrk_index)
- return VNET_API_ERROR_ADDRESS_IN_USE;
-
- app_listener = app_local_listener_get (app, ll->listener_db_index);
- app_listener->workers = clib_bitmap_set (app_listener->workers,
- app_wrk->wrk_map_index, 1);
- *handle = application_local_session_handle (ll);
- return 0;
- }
-
- ll = application_local_listen_session_alloc (app);
- ll->session_type = session_type_from_proto_and_ip (TRANSPORT_PROTO_NONE, 0);
- ll->app_wrk_index = app_wrk->app_index;
- ll->session_index = application_local_listener_index (app, ll);
- ll->port = sep_ext->port;
- /* Store the original session type for the unbind */
- ll->listener_session_type =
- session_type_from_proto_and_ip (sep_ext->transport_proto,
- sep_ext->is_ip4);
- ll->transport_listener_index = ~0;
- ll->app_index = app->app_index;
-
- app_listener = app_local_listener_alloc (app);
- ll->listener_db_index = app_listener->al_index;
- app_listener->workers = clib_bitmap_set (app_listener->workers,
- app_wrk->wrk_map_index, 1);
-
- *handle = application_local_session_handle (ll);
- session_lookup_add_session_endpoint (table_index, sep, *handle);
-
- return 0;
-}
-
-/**
- * Clean up local session table. If we have a listener session use it to
- * find the port and proto. If not, the handle must be a local table handle
- * so parse it.
- */
-int
-application_stop_local_listen (u32 app_index, u32 wrk_map_index,
- session_handle_t lh)
-{
- session_endpoint_t sep = SESSION_ENDPOINT_NULL;
- u32 table_index, ll_index, server_index;
- app_listener_t *app_listener;
- app_worker_t *server_wrk;
- session_t *sl = 0;
- local_session_t *ll, *ls;
- application_t *server;
-
- server = application_get (app_index);
- table_index = application_local_session_table (server);
-
- /* We have both local and global table binds. Figure from global what
- * sep we should be cleaning up.
- */
- if (!session_handle_is_local (lh))
- {
- sl = listen_session_get_from_handle (lh);
- if (!sl || listen_session_get_local_session_endpoint (sl, &sep))
- {
- clib_warning ("broken listener");
- return -1;
- }
- lh = session_lookup_endpoint_listener (table_index, &sep, 0);
- if (lh == SESSION_INVALID_HANDLE)
- return -1;
- }
-
- local_session_parse_handle (lh, &server_index, &ll_index);
- if (PREDICT_FALSE (server_index != app_index))
- {
- clib_warning ("app %u does not own local handle 0x%lx", app_index, lh);
- return -1;
- }
-
- ll = application_get_local_listen_session (server, ll_index);
- if (PREDICT_FALSE (!ll))
- {
- clib_warning ("no local listener");
- return -1;
- }
-
- app_listener = app_local_listener_get (server, ll->listener_db_index);
- if (!clib_bitmap_get (app_listener->workers, wrk_map_index))
- {
- clib_warning ("app wrk %u not listening on handle %lu", wrk_map_index,
- lh);
- return -1;
- }
-
- server_wrk = application_get_worker (server, wrk_map_index);
- /* *INDENT-OFF* */
- pool_foreach (ls, server_wrk->local_sessions, ({
- if (ls->listener_index == ll->session_index)
- app_worker_local_session_disconnect (server_wrk->app_index, ls);
- }));
- /* *INDENT-ON* */
-
- clib_bitmap_set_no_check (app_listener->workers, wrk_map_index, 0);
- if (clib_bitmap_is_zero (app_listener->workers))
- {
- app_local_listener_free (server, app_listener);
- application_local_listener_session_endpoint (ll, &sep);
- session_lookup_del_session_endpoint (table_index, &sep);
- application_local_listen_session_free (server, ll);
- }
-
- return 0;
-}
-
clib_error_t *
vnet_app_add_tls_cert (vnet_app_add_tls_cert_args_t * a)
{
diff --git a/src/vnet/session/application.h b/src/vnet/session/application.h
index e5bb00e2b14..d641263497c 100644
--- a/src/vnet/session/application.h
+++ b/src/vnet/session/application.h
@@ -116,6 +116,9 @@ typedef struct app_listener_
clib_bitmap_t *workers; /**< workers accepting connections */
u32 accept_rotor; /**< last worker to accept a connection */
u32 al_index;
+ u32 app_index;
+ u32 local_index;
+ u32 session_index;
} app_listener_t;
typedef struct application_
@@ -215,6 +218,19 @@ typedef struct _vnet_app_worker_add_del_args
#define APP_NS_INVALID_INDEX ((u32)~0)
#define APP_INVALID_SEGMENT_MANAGER_INDEX ((u32) ~0)
+app_listener_t *app_listener_get (application_t * app, u32 al_index);
+int app_listener_alloc_and_init (application_t * app,
+ session_endpoint_cfg_t * sep,
+ app_listener_t ** listener);
+void app_listener_cleanup (app_listener_t * app_listener);
+session_handle_t app_listener_handle (app_listener_t * app_listener);
+app_listener_t *app_listener_lookup (application_t * app,
+ session_endpoint_cfg_t * sep);
+app_listener_t *app_listener_get_w_handle (session_handle_t handle);
+app_listener_t *app_listener_get_w_session (session_t * ls);
+app_worker_t *app_listener_select_worker (app_listener_t * al);
+session_t *app_listener_get_session (app_listener_t * al);
+
application_t *application_alloc (void);
int application_alloc_and_init (app_init_args_t * args);
void application_free (application_t * app);
@@ -225,13 +241,7 @@ application_t *application_lookup (u32 api_client_index);
application_t *application_lookup_name (const u8 * name);
app_worker_t *application_get_worker (application_t * app, u32 wrk_index);
app_worker_t *application_get_default_worker (application_t * app);
-app_worker_t *application_listener_select_worker (session_t * ls,
- u8 is_local);
-int application_start_listen (application_t * app,
- session_endpoint_cfg_t * tep,
- session_handle_t * handle);
-int application_stop_listen (u32 app_index, u32 app_or_wrk,
- session_handle_t handle);
+app_worker_t *application_listener_select_worker (session_t * ls);
int application_change_listener_owner (session_t * s, app_worker_t * app_wrk);
int application_is_proxy (application_t * app);
int application_is_builtin (application_t * app);
@@ -263,10 +273,10 @@ app_worker_t *app_worker_get_if_valid (u32 wrk_index);
application_t *app_worker_get_app (u32 wrk_index);
int app_worker_own_session (app_worker_t * app_wrk, session_t * s);
void app_worker_free (app_worker_t * app_wrk);
-int app_worker_open_session (app_worker_t * app, session_endpoint_t * tep,
- u32 api_context);
-int app_worker_start_listen (app_worker_t * app_wrk, session_t * ls);
-int app_worker_stop_listen (app_worker_t * app_wrk, session_handle_t handle);
+int app_worker_connect_session (app_worker_t * app, session_endpoint_t * tep,
+ u32 api_context);
+int app_worker_start_listen (app_worker_t * app_wrk, app_listener_t * lstnr);
+int app_worker_stop_listen (app_worker_t * app_wrk, app_listener_t * al);
segment_manager_t *app_worker_get_listen_segment_manager (app_worker_t *,
session_t *);
segment_manager_t *app_worker_get_connect_segment_manager (app_worker_t *);
@@ -298,13 +308,6 @@ local_session_t *app_worker_get_local_session (app_worker_t * app,
u32 session_index);
local_session_t *app_worker_get_local_session_from_handle (session_handle_t
handle);
-local_session_t
- * application_get_local_listen_session_from_handle (session_handle_t lh);
-int application_start_local_listen (application_t * server,
- session_endpoint_cfg_t * sep,
- session_handle_t * handle);
-int application_stop_local_listen (u32 app_index, u32 app_or_wrk,
- session_handle_t lh);
int app_worker_local_session_connect (app_worker_t * client,
app_worker_t * server,
local_session_t * ls, u32 opaque);
diff --git a/src/vnet/session/application_interface.c b/src/vnet/session/application_interface.c
index c00c4ded1c7..11dc97d89b7 100644
--- a/src/vnet/session/application_interface.c
+++ b/src/vnet/session/application_interface.c
@@ -13,7 +13,6 @@
* limitations under the License.
*/
#include <vnet/session/application_interface.h>
-
#include <vnet/session/session.h>
#include <vlibmemory/api.h>
#include <vnet/dpo/load_balance.h>
@@ -88,19 +87,6 @@ const u32 test_srv_key_rsa_len = sizeof (test_srv_key_rsa);
return 0; \
}
-static u8
-session_endpoint_is_local (session_endpoint_t * sep)
-{
- return (ip_is_zero (&sep->ip, sep->is_ip4)
- || ip_is_local_host (&sep->ip, sep->is_ip4));
-}
-
-static u8
-session_endpoint_is_zero (session_endpoint_t * sep)
-{
- return ip_is_zero (&sep->ip, sep->is_ip4);
-}
-
u8
session_endpoint_in_ns (session_endpoint_t * sep)
{
@@ -188,20 +174,21 @@ session_endpoint_update_for_app (session_endpoint_cfg_t * sep,
}
static inline int
-vnet_bind_inline (vnet_bind_args_t * a)
+vnet_listen_inline (vnet_listen_args_t * a)
{
- u64 ll_handle = SESSION_INVALID_HANDLE;
+ app_listener_t *app_listener;
app_worker_t *app_wrk;
application_t *app;
int rv;
app = application_get_if_valid (a->app_index);
if (!app)
- {
- SESSION_DBG ("app not attached");
- return VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
- }
+ return VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
+
app_wrk = application_get_worker (app, a->wrk_map_index);
+ if (!app_wrk)
+ return VNET_API_ERROR_INVALID_VALUE;
+
a->sep_ext.app_wrk_index = app_wrk->wrk_index;
session_endpoint_update_for_app (&a->sep_ext, app, 0 /* is_connect */ );
@@ -209,87 +196,71 @@ vnet_bind_inline (vnet_bind_args_t * a)
return VNET_API_ERROR_INVALID_VALUE_2;
/*
- * Add session endpoint to local session table. Only binds to "inaddr_any"
- * (i.e., zero address) are added to local scope table.
+ * Check if we already have an app listener
*/
- if (application_has_local_scope (app)
- && session_endpoint_is_local (&a->sep))
+ app_listener = app_listener_lookup (app, &a->sep_ext);
+ if (app_listener)
{
- if ((rv = application_start_local_listen (app, &a->sep_ext,
- &a->handle)))
- return rv;
- ll_handle = a->handle;
+ if (app_listener->app_index != app->app_index)
+ return VNET_API_ERROR_ADDRESS_IN_USE;
+ if (app_worker_start_listen (app_wrk, app_listener))
+ return -1;
+ a->handle = app_listener_handle (app_listener);
+ return 0;
}
- if (!application_has_global_scope (app))
- return (ll_handle == SESSION_INVALID_HANDLE ? -1 : 0);
-
/*
- * Add session endpoint to global session table
+ * Create new app listener
*/
+ if ((rv = app_listener_alloc_and_init (app, &a->sep_ext, &app_listener)))
+ return rv;
- /* Setup listen path down to transport */
- rv = application_start_listen (app, &a->sep_ext, &a->handle);
- if (rv && ll_handle != SESSION_INVALID_HANDLE)
+ if ((rv = app_worker_start_listen (app_wrk, app_listener)))
{
- application_stop_local_listen (a->app_index, a->wrk_map_index,
- ll_handle);
+ app_listener_cleanup (app_listener);
return rv;
}
- /*
- * Store in local table listener the index of the transport layer
- * listener. We'll need if if local listeners are hit and we need to
- * return global handle
- */
- if (ll_handle != SESSION_INVALID_HANDLE)
- {
- local_session_t *ll;
- session_t *tl;
- ll = application_get_local_listener_w_handle (ll_handle);
- tl = listen_session_get_from_handle (a->handle);
- if (ll->transport_listener_index == ~0)
- ll->transport_listener_index = tl->session_index;
- }
- return rv;
+ a->handle = app_listener_handle (app_listener);
+ return 0;
}
static inline int
-vnet_unbind_inline (vnet_unbind_args_t * a)
+vnet_unlisten_inline (vnet_unbind_args_t * a)
{
+ app_worker_t *app_wrk;
+ app_listener_t *al;
application_t *app;
- int rv;
if (!(app = application_get_if_valid (a->app_index)))
+ return VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
+
+ al = app_listener_get_w_handle (a->handle);
+ if (al->app_index != app->app_index)
{
- SESSION_DBG ("app (%d) not attached", wrk_map_index);
- return VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
+ clib_warning ("app doesn't own handle %llu!", a->handle);
+ return -1;
}
- if (application_has_local_scope (app))
+ app_wrk = application_get_worker (app, a->wrk_map_index);
+ if (!app_wrk)
{
- if ((rv = application_stop_local_listen (a->app_index,
- a->wrk_map_index, a->handle)))
- return rv;
+ clib_warning ("no app %u worker %u", app->app_index, a->wrk_map_index);
+ return -1;
}
- /*
- * Clear the global scope table of the listener
- */
- if (application_has_global_scope (app))
- return application_stop_listen (a->app_index, a->wrk_map_index,
- a->handle);
- return 0;
+ return app_worker_stop_listen (app_wrk, al);
}
static int
application_connect (vnet_connect_args_t * a)
{
app_worker_t *server_wrk, *client_wrk;
- u32 table_index, server_index, li;
- session_t *listener;
- application_t *client, *server;
+ application_t *client;
local_session_t *ll;
+ app_listener_t *al;
+ u32 table_index;
+ session_t *ls;
u8 fib_proto;
u64 lh;
@@ -315,24 +286,20 @@ application_connect (vnet_connect_args_t * a)
if (lh == SESSION_INVALID_HANDLE)
goto global_scope;
- local_session_parse_handle (lh, &server_index, &li);
+ ll = application_get_local_listener_w_handle (lh);
+ al = app_listener_get_w_session ((session_t *) ll);
/*
* Break loop if rule in local table points to connecting app. This
* can happen if client is a generic proxy. Route connect through
* global table instead.
*/
- if (server_index != a->app_index)
- {
- server = application_get (server_index);
- ll = application_get_local_listen_session (server, li);
- listener = (session_t *) ll;
- server_wrk = application_listener_select_worker (listener,
- 1 /* is_local */ );
- return app_worker_local_session_connect (client_wrk,
- server_wrk, ll,
- a->api_context);
- }
+ if (al->app_index == a->app_index)
+ goto global_scope;
+
+ server_wrk = app_listener_select_worker (al);
+ return app_worker_local_session_connect (client_wrk, server_wrk, ll,
+ a->api_context);
}
/*
@@ -349,12 +316,12 @@ global_scope:
fib_proto = session_endpoint_fib_proto (&a->sep);
table_index = application_session_table (client, fib_proto);
- listener = session_lookup_listener (table_index, &a->sep);
- if (listener)
+ ls = session_lookup_listener (table_index, &a->sep);
+ if (ls)
{
- server_wrk = application_listener_select_worker (listener,
- 0 /* is_local */ );
- ll = (local_session_t *) listener;
+ al = app_listener_get_w_session (ls);
+ server_wrk = app_listener_select_worker (al);
+ ll = (local_session_t *) ls;
return app_worker_local_session_connect (client_wrk, server_wrk, ll,
a->api_context);
}
@@ -362,7 +329,7 @@ global_scope:
/*
* Not connecting to a local server, propagate to transport
*/
- if (app_worker_open_session (client_wrk, &a->sep, a->api_context))
+ if (app_worker_connect_session (client_wrk, &a->sep, a->api_context))
return VNET_API_ERROR_SESSION_CONNECT;
return 0;
}
@@ -586,7 +553,7 @@ vnet_application_detach (vnet_app_detach_args_t * a)
}
int
-vnet_bind_uri (vnet_bind_args_t * a)
+vnet_bind_uri (vnet_listen_args_t * a)
{
session_endpoint_cfg_t sep = SESSION_ENDPOINT_CFG_NULL;
int rv;
@@ -596,7 +563,7 @@ vnet_bind_uri (vnet_bind_args_t * a)
return rv;
sep.app_wrk_index = 0;
clib_memcpy (&a->sep_ext, &sep, sizeof (sep));
- return vnet_bind_inline (a);
+ return vnet_listen_inline (a);
}
int
@@ -619,7 +586,7 @@ vnet_unbind_uri (vnet_unbind_args_t * a)
if (!listener)
return VNET_API_ERROR_ADDRESS_NOT_IN_USE;
a->handle = listen_session_get_handle (listener);
- return vnet_unbind_inline (a);
+ return vnet_unlisten_inline (a);
}
clib_error_t *
@@ -675,19 +642,19 @@ vnet_disconnect_session (vnet_disconnect_args_t * a)
}
clib_error_t *
-vnet_bind (vnet_bind_args_t * a)
+vnet_listen (vnet_listen_args_t * a)
{
int rv;
- if ((rv = vnet_bind_inline (a)))
+ if ((rv = vnet_listen_inline (a)))
return clib_error_return_code (0, rv, 0, "bind failed: %d", rv);
return 0;
}
clib_error_t *
-vnet_unbind (vnet_unbind_args_t * a)
+vnet_unlisten (vnet_unbind_args_t * a)
{
int rv;
- if ((rv = vnet_unbind_inline (a)))
+ if ((rv = vnet_unlisten_inline (a)))
return clib_error_return_code (0, rv, 0, "unbind failed: %d", rv);
return 0;
}
diff --git a/src/vnet/session/application_interface.h b/src/vnet/session/application_interface.h
index 8ecb0050592..ac6895ea50b 100644
--- a/src/vnet/session/application_interface.h
+++ b/src/vnet/session/application_interface.h
@@ -16,7 +16,7 @@
#define __included_uri_h__
#include <svm/svm_fifo_segment.h>
-#include <vnet/session/session.h>
+#include <vnet/session/session_types.h>
#include <vnet/session/application.h>
#include <vnet/session/transport.h>
#include <vnet/tls/tls.h>
@@ -56,7 +56,7 @@ typedef struct _vnet_bind_args_t
u32 segment_name_length;
u64 server_event_queue_address;
u64 handle;
-} vnet_bind_args_t;
+} vnet_listen_args_t;
typedef struct _vnet_unbind_args_t
{
@@ -167,14 +167,14 @@ typedef enum session_fd_flag_
#undef _
} session_fd_flag_t;
-int vnet_bind_uri (vnet_bind_args_t *);
+int vnet_bind_uri (vnet_listen_args_t *);
int vnet_unbind_uri (vnet_unbind_args_t * a);
clib_error_t *vnet_connect_uri (vnet_connect_args_t * a);
clib_error_t *vnet_application_attach (vnet_app_attach_args_t * a);
-clib_error_t *vnet_bind (vnet_bind_args_t * a);
+clib_error_t *vnet_listen (vnet_listen_args_t * a);
clib_error_t *vnet_connect (vnet_connect_args_t * a);
-clib_error_t *vnet_unbind (vnet_unbind_args_t * a);
+clib_error_t *vnet_unlisten (vnet_unbind_args_t * a);
int vnet_application_detach (vnet_app_detach_args_t * a);
int vnet_disconnect_session (vnet_disconnect_args_t * a);
diff --git a/src/vnet/session/application_worker.c b/src/vnet/session/application_worker.c
index 89ee6057172..44e0d399433 100644
--- a/src/vnet/session/application_worker.c
+++ b/src/vnet/session/application_worker.c
@@ -164,15 +164,18 @@ app_worker_free (app_worker_t * app_wrk)
segment_manager_t *sm;
u32 sm_index;
int i;
+ app_listener_t *al;
+ session_t *ls;
/*
* Listener cleanup
*/
/* *INDENT-OFF* */
- hash_foreach (handle, sm_index, app_wrk->listeners_table,
- ({
- vec_add1 (handles, handle);
+ hash_foreach (handle, sm_index, app_wrk->listeners_table, ({
+ ls = listen_session_get_from_handle (handle);
+ al = app_listener_get (app, ls->al_index);
+ vec_add1 (handles, app_listener_handle (al));
sm = segment_manager_get (sm_index);
sm->app_wrk_index = SEGMENT_MANAGER_INVALID_APP_INDEX;
}));
@@ -184,7 +187,7 @@ app_worker_free (app_worker_t * app_wrk)
a->wrk_map_index = app_wrk->wrk_map_index;
a->handle = handles[i];
/* seg manager is removed when unbind completes */
- vnet_unbind (a);
+ vnet_unlisten (a);
}
/*
@@ -252,54 +255,97 @@ app_worker_alloc_segment_manager (app_worker_t * app_wrk)
}
int
-app_worker_start_listen (app_worker_t * app_wrk, session_t * ls)
+app_worker_start_listen (app_worker_t * app_wrk,
+ app_listener_t * app_listener)
{
segment_manager_t *sm;
+ session_t *ls;
+
+ if (clib_bitmap_get (app_listener->workers, app_wrk->wrk_map_index))
+ return VNET_API_ERROR_ADDRESS_IN_USE;
+
+ app_listener->workers = clib_bitmap_set (app_listener->workers,
+ app_wrk->wrk_map_index, 1);
+
+ if (app_listener->session_index == SESSION_INVALID_INDEX)
+ return 0;
+
+ ls = session_get (app_listener->session_index, 0);
/* Allocate segment manager. All sessions derived out of a listen session
* have fifos allocated by the same segment manager. */
if (!(sm = app_worker_alloc_segment_manager (app_wrk)))
return -1;
- /* Add to app's listener table. Useful to find all child listeners
- * when app goes down, although, just for unbinding this is not needed */
+ /* Keep track of the segment manager for the listener or this worker */
hash_set (app_wrk->listeners_table, listen_session_get_handle (ls),
segment_manager_index (sm));
- if (!ls->rx_fifo
- && session_transport_service_type (ls) == TRANSPORT_SERVICE_CL)
+ if (session_transport_service_type (ls) == TRANSPORT_SERVICE_CL)
{
- if (session_alloc_fifos (sm, ls))
+ if (!ls->rx_fifo && session_alloc_fifos (sm, ls))
return -1;
}
return 0;
}
int
-app_worker_stop_listen (app_worker_t * app_wrk, session_handle_t handle)
+app_worker_stop_listen (app_worker_t * app_wrk, app_listener_t * al)
{
+ session_handle_t handle;
segment_manager_t *sm;
uword *sm_indexp;
- sm_indexp = hash_get (app_wrk->listeners_table, handle);
- if (PREDICT_FALSE (!sm_indexp))
- {
- clib_warning ("listener handle was removed %llu!", handle);
- return -1;
- }
+ if (!clib_bitmap_get (al->workers, app_wrk->wrk_map_index))
+ return 0;
- sm = segment_manager_get (*sm_indexp);
- if (app_wrk->first_segment_manager == *sm_indexp)
+ if (al->session_index != SESSION_INVALID_INDEX)
{
- /* Delete sessions but don't remove segment manager */
- app_wrk->first_segment_manager_in_use = 0;
- segment_manager_del_sessions (sm);
+ session_t *ls;
+
+ ls = listen_session_get (al->session_index);
+ handle = listen_session_get_handle (ls);
+
+ sm_indexp = hash_get (app_wrk->listeners_table, handle);
+ if (PREDICT_FALSE (!sm_indexp))
+ {
+ clib_warning ("listener handle was removed %llu!", handle);
+ return -1;
+ }
+
+ sm = segment_manager_get (*sm_indexp);
+ if (app_wrk->first_segment_manager == *sm_indexp)
+ {
+ /* Delete sessions but don't remove segment manager */
+ app_wrk->first_segment_manager_in_use = 0;
+ segment_manager_del_sessions (sm);
+ }
+ else
+ {
+ segment_manager_init_del (sm);
+ }
+ hash_unset (app_wrk->listeners_table, handle);
}
- else
+
+ if (al->local_index != SESSION_INVALID_INDEX)
{
- segment_manager_init_del (sm);
+ local_session_t *ll, *ls;
+ application_t *app;
+
+ app = application_get (app_wrk->app_index);
+ ll = application_get_local_listen_session (app, al->local_index);
+
+ /* *INDENT-OFF* */
+ pool_foreach (ls, app_wrk->local_sessions, ({
+ if (ls->listener_index == ll->session_index)
+ app_worker_local_session_disconnect (app_wrk->app_index, ls);
+ }));
+ /* *INDENT-ON* */
}
- hash_unset (app_wrk->listeners_table, handle);
+
+ clib_bitmap_set_no_check (al->workers, app_wrk->wrk_map_index, 0);
+ if (clib_bitmap_is_zero (al->workers))
+ app_listener_cleanup (al);
return 0;
}
@@ -350,8 +396,8 @@ app_worker_own_session (app_worker_t * app_wrk, session_t * s)
}
int
-app_worker_open_session (app_worker_t * app, session_endpoint_t * sep,
- u32 api_context)
+app_worker_connect_session (app_worker_t * app, session_endpoint_t * sep,
+ u32 api_context)
{
int rv;
@@ -405,7 +451,7 @@ app_worker_get_listen_segment_manager (app_worker_t * app,
}
session_t *
-app_worker_first_listener (app_worker_t * app, u8 fib_proto,
+app_worker_first_listener (app_worker_t * app_wrk, u8 fib_proto,
u8 transport_proto)
{
session_t *listener;
@@ -417,7 +463,7 @@ app_worker_first_listener (app_worker_t * app, u8 fib_proto,
fib_proto == FIB_PROTOCOL_IP4);
/* *INDENT-OFF* */
- hash_foreach (handle, sm_index, app->listeners_table, ({
+ hash_foreach (handle, sm_index, app_wrk->listeners_table, ({
listener = listen_session_get_from_handle (handle);
if (listener->session_type == sst
&& listener->enqueue_epoch != SESSION_PROXY_LISTENER_INDEX)
@@ -429,7 +475,7 @@ app_worker_first_listener (app_worker_t * app, u8 fib_proto,
}
session_t *
-app_worker_proxy_listener (app_worker_t * app, u8 fib_proto,
+app_worker_proxy_listener (app_worker_t * app_wrk, u8 fib_proto,
u8 transport_proto)
{
session_t *listener;
@@ -441,7 +487,7 @@ app_worker_proxy_listener (app_worker_t * app, u8 fib_proto,
fib_proto == FIB_PROTOCOL_IP4);
/* *INDENT-OFF* */
- hash_foreach (handle, sm_index, app->listeners_table, ({
+ hash_foreach (handle, sm_index, app_wrk->listeners_table, ({
listener = listen_session_get_from_handle (handle);
if (listener->session_type == sst
&& listener->enqueue_epoch == SESSION_PROXY_LISTENER_INDEX)
@@ -1040,6 +1086,7 @@ void
app_worker_format_local_sessions (app_worker_t * app_wrk, int verbose)
{
vlib_main_t *vm = vlib_get_main ();
+ app_worker_t *client_wrk;
local_session_t *ls;
transport_proto_t tp;
u8 *conn = 0;
@@ -1061,8 +1108,9 @@ app_worker_format_local_sessions (app_worker_t * app_wrk, int verbose)
tp = session_type_transport_proto(ls->listener_session_type);
conn = format (0, "[L][%U] *:%u", format_transport_proto_short, tp,
ls->port);
- vlib_cli_output (vm, "%-40v%-15u%-20u", conn, ls->app_wrk_index,
- ls->client_wrk_index);
+ client_wrk = app_worker_get (ls->client_wrk_index);
+ vlib_cli_output (vm, "%-40v%-15u%-20u", conn, ls->app_index,
+ client_wrk->app_index);
vec_reset_length (conn);
}));
/* *INDENT-ON* */
diff --git a/src/vnet/session/session.c b/src/vnet/session/session.c
index 6833a93e12b..532a242cc5f 100644
--- a/src/vnet/session/session.c
+++ b/src/vnet/session/session.c
@@ -945,7 +945,7 @@ session_transport_reset_notify (transport_connection_t * tc)
* Accept a stream session. Optionally ping the server by callback.
*/
int
-stream_session_accept (transport_connection_t * tc, u32 listener_index,
+session_stream_accept (transport_connection_t * tc, u32 listener_index,
u8 notify)
{
session_t *s, *listener;
@@ -955,7 +955,7 @@ stream_session_accept (transport_connection_t * tc, u32 listener_index,
/* Find the server */
listener = listen_session_get (listener_index);
- app_wrk = application_listener_select_worker (listener, 0);
+ app_wrk = application_listener_select_worker (listener);
sm = app_worker_get_listen_segment_manager (app_wrk, listener);
if ((rv = session_alloc_and_init (sm, tc, 1, &s)))
@@ -1119,7 +1119,7 @@ session_listen (session_t * ls, session_endpoint_cfg_t * sep)
/* Add to the main lookup table after transport was initialized */
tc = transport_get_listener (sep->transport_proto, tc_index);
- session_lookup_add_connection (tc, s_index);
+ session_lookup_add_connection (tc, listen_session_get_handle (ls));
return 0;
}
diff --git a/src/vnet/session/session.h b/src/vnet/session/session.h
index c622e4eb74a..7722f4f03e3 100644
--- a/src/vnet/session/session.h
+++ b/src/vnet/session/session.h
@@ -23,58 +23,6 @@
#define SESSION_PROXY_LISTENER_INDEX ((u8)~0 - 1)
-typedef enum
-{
- FIFO_EVENT_APP_RX,
- SESSION_IO_EVT_CT_RX,
- FIFO_EVENT_APP_TX,
- SESSION_IO_EVT_CT_TX,
- SESSION_IO_EVT_TX_FLUSH,
- FIFO_EVENT_DISCONNECT,
- FIFO_EVENT_BUILTIN_RX,
- FIFO_EVENT_BUILTIN_TX,
- FIFO_EVENT_RPC,
- SESSION_CTRL_EVT_BOUND,
- SESSION_CTRL_EVT_ACCEPTED,
- SESSION_CTRL_EVT_ACCEPTED_REPLY,
- SESSION_CTRL_EVT_CONNECTED,
- SESSION_CTRL_EVT_CONNECTED_REPLY,
- SESSION_CTRL_EVT_DISCONNECTED,
- SESSION_CTRL_EVT_DISCONNECTED_REPLY,
- SESSION_CTRL_EVT_RESET,
- SESSION_CTRL_EVT_RESET_REPLY,
- SESSION_CTRL_EVT_REQ_WORKER_UPDATE,
- SESSION_CTRL_EVT_WORKER_UPDATE,
- SESSION_CTRL_EVT_WORKER_UPDATE_REPLY,
-} session_evt_type_t;
-
-static inline const char *
-fifo_event_type_str (session_evt_type_t et)
-{
- switch (et)
- {
- case FIFO_EVENT_APP_RX:
- return "FIFO_EVENT_APP_RX";
- case FIFO_EVENT_APP_TX:
- return "FIFO_EVENT_APP_TX";
- case FIFO_EVENT_DISCONNECT:
- return "FIFO_EVENT_DISCONNECT";
- case FIFO_EVENT_BUILTIN_RX:
- return "FIFO_EVENT_BUILTIN_RX";
- case FIFO_EVENT_RPC:
- return "FIFO_EVENT_RPC";
- default:
- return "UNKNOWN FIFO EVENT";
- }
-}
-
-typedef enum
-{
- SESSION_MQ_IO_EVT_RING,
- SESSION_MQ_CTRL_EVT_RING,
- SESSION_MQ_N_RINGS
-} session_mq_rings_e;
-
#define foreach_session_input_error \
_(NO_SESSION, "No session drops") \
_(NO_LISTENER, "No listener for dst port drops") \
@@ -95,57 +43,6 @@ typedef enum
SESSION_N_ERROR,
} session_error_t;
-typedef struct
-{
- void *fp;
- void *arg;
-} session_rpc_args_t;
-
-/* *INDENT-OFF* */
-typedef struct
-{
- u8 event_type;
- u8 postponed;
- union
- {
- svm_fifo_t *fifo;
- session_handle_t session_handle;
- session_rpc_args_t rpc_args;
- struct
- {
- u8 data[0];
- };
- };
-} __clib_packed session_event_t;
-/* *INDENT-ON* */
-
-#define SESSION_MSG_NULL { }
-
-typedef struct session_dgram_pre_hdr_
-{
- u32 data_length;
- u32 data_offset;
-} session_dgram_pre_hdr_t;
-
-/* *INDENT-OFF* */
-typedef CLIB_PACKED (struct session_dgram_header_
-{
- u32 data_length;
- u32 data_offset;
- ip46_address_t rmt_ip;
- ip46_address_t lcl_ip;
- u16 rmt_port;
- u16 lcl_port;
- u8 is_ip4;
-}) session_dgram_hdr_t;
-/* *INDENT-ON* */
-
-#define SESSION_CONN_ID_LEN 37
-#define SESSION_CONN_HDR_LEN 45
-
-STATIC_ASSERT (sizeof (session_dgram_hdr_t) == (SESSION_CONN_ID_LEN + 8),
- "session conn id wrong length");
-
typedef struct session_tx_context_
{
CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
@@ -493,7 +390,7 @@ void session_transport_closing_notify (transport_connection_t * tc);
void session_transport_delete_notify (transport_connection_t * tc);
void session_transport_closed_notify (transport_connection_t * tc);
void session_transport_reset_notify (transport_connection_t * tc);
-int stream_session_accept (transport_connection_t * tc, u32 listener_index,
+int session_stream_accept (transport_connection_t * tc, u32 listener_index,
u8 notify);
u32 session_tx_fifo_max_dequeue (transport_connection_t * tc);
void session_register_transport (transport_proto_t transport_proto,
diff --git a/src/vnet/session/session_api.c b/src/vnet/session/session_api.c
index 8196f4ca142..6a845519b83 100755
--- a/src/vnet/session/session_api.c
+++ b/src/vnet/session/session_api.c
@@ -19,6 +19,7 @@
#include <vnet/session/application_interface.h>
#include <vnet/session/session_rules_table.h>
#include <vnet/session/session_table.h>
+#include <vnet/session/session.h>
#include <vnet/vnet_msg_enum.h>
@@ -207,6 +208,7 @@ send_session_accept_callback (session_t * s)
session_t *listener;
svm_msg_q_t *vpp_queue;
application_t *server;
+ app_listener_t *al;
server = application_get (server_wrk->app_index);
reg =
@@ -228,7 +230,8 @@ send_session_accept_callback (session_t * s)
if (session_has_transport (s))
{
listener = listen_session_get (s->listener_index);
- mp->listener_handle = listen_session_get_handle (listener);
+ al = app_listener_get (server, listener->al_index);
+ mp->listener_handle = app_listener_handle (al);
if (application_is_proxy (server))
{
listener =
@@ -253,22 +256,16 @@ send_session_accept_callback (session_t * s)
if (application_local_session_listener_has_transport (ls))
{
listener = listen_session_get (ls->listener_index);
- mp->listener_handle = listen_session_get_handle (listener);
+ al = app_listener_get (server, listener->al_index);
+ mp->listener_handle = app_listener_handle (al);
mp->is_ip4 = session_type_is_ip4 (listener->session_type);
}
else
{
ll = application_get_local_listen_session (server,
ls->listener_index);
- if (ll->transport_listener_index != ~0)
- {
- listener = listen_session_get (ll->transport_listener_index);
- mp->listener_handle = listen_session_get_handle (listener);
- }
- else
- {
- mp->listener_handle = application_local_session_handle (ll);
- }
+ al = app_listener_get (server, ll->al_index);
+ mp->listener_handle = app_listener_handle (al);
mp->is_ip4 = session_type_is_ip4 (ll->listener_session_type);
}
mp->handle = application_local_session_handle (ls);
@@ -424,6 +421,7 @@ mq_send_session_accepted_cb (session_t * s)
session_accepted_msg_t *mp;
session_event_t *evt;
application_t *app;
+ app_listener_t *al;
app = application_get (app_wrk->app_index);
app_mq = app_wrk->event_queue;
@@ -443,7 +441,8 @@ mq_send_session_accepted_cb (session_t * s)
if (session_has_transport (s))
{
listener = listen_session_get (s->listener_index);
- mp->listener_handle = listen_session_get_handle (listener);
+ al = app_listener_get (app, listener->al_index);
+ mp->listener_handle = app_listener_handle (al);
if (application_is_proxy (app))
{
listener =
@@ -475,21 +474,15 @@ mq_send_session_accepted_cb (session_t * s)
if (application_local_session_listener_has_transport (ls))
{
listener = listen_session_get (ls->listener_index);
- mp->listener_handle = listen_session_get_handle (listener);
+ al = app_listener_get (app, listener->al_index);
+ mp->listener_handle = app_listener_handle (al);
mp->is_ip4 = session_type_is_ip4 (listener->session_type);
}
else
{
ll = application_get_local_listen_session (app, ls->listener_index);
- if (ll->transport_listener_index != ~0)
- {
- listener = listen_session_get (ll->transport_listener_index);
- mp->listener_handle = listen_session_get_handle (listener);
- }
- else
- {
- mp->listener_handle = application_local_session_handle (ll);
- }
+ al = app_listener_get (app, ll->al_index);
+ mp->listener_handle = app_listener_handle (al);
mp->is_ip4 = session_type_is_ip4 (ll->listener_session_type);
}
mp->handle = application_local_session_handle (ls);
@@ -674,11 +667,12 @@ mq_send_session_bound_cb (u32 app_wrk_index, u32 api_context,
svm_msg_q_msg_t _msg, *msg = &_msg;
svm_msg_q_t *app_mq, *vpp_evt_q;
transport_connection_t *tc;
- session_t *ls = 0;
session_bound_msg_t *mp;
app_worker_t *app_wrk;
session_event_t *evt;
application_t *app;
+ app_listener_t *al;
+ session_t *ls = 0;
app_wrk = app_worker_get (app_wrk_index);
app = application_get (app_wrk->app_index);
@@ -705,7 +699,8 @@ mq_send_session_bound_cb (u32 app_wrk_index, u32 api_context,
mp->handle = handle;
if (application_has_global_scope (app))
{
- ls = listen_session_get_from_handle (handle);
+ al = app_listener_get_w_handle (handle);
+ ls = app_listener_get_session (al);
tc = listen_session_get_transport (ls);
mp->lcl_port = tc->lcl_port;
mp->lcl_is_ip4 = tc->is_ip4;
@@ -888,7 +883,7 @@ static void
vl_api_bind_uri_t_handler (vl_api_bind_uri_t * mp)
{
transport_connection_t *tc = 0;
- vnet_bind_args_t _a, *a = &_a;
+ vnet_listen_args_t _a, *a = &_a;
vl_api_bind_uri_reply_t *rmp;
session_t *s;
application_t *app = 0;
@@ -1180,16 +1175,17 @@ vl_api_map_another_segment_reply_t_handler (vl_api_map_another_segment_reply_t
static void
vl_api_bind_sock_t_handler (vl_api_bind_sock_t * mp)
{
+ vnet_listen_args_t _a, *a = &_a;
+ transport_connection_t *tc = 0;
vl_api_bind_sock_reply_t *rmp;
- vnet_bind_args_t _a, *a = &_a;
- int rv = 0;
- clib_error_t *error;
+ svm_msg_q_t *vpp_evt_q;
application_t *app = 0;
app_worker_t *app_wrk;
- session_t *s;
- transport_connection_t *tc = 0;
ip46_address_t *ip46;
- svm_msg_q_t *vpp_evt_q;
+ clib_error_t *error;
+ app_listener_t *al;
+ session_t *s;
+ int rv = 0;
if (session_manager_is_enabled () == 0)
{
@@ -1215,7 +1211,7 @@ vl_api_bind_sock_t_handler (vl_api_bind_sock_t * mp)
a->app_index = app->app_index;
a->wrk_map_index = mp->wrk_index;
- if ((error = vnet_bind (a)))
+ if ((error = vnet_listen (a)))
{
rv = clib_error_get_code (error);
clib_error_report (error);
@@ -1231,7 +1227,8 @@ done:
rmp->lcl_is_ip4 = mp->is_ip4;
if (app && application_has_global_scope (app))
{
- s = listen_session_get_from_handle (a->handle);
+ al = app_listener_get_w_handle (a->handle);
+ s = app_listener_get_session (al);
tc = listen_session_get_transport (s);
clib_memcpy_fast (rmp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
if (session_transport_service_type (s) == TRANSPORT_SERVICE_CL)
@@ -1276,7 +1273,7 @@ vl_api_unbind_sock_t_handler (vl_api_unbind_sock_t * mp)
a->app_index = app->app_index;
a->handle = mp->handle;
a->wrk_map_index = mp->wrk_index;
- if ((error = vnet_unbind (a)))
+ if ((error = vnet_unlisten (a)))
{
rv = clib_error_get_code (error);
clib_error_report (error);
diff --git a/src/vnet/session/session_types.h b/src/vnet/session/session_types.h
index 286f4c49d80..846af25c777 100644
--- a/src/vnet/session/session_types.h
+++ b/src/vnet/session/session_types.h
@@ -19,7 +19,8 @@
#include <svm/svm_fifo.h>
#include <vnet/session/transport_types.h>
-#define SESSION_LOCAL_HANDLE_PREFIX 0x7FFFFFFF
+#define SESSION_LOCAL_HANDLE_PREFIX 0x7FFFFFFF
+#define SESSION_LISTENER_PREFIX 0x5FFFFFFF
#define foreach_session_endpoint_fields \
foreach_transport_endpoint_cfg_fields \
@@ -91,6 +92,19 @@ session_endpoint_fib_proto (session_endpoint_t * sep)
return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
}
+static inline u8
+session_endpoint_is_local (session_endpoint_t * sep)
+{
+ return (ip_is_zero (&sep->ip, sep->is_ip4)
+ || ip_is_local_host (&sep->ip, sep->is_ip4));
+}
+
+static inline u8
+session_endpoint_is_zero (session_endpoint_t * sep)
+{
+ return ip_is_zero (&sep->ip, sep->is_ip4);
+}
+
typedef u8 session_type_t;
typedef u64 session_handle_t;
@@ -164,8 +178,8 @@ typedef struct session_
/** Transport app index for apps acting as transports */
u32 t_app_index;
- /** Index in listener app's listener db */
- u32 listener_db_index;
+ /** App listener index */
+ u32 al_index;
/** Opaque, for general use */
u32 opaque;
@@ -303,7 +317,7 @@ typedef struct local_session_
u32 app_index;
};
- u32 listener_db_index;
+ u32 al_index;
/** Has transport embedded when listener not purely local */
session_type_t listener_session_type;
@@ -364,6 +378,108 @@ application_local_session_handle (local_session_t * ls)
| (u64) local_session_id (ls);
}
+typedef enum
+{
+ FIFO_EVENT_APP_RX,
+ SESSION_IO_EVT_CT_RX,
+ FIFO_EVENT_APP_TX,
+ SESSION_IO_EVT_CT_TX,
+ SESSION_IO_EVT_TX_FLUSH,
+ FIFO_EVENT_DISCONNECT,
+ FIFO_EVENT_BUILTIN_RX,
+ FIFO_EVENT_BUILTIN_TX,
+ FIFO_EVENT_RPC,
+ SESSION_CTRL_EVT_BOUND,
+ SESSION_CTRL_EVT_ACCEPTED,
+ SESSION_CTRL_EVT_ACCEPTED_REPLY,
+ SESSION_CTRL_EVT_CONNECTED,
+ SESSION_CTRL_EVT_CONNECTED_REPLY,
+ SESSION_CTRL_EVT_DISCONNECTED,
+ SESSION_CTRL_EVT_DISCONNECTED_REPLY,
+ SESSION_CTRL_EVT_RESET,
+ SESSION_CTRL_EVT_RESET_REPLY,
+ SESSION_CTRL_EVT_REQ_WORKER_UPDATE,
+ SESSION_CTRL_EVT_WORKER_UPDATE,
+ SESSION_CTRL_EVT_WORKER_UPDATE_REPLY,
+} session_evt_type_t;
+
+static inline const char *
+fifo_event_type_str (session_evt_type_t et)
+{
+ switch (et)
+ {
+ case FIFO_EVENT_APP_RX:
+ return "FIFO_EVENT_APP_RX";
+ case FIFO_EVENT_APP_TX:
+ return "FIFO_EVENT_APP_TX";
+ case FIFO_EVENT_DISCONNECT:
+ return "FIFO_EVENT_DISCONNECT";
+ case FIFO_EVENT_BUILTIN_RX:
+ return "FIFO_EVENT_BUILTIN_RX";
+ case FIFO_EVENT_RPC:
+ return "FIFO_EVENT_RPC";
+ default:
+ return "UNKNOWN FIFO EVENT";
+ }
+}
+
+typedef enum
+{
+ SESSION_MQ_IO_EVT_RING,
+ SESSION_MQ_CTRL_EVT_RING,
+ SESSION_MQ_N_RINGS
+} session_mq_rings_e;
+
+typedef struct
+{
+ void *fp;
+ void *arg;
+} session_rpc_args_t;
+
+/* *INDENT-OFF* */
+typedef struct
+{
+ u8 event_type;
+ u8 postponed;
+ union
+ {
+ svm_fifo_t *fifo;
+ session_handle_t session_handle;
+ session_rpc_args_t rpc_args;
+ struct
+ {
+ u8 data[0];
+ };
+ };
+} __clib_packed session_event_t;
+/* *INDENT-ON* */
+
+#define SESSION_MSG_NULL { }
+
+typedef struct session_dgram_pre_hdr_
+{
+ u32 data_length;
+ u32 data_offset;
+} session_dgram_pre_hdr_t;
+
+/* *INDENT-OFF* */
+typedef CLIB_PACKED (struct session_dgram_header_
+{
+ u32 data_length;
+ u32 data_offset;
+ ip46_address_t rmt_ip;
+ ip46_address_t lcl_ip;
+ u16 rmt_port;
+ u16 lcl_port;
+ u8 is_ip4;
+}) session_dgram_hdr_t;
+/* *INDENT-ON* */
+
+#define SESSION_CONN_ID_LEN 37
+#define SESSION_CONN_HDR_LEN 45
+
+STATIC_ASSERT (sizeof (session_dgram_hdr_t) == (SESSION_CONN_ID_LEN + 8),
+ "session conn id wrong length");
#endif /* SRC_VNET_SESSION_SESSION_TYPES_H_ */
/*
diff --git a/src/vnet/tcp/tcp_input.c b/src/vnet/tcp/tcp_input.c
index 2aeec2f3846..da03cababb7 100644
--- a/src/vnet/tcp/tcp_input.c
+++ b/src/vnet/tcp/tcp_input.c
@@ -3147,7 +3147,7 @@ tcp46_listen_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
child0->rto = TCP_RTO_MIN;
TCP_EVT_DBG (TCP_EVT_SYN_RCVD, child0, 1);
- if (stream_session_accept (&child0->connection, lc0->c_s_index,
+ if (session_stream_accept (&child0->connection, lc0->c_s_index,
0 /* notify */ ))
{
tcp_connection_cleanup (child0);
diff --git a/src/vnet/tls/tls.c b/src/vnet/tls/tls.c
index ed12378862d..e36a88476ee 100644
--- a/src/vnet/tls/tls.c
+++ b/src/vnet/tls/tls.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018 Cisco and/or its affiliates.
+ * Copyright (c) 2018-2019 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:
@@ -586,7 +586,7 @@ tls_disconnect (u32 ctx_handle, u32 thread_index)
u32
tls_start_listen (u32 app_listener_index, transport_endpoint_t * tep)
{
- vnet_bind_args_t _bargs, *args = &_bargs;
+ vnet_listen_args_t _bargs, *args = &_bargs;
app_worker_t *app_wrk;
tls_main_t *tm = &tls_main;
session_handle_t tls_handle;
@@ -612,7 +612,7 @@ tls_start_listen (u32 app_listener_index, transport_endpoint_t * tep)
clib_memset (args, 0, sizeof (*args));
args->app_index = tm->app_index;
args->sep_ext = *sep;
- if (vnet_bind (args))
+ if (vnet_listen (args))
return -1;
tls_handle = args->handle;
@@ -648,7 +648,7 @@ tls_stop_listen (u32 lctx_index)
.app_index = tls_main.app_index,
.wrk_map_index = 0 /* default wrk */
};
- if (vnet_unbind (&a))
+ if (vnet_unlisten (&a))
clib_warning ("unbind returned");
engine_type = lctx->tls_ctx_engine;
diff --git a/src/vnet/tls/tls.h b/src/vnet/tls/tls.h
index b9b0e0baa83..83daa426bf1 100644
--- a/src/vnet/tls/tls.h
+++ b/src/vnet/tls/tls.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018 Cisco and/or its affiliates.
+ * Copyright (c) 2018-2019 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:
@@ -15,6 +15,7 @@
#include <vnet/session/application_interface.h>
+#include <vnet/session/session.h>
#include <vppinfra/lock.h>
#ifndef SRC_VNET_TLS_TLS_H_
diff --git a/src/vnet/udp/udp_input.c b/src/vnet/udp/udp_input.c
index bbfee571969..1adefab23f4 100644
--- a/src/vnet/udp/udp_input.c
+++ b/src/vnet/udp/udp_input.c
@@ -207,7 +207,7 @@ udp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
child0->c_rmt_port = udp0->src_port;
child0->c_is_ip4 = is_ip4;
- if (stream_session_accept (&child0->connection,
+ if (session_stream_accept (&child0->connection,
tc0->s_index, 1))
{
error0 = UDP_ERROR_CREATE_SESSION;