aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2018-11-29 12:40:10 -0800
committerOle Trøan <otroan@employees.org>2018-11-30 07:21:02 +0000
commitfa76a76bf3388f09d55d0c83e7aea507c44f9619 (patch)
treeee9f51236f6e4acf5627f11f27aff73de9d1fe15 /src/vnet
parent4744ddbfe0012861895dbd33487569e46b81554b (diff)
session: segment handle in accept/connect notifications
Change-Id: I03884b6cde9d4c38ae13d1994fd8d37d44016ef0 Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/vnet')
-rw-r--r--src/vnet/session-apps/echo_client.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.c19
-rw-r--r--src/vnet/session/application.h10
-rw-r--r--src/vnet/session/application_interface.h2
-rw-r--r--src/vnet/session/segment_manager.c42
-rw-r--r--src/vnet/session/segment_manager.h14
-rw-r--r--src/vnet/session/session.api11
-rw-r--r--src/vnet/session/session.h8
-rwxr-xr-xsrc/vnet/session/session_api.c18
-rw-r--r--src/vnet/tls/tls.c4
13 files changed, 105 insertions, 31 deletions
diff --git a/src/vnet/session-apps/echo_client.c b/src/vnet/session-apps/echo_client.c
index faf8521ce8c..51a85c068f8 100644
--- a/src/vnet/session-apps/echo_client.c
+++ b/src/vnet/session-apps/echo_client.c
@@ -483,7 +483,7 @@ echo_clients_rx_callback (stream_session_t * s)
}
int
-echo_client_add_segment_callback (u32 client_index, const ssvm_private_t * sp)
+echo_client_add_segment_callback (u32 client_index, u64 segment_handle)
{
/* New heaps may be added */
return 0;
diff --git a/src/vnet/session-apps/echo_server.c b/src/vnet/session-apps/echo_server.c
index a4afc5d512f..e79e8380fe5 100644
--- a/src/vnet/session-apps/echo_server.c
+++ b/src/vnet/session-apps/echo_server.c
@@ -96,7 +96,7 @@ echo_server_session_connected_callback (u32 app_index, u32 api_context,
}
int
-echo_server_add_segment_callback (u32 client_index, const ssvm_private_t * sp)
+echo_server_add_segment_callback (u32 client_index, u64 segment_handle)
{
/* New heaps may be added */
return 0;
diff --git a/src/vnet/session-apps/http_server.c b/src/vnet/session-apps/http_server.c
index 79c2d4a7bfc..37441bb2188 100644
--- a/src/vnet/session-apps/http_server.c
+++ b/src/vnet/session-apps/http_server.c
@@ -458,7 +458,7 @@ http_server_session_connected_callback (u32 app_index, u32 api_context,
}
static int
-http_server_add_segment_callback (u32 client_index, const ssvm_private_t * sp)
+http_server_add_segment_callback (u32 client_index, u64 segment_handle)
{
clib_warning ("called...");
return -1;
diff --git a/src/vnet/session-apps/proxy.c b/src/vnet/session-apps/proxy.c
index 0b2baa7697c..06c095440bc 100644
--- a/src/vnet/session-apps/proxy.c
+++ b/src/vnet/session-apps/proxy.c
@@ -176,7 +176,7 @@ proxy_connected_callback (u32 app_index, u32 api_context,
}
static int
-proxy_add_segment_callback (u32 client_index, const ssvm_private_t * sp)
+proxy_add_segment_callback (u32 client_index, u64 segment_handle)
{
clib_warning ("called...");
return -1;
diff --git a/src/vnet/session/application.c b/src/vnet/session/application.c
index 380c960bdaf..69f33290a73 100644
--- a/src/vnet/session/application.c
+++ b/src/vnet/session/application.c
@@ -924,6 +924,7 @@ vnet_app_worker_add_del (vnet_app_worker_add_del_args_t * a)
sm = segment_manager_get (app_wrk->first_segment_manager);
fs = segment_manager_get_segment_w_lock (sm, 0);
a->segment = &fs->ssvm;
+ a->segment_handle = segment_manager_segment_handle (sm, fs);
segment_manager_segment_reader_unlock (sm);
a->evt_q = app_wrk->event_queue;
a->wrk_map_index = app_wrk->wrk_map_index;
@@ -1007,11 +1008,12 @@ application_use_mq_for_ctrl (application_t * app)
* Send an API message to the external app, to map new segment
*/
int
-app_worker_add_segment_notify (u32 app_wrk_index, ssvm_private_t * fs)
+app_worker_add_segment_notify (u32 app_wrk_index, u64 segment_handle)
{
app_worker_t *app_wrk = app_worker_get (app_wrk_index);
application_t *app = application_get (app_wrk->app_index);
- return app->cb_fns.add_segment_callback (app_wrk->api_client_index, fs);
+ return app->cb_fns.add_segment_callback (app_wrk->api_client_index,
+ segment_handle);
}
u32
@@ -1597,6 +1599,7 @@ application_local_session_connect (app_worker_t * client_wrk,
segment_manager_t *sm;
local_session_t *ls;
svm_msg_q_t *sq, *cq;
+ u64 segment_handle;
ls = application_local_session_alloc (server_wrk);
server = application_get (server_wrk->app_index);
@@ -1660,8 +1663,9 @@ application_local_session_connect (app_worker_t * client_wrk,
ls->listener_session_type = ll->session_type;
ls->session_state = SESSION_STATE_READY;
+ segment_handle = segment_manager_segment_handle (sm, seg);
if ((rv = server->cb_fns.add_segment_callback (server_wrk->api_client_index,
- &seg->ssvm)))
+ segment_handle)))
{
clib_warning ("failed to notify server of new segment");
segment_manager_segment_reader_unlock (sm);
@@ -1706,6 +1710,7 @@ application_local_session_connect_notify (local_session_t * ls)
segment_manager_t *sm;
application_t *client;
int rv, is_fail = 0;
+ u64 segment_handle;
uword client_key;
client_wrk = app_worker_get (ls->client_wrk_index);
@@ -1714,8 +1719,9 @@ application_local_session_connect_notify (local_session_t * ls)
sm = application_get_local_segment_manager_w_session (server_wrk, ls);
seg = segment_manager_get_segment_w_lock (sm, ls->svm_segment_index);
+ segment_handle = segment_manager_segment_handle (sm, seg);
if ((rv = client->cb_fns.add_segment_callback (client_wrk->api_client_index,
- &seg->ssvm)))
+ segment_handle)))
{
clib_warning ("failed to notify client %u of new segment",
ls->client_wrk_index);
@@ -1770,13 +1776,14 @@ application_local_session_cleanup (app_worker_t * client_wrk,
if (!has_transport)
{
application_t *server = application_get (server_wrk->app_index);
+ u64 segment_handle = segment_manager_segment_handle (sm, seg);
server->cb_fns.del_segment_callback (server_wrk->api_client_index,
- &seg->ssvm);
+ segment_handle);
if (client_wrk)
{
application_t *client = application_get (client_wrk->app_index);
client->cb_fns.del_segment_callback (client_wrk->api_client_index,
- &seg->ssvm);
+ segment_handle);
}
segment_manager_del_segment (sm, seg);
}
diff --git a/src/vnet/session/application.h b/src/vnet/session/application.h
index 0ac2b25e081..e33f2ff797e 100644
--- a/src/vnet/session/application.h
+++ b/src/vnet/session/application.h
@@ -31,11 +31,10 @@
typedef struct _stream_session_cb_vft
{
/** Notify server of new segment */
- int (*add_segment_callback) (u32 api_client_index,
- const ssvm_private_t * ssvm_seg);
+ int (*add_segment_callback) (u32 api_client_index, u64 segment_handle);
+
/** Notify server of new segment */
- int (*del_segment_callback) (u32 api_client_index,
- const ssvm_private_t * ssvm_seg);
+ int (*del_segment_callback) (u32 api_client_index, u64 segment_handle);
/** Notify server of newly accepted session */
int (*session_accept_callback) (stream_session_t * new_session);
@@ -212,6 +211,7 @@ typedef struct _vnet_app_worker_add_del_args
u32 wrk_map_index; /**< Index to delete or return value if add */
u32 api_client_index; /**< Binary API client index */
ssvm_private_t *segment; /**< First segment in segment manager */
+ u64 segment_handle; /**< Handle for the segment */
svm_msg_q_t *evt_q; /**< Worker message queue */
u8 is_add; /**< Flag set if addition */
} vnet_app_worker_add_del_args_t;
@@ -232,7 +232,7 @@ segment_manager_t *app_worker_get_listen_segment_manager (app_worker_t *,
stream_session_t *);
segment_manager_t *app_worker_get_connect_segment_manager (app_worker_t *);
int app_worker_alloc_connects_segment_manager (app_worker_t * app);
-int app_worker_add_segment_notify (u32 app_or_wrk, ssvm_private_t * fs);
+int app_worker_add_segment_notify (u32 app_or_wrk, u64 segment_handle);
u32 app_worker_n_listeners (app_worker_t * app);
stream_session_t *app_worker_first_listener (app_worker_t * app,
u8 fib_proto,
diff --git a/src/vnet/session/application_interface.h b/src/vnet/session/application_interface.h
index 10edfdef35a..ecd99d8755b 100644
--- a/src/vnet/session/application_interface.h
+++ b/src/vnet/session/application_interface.h
@@ -234,6 +234,7 @@ typedef struct session_accepted_msg_
u64 handle;
u64 server_rx_fifo;
u64 server_tx_fifo;
+ u64 segment_handle;
u64 vpp_event_queue_address;
u64 server_event_queue_address;
u64 client_event_queue_address;
@@ -260,6 +261,7 @@ typedef struct session_connected_msg_
u64 handle;
u64 server_rx_fifo;
u64 server_tx_fifo;
+ u64 segment_handle;
u64 vpp_event_queue_address;
u64 client_event_queue_address;
u64 server_event_queue_address;
diff --git a/src/vnet/session/segment_manager.c b/src/vnet/session/segment_manager.c
index 6386645a974..47704a7178b 100644
--- a/src/vnet/session/segment_manager.c
+++ b/src/vnet/session/segment_manager.c
@@ -117,6 +117,36 @@ segment_manager_get_segment (segment_manager_t * sm, u32 segment_index)
return pool_elt_at_index (sm->segments, segment_index);
}
+u64
+segment_manager_segment_handle (segment_manager_t * sm,
+ svm_fifo_segment_private_t * segment)
+{
+ u32 segment_index = segment_manager_segment_index (sm, segment);
+ return (((u64) segment_manager_index (sm) << 32) | segment_index);
+}
+
+void
+segment_manager_parse_segment_handle (u64 segment_handle, u32 * sm_index,
+ u32 * segment_index)
+{
+ *sm_index = segment_handle >> 32;
+ *segment_index = segment_handle & 0xFFFFFFFF;
+}
+
+svm_fifo_segment_private_t *
+segment_manager_get_segment_w_handle (u64 segment_handle)
+{
+ u32 sm_index, segment_index;
+ segment_manager_t *sm;
+
+ segment_manager_parse_segment_handle (segment_handle, &sm_index,
+ &segment_index);
+ sm = segment_manager_get (sm_index);
+ if (!sm || pool_is_free_index (sm->segments, segment_index))
+ return 0;
+ return pool_elt_at_index (sm->segments, segment_index);
+}
+
/**
* Reads a segment from the segment manager's pool and acquires reader lock
*
@@ -484,6 +514,7 @@ segment_manager_alloc_session_fifos (segment_manager_t * sm,
int alloc_fail = 1, rv = 0, new_fs_index;
segment_manager_properties_t *props;
u8 added_a_segment = 0;
+ u64 segment_handle;
u32 sm_index;
props = segment_manager_properties_get (sm);
@@ -513,13 +544,18 @@ alloc_check:
ASSERT (rx_fifo && tx_fifo);
sm_index = segment_manager_index (sm);
+ *fifo_segment_index = segment_manager_segment_index (sm, fifo_segment);
(*tx_fifo)->segment_manager = sm_index;
(*rx_fifo)->segment_manager = sm_index;
- *fifo_segment_index = segment_manager_segment_index (sm, fifo_segment);
+ (*tx_fifo)->segment_index = *fifo_segment_index;
+ (*rx_fifo)->segment_index = *fifo_segment_index;
if (added_a_segment)
- rv = app_worker_add_segment_notify (sm->app_wrk_index,
- &fifo_segment->ssvm);
+ {
+ segment_handle = segment_manager_segment_handle (sm, fifo_segment);
+ rv = app_worker_add_segment_notify (sm->app_wrk_index,
+ segment_handle);
+ }
/* Drop the lock after app is notified */
segment_manager_segment_reader_unlock (sm);
return rv;
diff --git a/src/vnet/session/segment_manager.h b/src/vnet/session/segment_manager.h
index 0e5f62414e5..657a1fcc231 100644
--- a/src/vnet/session/segment_manager.h
+++ b/src/vnet/session/segment_manager.h
@@ -117,13 +117,23 @@ segment_manager_event_queue (segment_manager_t * sm)
return sm->event_queue;
}
+always_inline u64
+segment_manager_make_segment_handle (u32 segment_manager_index,
+ u32 segment_index)
+{
+ return (((u64) segment_manager_index << 32) | segment_index);
+}
+
+u64 segment_manager_segment_handle (segment_manager_t * sm,
+ svm_fifo_segment_private_t * segment);
+
segment_manager_t *segment_manager_new ();
int segment_manager_init (segment_manager_t * sm, u32 first_seg_size,
u32 prealloc_fifo_pairs);
-svm_fifo_segment_private_t *segment_manager_get_segment (segment_manager_t *
- sm,
+svm_fifo_segment_private_t *segment_manager_get_segment (segment_manager_t *,
u32 segment_index);
+svm_fifo_segment_private_t *segment_manager_get_segment_w_handle (u64);
svm_fifo_segment_private_t
* segment_manager_get_segment_w_lock (segment_manager_t * sm,
u32 segment_index);
diff --git a/src/vnet/session/session.api b/src/vnet/session/session.api
index eced1d47770..3dc0cc8d360 100644
--- a/src/vnet/session/session.api
+++ b/src/vnet/session/session.api
@@ -13,7 +13,7 @@
* limitations under the License.
*/
-option version = "1.3.0";
+option version = "1.4.0";
/** \brief client->vpp, attach application to session layer
@param client_index - opaque cookie to identify the sender
@@ -103,6 +103,7 @@ autoreply define application_detach {
socket transport available
@param segment_size - size of the segment to be mapped
@param segment_name - name of the segment to be mapped
+ @param segment_handle - unique identifier for segment
*/
autoreply define map_another_segment {
u32 client_index;
@@ -110,17 +111,19 @@ autoreply define map_another_segment {
u8 fd_flags;
u32 segment_size;
u8 segment_name[128];
+ u64 segment_handle;
};
/** \brief vpp->client unmap shared memory segment
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
- @param segment_name -
+ @param segment_name - segment name
+ @param segment_handle - handle of the segment to be unmapped
*/
autoreply define unmap_segment {
u32 client_index;
u32 context;
- u8 segment_name[128];
+ u64 segment_handle;
};
/** \brief Bind to a given URI
@@ -462,6 +465,7 @@ define app_worker_add_del
over the socket (set only if socket transport available)
@param segment_name_length - length of segment name
@param segment_name - name of segment client needs to attach to
+ @param segment_handle - handle for segment
*/
define app_worker_add_del_reply
{
@@ -473,6 +477,7 @@ define app_worker_add_del_reply
u8 fd_flags;
u8 segment_name_length;
u8 segment_name[128];
+ u64 segment_handle;
u8 is_add;
};
diff --git a/src/vnet/session/session.h b/src/vnet/session/session.h
index ea21464ee54..d5f040edc59 100644
--- a/src/vnet/session/session.h
+++ b/src/vnet/session/session.h
@@ -441,6 +441,14 @@ session_type_from_proto_and_ip (transport_proto_t proto, u8 is_ip4)
return (proto << 1 | is_ip4);
}
+always_inline u64
+session_segment_handle (stream_session_t * s)
+{
+ svm_fifo_t *f = s->server_rx_fifo;
+ return segment_manager_make_segment_handle (f->segment_manager,
+ f->segment_index);
+}
+
always_inline u8
session_has_transport (stream_session_t * s)
{
diff --git a/src/vnet/session/session_api.c b/src/vnet/session/session_api.c
index 7d3ff31031d..d37b3c995d0 100755
--- a/src/vnet/session/session_api.c
+++ b/src/vnet/session/session_api.c
@@ -79,20 +79,24 @@ session_send_fds (vl_api_registration_t * reg, int fds[], int n_fds)
}
static int
-send_add_segment_callback (u32 api_client_index, const ssvm_private_t * sp)
+send_add_segment_callback (u32 api_client_index, u64 segment_handle)
{
int fds[SESSION_N_FD_TYPE], n_fds = 0;
vl_api_map_another_segment_t *mp;
+ svm_fifo_segment_private_t *fs;
vl_api_registration_t *reg;
+ ssvm_private_t *sp;
u8 fd_flags = 0;
reg = vl_mem_api_client_index_to_registration (api_client_index);
if (!reg)
{
- clib_warning ("no registration: %u", api_client_index);
+ clib_warning ("no api registration for client: %u", api_client_index);
return -1;
}
+ fs = segment_manager_get_segment_w_handle (segment_handle);
+ sp = &fs->ssvm;
if (ssvm_type (sp) == SSVM_SEGMENT_MEMFD)
{
if (vl_api_registration_file_index (reg) == VL_API_INVALID_FI)
@@ -111,6 +115,7 @@ send_add_segment_callback (u32 api_client_index, const ssvm_private_t * sp)
mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_MAP_ANOTHER_SEGMENT);
mp->segment_size = sp->ssvm_size;
mp->fd_flags = fd_flags;
+ mp->segment_handle = clib_host_to_net_u64 (segment_handle);
strncpy ((char *) mp->segment_name, (char *) sp->name,
sizeof (mp->segment_name) - 1);
@@ -123,7 +128,7 @@ send_add_segment_callback (u32 api_client_index, const ssvm_private_t * sp)
}
static int
-send_del_segment_callback (u32 api_client_index, const ssvm_private_t * fs)
+send_del_segment_callback (u32 api_client_index, u64 segment_handle)
{
vl_api_unmap_segment_t *mp;
vl_api_registration_t *reg;
@@ -138,9 +143,7 @@ send_del_segment_callback (u32 api_client_index, const ssvm_private_t * fs)
mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
clib_memset (mp, 0, sizeof (*mp));
mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_UNMAP_SEGMENT);
- strncpy ((char *) mp->segment_name, (char *) fs->name,
- sizeof (mp->segment_name) - 1);
-
+ mp->segment_handle = clib_host_to_net_u64 (segment_handle);
vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
return 0;
@@ -434,6 +437,7 @@ mq_send_session_accepted_cb (stream_session_t * s)
mp->context = app->app_index;
mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo);
mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo);
+ mp->segment_handle = session_segment_handle (s);
if (session_has_transport (s))
{
@@ -589,6 +593,7 @@ mq_send_session_connected_cb (u32 app_wrk_index, u32 api_context,
evt->event_type = SESSION_CTRL_EVT_CONNECTED;
mp = (session_connected_msg_t *) evt->data;
mp->context = api_context;
+ mp->segment_handle = session_segment_handle (s);
if (is_fail)
goto done;
@@ -1383,6 +1388,7 @@ done:
REPLY_MACRO2 (VL_API_APP_WORKER_ADD_DEL_REPLY, ({
rmp->is_add = mp->is_add;
rmp->wrk_index = clib_host_to_net_u32 (args.wrk_map_index);
+ rmp->segment_handle = clib_host_to_net_u64 (args.segment_handle);
if (!rv && mp->is_add)
{
if (vec_len (args.segment->name))
diff --git a/src/vnet/tls/tls.c b/src/vnet/tls/tls.c
index 7378093bd04..0fdd68c7d38 100644
--- a/src/vnet/tls/tls.c
+++ b/src/vnet/tls/tls.c
@@ -367,14 +367,14 @@ tls_session_reset_callback (stream_session_t * s)
}
int
-tls_add_segment_callback (u32 client_index, const ssvm_private_t * fs)
+tls_add_segment_callback (u32 client_index, u64 segment_handle)
{
/* No-op for builtin */
return 0;
}
int
-tls_del_segment_callback (u32 client_index, const ssvm_private_t * fs)
+tls_del_segment_callback (u32 client_index, u64 segment_handle)
{
return 0;
}