aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNathan Skrzypczak <nathan.skrzypczak@gmail.com>2019-06-13 10:14:28 +0200
committerFlorin Coras <florin.coras@gmail.com>2019-06-17 14:05:37 +0000
commit2f0f96b9dbcb198dede1e5ebd4d880129d5d52c8 (patch)
tree41dc5f84d8fadda65234f5c990dbdc78392b0d91 /src
parent8a2fa3b482b2f32da8e0b634fd09c9bdef2e9443 (diff)
session: use listener_handle instead of listener_index
Type: refactor Change-Id: I97fa59a0ba0b6b7a98698926020ffffcf6ae6ba3 Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/quic/quic.c35
-rw-r--r--src/plugins/quic/quic.h1
-rw-r--r--src/plugins/unittest/tcp_test.c2
-rw-r--r--src/tests/vnet/session/quic_echo.c3
-rw-r--r--src/vnet/sctp/sctp_input.c4
-rw-r--r--src/vnet/session/application_local.c4
-rw-r--r--src/vnet/session/application_worker.c2
-rw-r--r--src/vnet/session/session.c5
-rw-r--r--src/vnet/session/session.h2
-rwxr-xr-xsrc/vnet/session/session_api.c4
-rw-r--r--src/vnet/session/session_types.h2
-rw-r--r--src/vnet/tcp/tcp_input.c2
-rw-r--r--src/vnet/tls/tls.c5
-rw-r--r--src/vnet/udp/udp_input.c3
14 files changed, 32 insertions, 42 deletions
diff --git a/src/plugins/quic/quic.c b/src/plugins/quic/quic.c
index ca48a905d0e..a5dbd8d18a3 100644
--- a/src/plugins/quic/quic.c
+++ b/src/plugins/quic/quic.c
@@ -484,12 +484,11 @@ static void
quic_accept_stream (void *s)
{
quicly_stream_t *stream = (quicly_stream_t *) s;
- session_t *stream_session;
+ session_t *stream_session, *quic_session;
quic_stream_data_t *stream_data;
app_worker_t *app_wrk;
quic_ctx_t *qctx, *sctx;
u32 sctx_id;
- quic_main_t *qm = &quic_main;
int rv;
sctx_id = quic_ctx_alloc (vlib_get_thread_index ());
@@ -522,8 +521,8 @@ quic_accept_stream (void *s)
stream_session->session_type =
session_type_from_proto_and_ip (TRANSPORT_PROTO_QUIC,
qctx->c_quic_ctx_id.udp_is_ip4);
- stream_session->listener_index = qm->fake_app_listener_index;
- stream_session->app_index = sctx->c_quic_ctx_id.parent_app_id;
+ quic_session = session_get (qctx->c_s_index, qctx->c_thread_index);
+ stream_session->listener_handle = listen_session_get_handle (quic_session);
app_wrk = app_worker_get (stream_session->app_wrk_index);
if ((rv = app_worker_init_connected (app_wrk, stream_session)))
@@ -1113,7 +1112,6 @@ quic_connect_new_stream (session_endpoint_cfg_t * sep)
app_worker_t *app_wrk;
quic_ctx_t *qctx, *sctx;
u32 sctx_index;
- quic_main_t *qm = &quic_main;
int rv;
/* Find base session to which the user want to attach a stream */
@@ -1174,7 +1172,7 @@ quic_connect_new_stream (session_endpoint_cfg_t * sep)
stream_session->flags |= SESSION_F_QUIC_STREAM;
stream_session->app_wrk_index = app_wrk->wrk_index;
stream_session->connection_index = sctx_index;
- stream_session->listener_index = qm->fake_app_listener_index;
+ stream_session->listener_handle = quic_session_handle;
stream_session->session_type =
session_type_from_proto_and_ip (TRANSPORT_PROTO_QUIC,
qctx->c_quic_ctx_id.udp_is_ip4);
@@ -1480,7 +1478,7 @@ quic_notify_app_connected (quic_ctx_t * ctx)
app_worker_t *app_wrk;
u32 ctx_id = ctx->c_c_index;
u32 thread_index = ctx->c_thread_index;
- quic_main_t *qm = &quic_main;
+ quic_ctx_t *lctx;
app_wrk = app_worker_get_if_valid (ctx->c_quic_ctx_id.parent_app_wrk_id);
if (!app_wrk)
@@ -1491,12 +1489,13 @@ quic_notify_app_connected (quic_ctx_t * ctx)
quic_session = session_alloc (thread_index);
+ lctx = quic_ctx_get (ctx->c_quic_ctx_id.listener_ctx_id, 0);
QUIC_DBG (2, "Allocated quic_session, id %u, thread %u",
quic_session->session_index, quic_session->thread_index);
ctx->c_s_index = quic_session->session_index;
quic_session->app_wrk_index = ctx->c_quic_ctx_id.parent_app_wrk_id;
quic_session->connection_index = ctx->c_c_index;
- quic_session->listener_index = qm->fake_app_listener_index;
+ quic_session->listener_handle = lctx->c_s_index;
quic_session->session_type =
session_type_from_proto_and_ip (TRANSPORT_PROTO_QUIC,
ctx->c_quic_ctx_id.udp_is_ip4);
@@ -1727,7 +1726,8 @@ quic_session_accepted_callback (session_t * udp_session)
session_t *udp_listen_session;
u32 thread_index = vlib_get_thread_index ();
- udp_listen_session = listen_session_get (udp_session->listener_index);
+ udp_listen_session =
+ listen_session_get_from_handle (udp_session->listener_handle);
ctx_index = quic_ctx_alloc (thread_index);
ctx = quic_ctx_get (ctx_index, thread_index);
@@ -1896,7 +1896,6 @@ quic_create_quic_session (quic_ctx_t * ctx)
session_t *quic_session;
app_worker_t *app_wrk;
quic_ctx_t *lctx;
- quic_main_t *qm = &quic_main;
int rv;
quic_session = session_alloc (ctx->c_thread_index);
@@ -1913,8 +1912,7 @@ quic_create_quic_session (quic_ctx_t * ctx)
quic_session->session_type =
session_type_from_proto_and_ip (TRANSPORT_PROTO_QUIC,
ctx->c_quic_ctx_id.udp_is_ip4);
- quic_session->listener_index = qm->fake_app_listener_index;
- quic_session->app_index = quic_main.app_index;
+ quic_session->listener_handle = lctx->c_quic_ctx_id.listener_ctx_id;
/* TODO: don't alloc fifos when we don't transfer data on this session
* but we still need fifos for the events? */
@@ -2233,7 +2231,6 @@ quic_init (vlib_main_t * vm)
quic_main_t *qm = &quic_main;
u32 fifo_size = QUIC_FIFO_SIZE;
u32 num_threads, i;
- application_t *app;
num_threads = 1 /* main thread */ + vtm->n_threads;
@@ -2277,18 +2274,6 @@ quic_init (vlib_main_t * vm)
qm->app_index = a->app_index;
- /* Fake app listener hack, to remove */
- app = application_get (a->app_index);
- app_listener_t *fake_app_listener;
- pool_get (app->listeners, fake_app_listener);
- clib_memset (fake_app_listener, 0, sizeof (*fake_app_listener));
- fake_app_listener->al_index = fake_app_listener - app->listeners;
- fake_app_listener->app_index = app->app_index;
- fake_app_listener->session_index = SESSION_INVALID_INDEX;
- fake_app_listener->local_index = SESSION_INVALID_INDEX;
- qm->fake_app_listener_index = fake_app_listener->al_index;
- /* End fake listener hack */
-
qm->tstamp_ticks_per_clock = vm->clib_time.seconds_per_clock
/ QUIC_TSTAMP_RESOLUTION;
diff --git a/src/plugins/quic/quic.h b/src/plugins/quic/quic.h
index 759dc9f0a4f..3e0f45a4cd5 100644
--- a/src/plugins/quic/quic.h
+++ b/src/plugins/quic/quic.h
@@ -112,7 +112,6 @@ typedef struct quic_main_
quic_worker_ctx_t *wrk_ctx;
clib_bihash_16_8_t connection_hash; /* quicly connection id -> conn handle */
f64 tstamp_ticks_per_clock;
- u32 fake_app_listener_index; /* ugly hack for accept cb */
/*
* Config
diff --git a/src/plugins/unittest/tcp_test.c b/src/plugins/unittest/tcp_test.c
index d7b80e17891..f919790b031 100644
--- a/src/plugins/unittest/tcp_test.c
+++ b/src/plugins/unittest/tcp_test.c
@@ -765,7 +765,7 @@ tcp_test_session (vlib_main_t * vm, unformat_input_t * input)
TCP_EVT_DBG (TCP_EVT_OPEN, tc0);
if (session_stream_accept (&tc0->connection, 0 /* listener index */ ,
- 0 /* notify */ ))
+ 0 /* thread index */ , 0 /* notify */ ))
clib_warning ("stream_session_accept failed");
session_stream_accept_notify (&tc0->connection);
diff --git a/src/tests/vnet/session/quic_echo.c b/src/tests/vnet/session/quic_echo.c
index a0bd9690246..0149448c916 100644
--- a/src/tests/vnet/session/quic_echo.c
+++ b/src/tests/vnet/session/quic_echo.c
@@ -788,7 +788,8 @@ session_accepted_handler (session_accepted_msg_t * mp)
svm_msg_q_t *);
/* Add it to lookup table */
- DBG ("Accepted session handle %lx, idx %lu", mp->handle, session_index);
+ DBG ("Accepted session handle %lx, Listener %lx idx %lu", mp->handle,
+ mp->listener_handle, session_index);
hash_set (em->session_index_by_vpp_handles, mp->handle, session_index);
/*
diff --git a/src/vnet/sctp/sctp_input.c b/src/vnet/sctp/sctp_input.c
index c41e9ccdcae..b102d51083a 100644
--- a/src/vnet/sctp/sctp_input.c
+++ b/src/vnet/sctp/sctp_input.c
@@ -1747,7 +1747,9 @@ sctp46_listen_process_inline (vlib_main_t * vm,
(&child_conn->
sub_conn[SCTP_PRIMARY_PATH_IDX].connection,
sctp_listener->
- sub_conn[SCTP_PRIMARY_PATH_IDX].c_s_index, 0))
+ sub_conn[SCTP_PRIMARY_PATH_IDX].c_s_index,
+ sctp_listener->
+ sub_conn[SCTP_PRIMARY_PATH_IDX].c_thread_index, 0))
{
clib_warning ("session accept fail");
sctp_connection_cleanup (child_conn);
diff --git a/src/vnet/session/application_local.c b/src/vnet/session/application_local.c
index f868e1964cc..2fcf070767c 100644
--- a/src/vnet/session/application_local.c
+++ b/src/vnet/session/application_local.c
@@ -128,7 +128,7 @@ ct_session_connect_notify (session_t * ss)
ss = session_get (ss_index, 0);
cs->session_type = ss->session_type;
cs->connection_index = sct->c_c_index;
- cs->listener_index = SESSION_INVALID_INDEX;
+ cs->listener_handle = SESSION_INVALID_HANDLE;
cs->session_state = SESSION_STATE_CONNECTING;
cs->app_wrk_index = client_wrk->wrk_index;
cs->connection_index = cct->c_c_index;
@@ -280,7 +280,7 @@ ct_connect (app_worker_t * client_wrk, session_t * ll,
ss->session_type = session_type_from_proto_and_ip (TRANSPORT_PROTO_NONE,
sct->c_is_ip4);
ss->connection_index = sct->c_c_index;
- ss->listener_index = ll->session_index;
+ ss->listener_handle = listen_session_get_handle (ll);
ss->session_state = SESSION_STATE_CREATED;
server_wrk = application_listener_select_worker (ll);
diff --git a/src/vnet/session/application_worker.c b/src/vnet/session/application_worker.c
index 6f137e91e55..69b19909b56 100644
--- a/src/vnet/session/application_worker.c
+++ b/src/vnet/session/application_worker.c
@@ -275,7 +275,7 @@ app_worker_init_accepted (session_t * s)
segment_manager_t *sm;
session_t *listener;
- listener = listen_session_get (s->listener_index);
+ listener = listen_session_get_from_handle (s->listener_handle);
app_wrk = application_listener_select_worker (listener);
s->app_wrk_index = app_wrk->wrk_index;
diff --git a/src/vnet/session/session.c b/src/vnet/session/session.c
index 298d8d8bb06..4b3ce016be5 100644
--- a/src/vnet/session/session.c
+++ b/src/vnet/session/session.c
@@ -168,6 +168,7 @@ session_alloc (u32 thread_index)
clib_memset (s, 0, sizeof (*s));
s->session_index = s - wrk->sessions;
s->thread_index = thread_index;
+ s->app_index = APP_INVALID_INDEX;
return s;
}
@@ -877,13 +878,13 @@ session_stream_accept_notify (transport_connection_t * tc)
*/
int
session_stream_accept (transport_connection_t * tc, u32 listener_index,
- u8 notify)
+ u32 thread_index, u8 notify)
{
session_t *s;
int rv;
s = session_alloc_for_connection (tc);
- s->listener_index = listener_index;
+ s->listener_handle = ((u64) thread_index << 32) | (u64) listener_index;
s->session_state = SESSION_STATE_CREATED;
if ((rv = app_worker_init_accepted (s)))
diff --git a/src/vnet/session/session.h b/src/vnet/session/session.h
index 4e63d42de83..d1268188962 100644
--- a/src/vnet/session/session.h
+++ b/src/vnet/session/session.h
@@ -367,7 +367,7 @@ 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 session_stream_accept (transport_connection_t * tc, u32 listener_index,
- u8 notify);
+ u32 thread_index, u8 notify);
void session_register_transport (transport_proto_t transport_proto,
const transport_proto_vft_t * vft, u8 is_ip4,
u32 output_node);
diff --git a/src/vnet/session/session_api.c b/src/vnet/session/session_api.c
index da62c8598b6..9e7a42d2d39 100755
--- a/src/vnet/session/session_api.c
+++ b/src/vnet/session/session_api.c
@@ -196,7 +196,7 @@ mq_send_session_accepted_cb (session_t * s)
if (session_has_transport (s))
{
- listener = listen_session_get (s->listener_index);
+ listener = listen_session_get_from_handle (s->listener_handle);
mp->listener_handle = app_listen_session_handle (listener);
if (application_is_proxy (app))
{
@@ -217,7 +217,7 @@ mq_send_session_accepted_cb (session_t * s)
ct_connection_t *ct;
ct = (ct_connection_t *) session_get_transport (s);
- listener = listen_session_get (s->listener_index);
+ listener = listen_session_get_from_handle (s->listener_handle);
mp->listener_handle = app_listen_session_handle (listener);
mp->rmt.is_ip4 = session_type_is_ip4 (listener->session_type);
mp->rmt.port = ct->c_rmt_port;
diff --git a/src/vnet/session/session_types.h b/src/vnet/session/session_types.h
index 4a8e97ecf89..ae5d4db2296 100644
--- a/src/vnet/session/session_types.h
+++ b/src/vnet/session/session_types.h
@@ -167,7 +167,7 @@ typedef struct session_
union
{
/** Parent listener session index if the result of an accept */
- u32 listener_index;
+ session_handle_t listener_handle;
/** App listener index in app's listener pool if a listener */
u32 al_index;
diff --git a/src/vnet/tcp/tcp_input.c b/src/vnet/tcp/tcp_input.c
index 304f725cd32..6c78af0fc88 100644
--- a/src/vnet/tcp/tcp_input.c
+++ b/src/vnet/tcp/tcp_input.c
@@ -3190,7 +3190,7 @@ tcp46_listen_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
child0->rto = TCP_RTO_MIN;
if (session_stream_accept (&child0->connection, lc0->c_s_index,
- 0 /* notify */ ))
+ lc0->c_thread_index, 0 /* notify */ ))
{
tcp_connection_cleanup (child0);
error0 = TCP_ERROR_CREATE_SESSION_FAIL;
diff --git a/src/vnet/tls/tls.c b/src/vnet/tls/tls.c
index 520ac7b7dda..e4e8d43e1a1 100644
--- a/src/vnet/tls/tls.c
+++ b/src/vnet/tls/tls.c
@@ -201,7 +201,7 @@ tls_notify_app_accept (tls_ctx_t * ctx)
app_session->app_wrk_index = ctx->parent_app_wrk_index;
app_session->connection_index = ctx->tls_ctx_handle;
app_session->session_type = app_listener->session_type;
- app_session->listener_index = app_listener->session_index;
+ app_session->listener_handle = listen_session_get_handle (app_listener);
app_session->session_state = SESSION_STATE_ACCEPTING;
if ((rv = app_worker_init_accepted (app_session)))
@@ -391,7 +391,8 @@ tls_session_accept_callback (session_t * tls_session)
tls_ctx_t *lctx, *ctx;
u32 ctx_handle;
- tls_listener = listen_session_get (tls_session->listener_index);
+ tls_listener =
+ listen_session_get_from_handle (tls_session->listener_handle);
lctx = tls_listener_ctx_get (tls_listener->opaque);
ctx_handle = tls_ctx_alloc (lctx->tls_ctx_engine);
diff --git a/src/vnet/udp/udp_input.c b/src/vnet/udp/udp_input.c
index c6b9167aff6..cc5ae2bd0eb 100644
--- a/src/vnet/udp/udp_input.c
+++ b/src/vnet/udp/udp_input.c
@@ -210,7 +210,8 @@ udp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
child0->is_connected = 1;
if (session_stream_accept (&child0->connection,
- tc0->s_index, 1))
+ tc0->s_index, tc0->thread_index,
+ 1))
{
error0 = UDP_ERROR_CREATE_SESSION;
goto trace0;