summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plugins/hs_apps/proxy.c129
-rw-r--r--src/plugins/hs_apps/proxy.h26
2 files changed, 52 insertions, 103 deletions
diff --git a/src/plugins/hs_apps/proxy.c b/src/plugins/hs_apps/proxy.c
index 3fdac06610d..db741f3eda1 100644
--- a/src/plugins/hs_apps/proxy.c
+++ b/src/plugins/hs_apps/proxy.c
@@ -66,27 +66,43 @@ proxy_call_main_thread (vnet_connect_args_t * a)
}
static proxy_session_t *
-proxy_get_active_open (proxy_main_t * pm, session_handle_t handle)
+proxy_session_alloc (void)
{
- proxy_session_t *ps = 0;
- uword *p;
+ proxy_main_t *pm = &proxy_main;
+ proxy_session_t *ps;
+
+ pool_get_zero (pm->sessions, ps);
+ ps->ps_index = ps - pm->sessions;
- p = hash_get (pm->proxy_session_by_active_open_handle, handle);
- if (p)
- ps = pool_elt_at_index (pm->sessions, p[0]);
return ps;
}
-static proxy_session_t *
-proxy_get_passive_open (proxy_main_t * pm, session_handle_t handle)
+static inline proxy_session_t *
+proxy_session_get (u32 ps_index)
{
- proxy_session_t *ps = 0;
- uword *p;
+ proxy_main_t *pm = &proxy_main;
- p = hash_get (pm->proxy_session_by_server_handle, handle);
- if (p)
- ps = pool_elt_at_index (pm->sessions, p[0]);
- return ps;
+ return pool_elt_at_index (pm->sessions, ps_index);
+}
+
+static inline proxy_session_t *
+proxy_session_get_if_valid (u32 ps_index)
+{
+ proxy_main_t *pm = &proxy_main;
+
+ if (pool_is_free_index (pm->sessions, ps_index))
+ return 0;
+ return pool_elt_at_index (pm->sessions, ps_index);
+}
+
+static void
+proxy_session_free (proxy_session_t *ps)
+{
+ proxy_main_t *pm = &proxy_main;
+
+ if (CLIB_DEBUG > 0)
+ clib_memset (ps, 0xFE, sizeof (*ps));
+ pool_put (pm->sessions, ps);
}
static void
@@ -95,17 +111,13 @@ proxy_try_close_session (session_t * s, int is_active_open)
proxy_main_t *pm = &proxy_main;
proxy_session_t *ps = 0;
vnet_disconnect_args_t _a, *a = &_a;
- session_handle_t handle;
-
- handle = session_handle (s);
clib_spinlock_lock_if_init (&pm->sessions_lock);
+ ps = proxy_session_get (s->opaque);
+
if (is_active_open)
{
- ps = proxy_get_active_open (pm, handle);
- ASSERT (ps != 0);
-
a->handle = ps->vpp_active_open_handle;
a->app_index = pm->active_open_app_index;
vnet_disconnect_session (a);
@@ -122,9 +134,6 @@ proxy_try_close_session (session_t * s, int is_active_open)
}
else
{
- ps = proxy_get_passive_open (pm, handle);
- ASSERT (ps != 0);
-
a->handle = ps->vpp_server_handle;
a->app_index = pm->server_app_index;
vnet_disconnect_session (a);
@@ -146,43 +155,25 @@ proxy_try_close_session (session_t * s, int is_active_open)
}
static void
-proxy_session_free (proxy_session_t * ps)
-{
- proxy_main_t *pm = &proxy_main;
- if (CLIB_DEBUG > 0)
- clib_memset (ps, 0xFE, sizeof (*ps));
- pool_put (pm->sessions, ps);
-}
-
-static void
proxy_try_delete_session (session_t * s, u8 is_active_open)
{
proxy_main_t *pm = &proxy_main;
proxy_session_t *ps = 0;
- session_handle_t handle;
-
- handle = session_handle (s);
clib_spinlock_lock_if_init (&pm->sessions_lock);
+ ps = proxy_session_get (s->opaque);
+
if (is_active_open)
{
- ps = proxy_get_active_open (pm, handle);
- ASSERT (ps != 0);
-
ps->vpp_active_open_handle = SESSION_INVALID_HANDLE;
- hash_unset (pm->proxy_session_by_active_open_handle, handle);
if (ps->vpp_server_handle == SESSION_INVALID_HANDLE)
proxy_session_free (ps);
}
else
{
- ps = proxy_get_passive_open (pm, handle);
- ASSERT (ps != 0);
-
ps->vpp_server_handle = SESSION_INVALID_HANDLE;
- hash_unset (pm->proxy_session_by_server_handle, handle);
if (ps->vpp_active_open_handle == SESSION_INVALID_HANDLE)
{
@@ -245,12 +236,11 @@ proxy_accept_callback (session_t * s)
clib_spinlock_lock_if_init (&pm->sessions_lock);
- pool_get_zero (pm->sessions, ps);
+ ps = proxy_session_alloc ();
ps->vpp_server_handle = session_handle (s);
ps->vpp_active_open_handle = SESSION_INVALID_HANDLE;
- hash_set (pm->proxy_session_by_server_handle, ps->vpp_server_handle,
- ps - pm->sessions);
+ s->opaque = ps->ps_index;
clib_spinlock_unlock_if_init (&pm->sessions_lock);
@@ -303,8 +293,7 @@ proxy_rx_callback (session_t * s)
clib_spinlock_lock_if_init (&pm->sessions_lock);
- ps = proxy_get_passive_open (pm, session_handle (s));
- ASSERT (ps != 0);
+ ps = proxy_session_get (s->opaque);
if (PREDICT_TRUE (ps->vpp_active_open_handle != SESSION_INVALID_HANDLE))
{
@@ -332,7 +321,7 @@ proxy_rx_callback (session_t * s)
{
vnet_connect_args_t _a, *a = &_a;
svm_fifo_t *tx_fifo, *rx_fifo;
- u32 max_dequeue, proxy_index;
+ u32 max_dequeue, ps_index;
int actual_transfer __attribute__ ((unused));
rx_fifo = s->rx_fifo;
@@ -360,12 +349,12 @@ proxy_rx_callback (session_t * s)
ps->server_rx_fifo = rx_fifo;
ps->server_tx_fifo = tx_fifo;
ps->active_open_establishing = 1;
- proxy_index = ps - pm->sessions;
+ ps_index = ps->ps_index;
clib_spinlock_unlock_if_init (&pm->sessions_lock);
clib_memcpy (&a->sep_ext, &pm->client_sep, sizeof (pm->client_sep));
- a->api_context = proxy_index;
+ a->api_context = ps_index;
a->app_index = pm->active_open_app_index;
if (proxy_transport_needs_crypto (a->sep.transport_proto))
@@ -410,8 +399,7 @@ proxy_tx_callback (session_t * proxy_s)
clib_spinlock_lock_if_init (&pm->sessions_lock);
- ps = proxy_get_passive_open (pm, session_handle (proxy_s));
- ASSERT (ps != 0);
+ ps = proxy_session_get (proxy_s->opaque);
if (ps->vpp_active_open_handle == SESSION_INVALID_HANDLE)
goto unlock;
@@ -462,7 +450,7 @@ active_open_connected_callback (u32 app_index, u32 opaque,
*/
clib_spinlock_lock_if_init (&pm->sessions_lock);
- ps = pool_elt_at_index (pm->sessions, opaque);
+ ps = proxy_session_get (opaque);
/* Connection failed */
if (err)
@@ -484,8 +472,6 @@ active_open_connected_callback (u32 app_index, u32 opaque,
if (ps->po_disconnected)
{
/* Setup everything for the cleanup notification */
- hash_set (pm->proxy_session_by_active_open_handle,
- ps->vpp_active_open_handle, opaque);
ps->ao_disconnected = 1;
clib_spinlock_unlock_if_init (&pm->sessions_lock);
return -1;
@@ -509,8 +495,7 @@ active_open_connected_callback (u32 app_index, u32 opaque,
s->tx_fifo->refcnt++;
s->rx_fifo->refcnt++;
- hash_set (pm->proxy_session_by_active_open_handle,
- ps->vpp_active_open_handle, opaque);
+ s->opaque = opaque;
clib_spinlock_unlock_if_init (&pm->sessions_lock);
@@ -572,11 +557,9 @@ active_open_tx_callback (session_t * ao_s)
{
proxy_main_t *pm = &proxy_main;
transport_connection_t *tc;
- session_handle_t handle;
proxy_session_t *ps;
session_t *proxy_s;
u32 min_free;
- uword *p;
min_free = clib_min (svm_fifo_size (ao_s->tx_fifo) >> 3, 128 << 10);
if (svm_fifo_max_enqueue (ao_s->tx_fifo) < min_free)
@@ -587,15 +570,10 @@ active_open_tx_callback (session_t * ao_s)
clib_spinlock_lock_if_init (&pm->sessions_lock);
- handle = session_handle (ao_s);
- p = hash_get (pm->proxy_session_by_active_open_handle, handle);
- if (!p)
- goto unlock;
-
- if (pool_is_free_index (pm->sessions, p[0]))
+ ps = proxy_session_get_if_valid (ao_s->opaque);
+ if (!ps)
goto unlock;
- ps = pool_elt_at_index (pm->sessions, p[0]);
if (ps->vpp_server_handle == ~0)
goto unlock;
@@ -758,14 +736,12 @@ proxy_server_add_ckpair (void)
static int
proxy_server_create (vlib_main_t * vm)
{
- proxy_main_t *pm = &proxy_main;
vlib_thread_main_t *vtm = vlib_get_thread_main ();
+ proxy_main_t *pm = &proxy_main;
u32 num_threads;
int i;
num_threads = 1 /* main thread */ + vtm->n_threads;
- vec_validate (proxy_main.server_event_queue, num_threads - 1);
- vec_validate (proxy_main.active_open_event_queue, num_threads - 1);
vec_validate (pm->rx_buf, num_threads - 1);
for (i = 0; i < num_threads; i++)
@@ -789,15 +765,6 @@ proxy_server_create (vlib_main_t * vm)
return -1;
}
- for (i = 0; i < num_threads; i++)
- {
- pm->active_open_event_queue[i] = session_main_get_vpp_event_queue (i);
-
- ASSERT (pm->active_open_event_queue[i]);
-
- pm->server_event_queue[i] = session_main_get_vpp_event_queue (i);
- }
-
return 0;
}
@@ -913,7 +880,6 @@ done:
return error;
}
-/* *INDENT-OFF* */
VLIB_CLI_COMMAND (proxy_create_command, static) =
{
.path = "test proxy server",
@@ -924,7 +890,6 @@ VLIB_CLI_COMMAND (proxy_create_command, static) =
"[private-segment-size <mem>][private-segment-count <nn>]",
.function = proxy_server_create_command_fn,
};
-/* *INDENT-ON* */
clib_error_t *
proxy_main_init (vlib_main_t * vm)
@@ -932,8 +897,6 @@ proxy_main_init (vlib_main_t * vm)
proxy_main_t *pm = &proxy_main;
pm->server_client_index = ~0;
pm->active_open_client_index = ~0;
- pm->proxy_session_by_active_open_handle = hash_create (0, sizeof (uword));
- pm->proxy_session_by_server_handle = hash_create (0, sizeof (uword));
return 0;
}
diff --git a/src/plugins/hs_apps/proxy.h b/src/plugins/hs_apps/proxy.h
index aef23e1e556..4b4c7c0ca8f 100644
--- a/src/plugins/hs_apps/proxy.h
+++ b/src/plugins/hs_apps/proxy.h
@@ -36,54 +36,40 @@ typedef struct
volatile int active_open_establishing;
volatile int po_disconnected;
volatile int ao_disconnected;
+
+ u32 ps_index;
} proxy_session_t;
typedef struct
{
- svm_queue_t *vl_input_queue; /**< vpe input queue */
- /** per-thread vectors */
- svm_msg_q_t **server_event_queue;
- svm_msg_q_t **active_open_event_queue;
+ proxy_session_t *sessions; /**< session pool, shared */
+ clib_spinlock_t sessions_lock; /**< lock for session pool */
u8 **rx_buf; /**< intermediate rx buffers */
- u32 cli_node_index; /**< cli process node index */
u32 server_client_index; /**< server API client handle */
u32 server_app_index; /**< server app index */
u32 active_open_client_index; /**< active open API client handle */
u32 active_open_app_index; /**< active open index after attach */
-
- uword *proxy_session_by_server_handle;
- uword *proxy_session_by_active_open_handle;
+ u32 ckpair_index; /**< certkey pair index for tls */
/*
* Configuration params
*/
- u8 *connect_uri; /**< URI for slave's connect */
- u32 configured_segment_size;
u32 fifo_size; /**< initial fifo size */
u32 max_fifo_size; /**< max fifo size */
u8 high_watermark; /**< high watermark (%) */
u8 low_watermark; /**< low watermark (%) */
u32 private_segment_count; /**< Number of private fifo segs */
u32 private_segment_size; /**< size of private fifo segs */
+ u8 prealloc_fifos; /**< Request fifo preallocation */
int rcv_buffer_size;
session_endpoint_cfg_t server_sep;
session_endpoint_cfg_t client_sep;
- u32 ckpair_index;
- /*
- * Test state variables
- */
- proxy_session_t *sessions; /**< Session pool, shared */
- clib_spinlock_t sessions_lock;
- u32 **connection_index_by_thread;
- pthread_t client_thread_handle;
-
/*
* Flags
*/
u8 is_init;
- u8 prealloc_fifos; /**< Request fifo preallocation */
} proxy_main_t;
extern proxy_main_t proxy_main;