diff options
Diffstat (limited to 'src/vnet')
-rw-r--r-- | src/vnet/session/application_interface.h | 66 | ||||
-rw-r--r-- | src/vnet/session/session_node.c | 18 | ||||
-rw-r--r-- | src/vnet/session/session_types.h | 5 | ||||
-rw-r--r-- | src/vnet/session/transport_types.h | 17 | ||||
-rw-r--r-- | src/vnet/tls/tls.c | 18 |
5 files changed, 105 insertions, 19 deletions
diff --git a/src/vnet/session/application_interface.h b/src/vnet/session/application_interface.h index 1702a3727de..0ad4d973bd9 100644 --- a/src/vnet/session/application_interface.h +++ b/src/vnet/session/application_interface.h @@ -910,17 +910,65 @@ typedef struct app_sapi_msg_ } __clib_packed app_sapi_msg_t; static inline void -session_endpoint_alloc_ext_cfg (session_endpoint_cfg_t *sep_ext, - transport_endpt_ext_cfg_type_t type) +session_endpoint_init_ext_cfgs (session_endpoint_cfg_t *sep_ext, u32 len) { - transport_endpt_ext_cfg_t *cfg; - u32 cfg_size; + sep_ext->ext_cfgs.len = len; + sep_ext->ext_cfgs.data = clib_mem_alloc (len); + clib_memset (sep_ext->ext_cfgs.data, 0, len); +} + +static inline transport_endpt_ext_cfg_t * +session_endpoint_add_ext_cfg (session_endpoint_cfg_t *sep_ext, + transport_endpt_ext_cfg_type_t type, u16 len) +{ + transport_endpt_ext_cfg_t *ext_cfg; + + if (!sep_ext->ext_cfgs.len) + session_endpoint_init_ext_cfgs (sep_ext, + TRANSPORT_ENDPT_EXT_CFGS_CHUNK_SIZE); + + ASSERT (sep_ext->ext_cfgs.tail_offset + len + + TRANSPORT_ENDPT_EXT_CFG_HEADER_SIZE < + sep_ext->ext_cfgs.len); + ext_cfg = (transport_endpt_ext_cfg_t *) (sep_ext->ext_cfgs.data + + sep_ext->ext_cfgs.tail_offset); + ext_cfg->len = len; + ext_cfg->type = type; + sep_ext->ext_cfgs.tail_offset += len + TRANSPORT_ENDPT_EXT_CFG_HEADER_SIZE; + return ext_cfg; +} + +static inline transport_endpt_ext_cfg_t * +session_endpoint_get_ext_cfg (session_endpoint_cfg_t *sep_ext, + transport_endpt_ext_cfg_type_t type) +{ + transport_endpt_ext_cfg_t *ext_cfg; + + if (!sep_ext->ext_cfgs.len) + return 0; + + ext_cfg = (transport_endpt_ext_cfg_t *) sep_ext->ext_cfgs.data; + while ((u8 *) ext_cfg < + sep_ext->ext_cfgs.data + sep_ext->ext_cfgs.tail_offset) + { + if (ext_cfg->type == type) + return ext_cfg; + ext_cfg = + (transport_endpt_ext_cfg_t *) (sep_ext->ext_cfgs.data + ext_cfg->len + + TRANSPORT_ENDPT_EXT_CFG_HEADER_SIZE); + } + return 0; +} - cfg_size = sizeof (transport_endpt_ext_cfg_t); - cfg = clib_mem_alloc (cfg_size); - clib_memset (cfg, 0, cfg_size); - cfg->type = type; - sep_ext->ext_cfg = cfg; +static inline void +session_endpoint_free_ext_cfgs (session_endpoint_cfg_t *sep_ext) +{ + if (!sep_ext->ext_cfgs.len) + return; + clib_mem_free (sep_ext->ext_cfgs.data); + sep_ext->ext_cfgs.len = 0; + sep_ext->ext_cfgs.tail_offset = 0; + sep_ext->ext_cfgs.data = 0; } #endif /* __included_uri_h__ */ diff --git a/src/vnet/session/session_node.c b/src/vnet/session/session_node.c index 14b8005d5d0..4d86d409e98 100644 --- a/src/vnet/session/session_node.c +++ b/src/vnet/session/session_node.c @@ -136,7 +136,14 @@ session_mq_listen_handler (session_worker_t *wrk, session_evt_elt_t *elt) a->sep_ext.transport_flags = mp->flags; if (mp->ext_config) - a->sep_ext.ext_cfg = session_mq_get_ext_config (app, mp->ext_config); + { + transport_endpt_ext_cfg_t *ext_cfg = + session_mq_get_ext_config (app, mp->ext_config); + a->sep_ext.ext_cfgs.data = (u8 *) ext_cfg; + a->sep_ext.ext_cfgs.len = + ext_cfg->len + TRANSPORT_ENDPT_EXT_CFG_HEADER_SIZE; + a->sep_ext.ext_cfgs.tail_offset = a->sep_ext.ext_cfgs.len; + } if ((rv = vnet_listen (a))) session_worker_stat_error_inc (wrk, rv, 1); @@ -213,7 +220,14 @@ session_mq_connect_one (session_connect_msg_t *mp) a->wrk_map_index = mp->wrk_index; if (mp->ext_config) - a->sep_ext.ext_cfg = session_mq_get_ext_config (app, mp->ext_config); + { + transport_endpt_ext_cfg_t *ext_cfg = + session_mq_get_ext_config (app, mp->ext_config); + a->sep_ext.ext_cfgs.data = (u8 *) ext_cfg; + a->sep_ext.ext_cfgs.len = + ext_cfg->len + TRANSPORT_ENDPT_EXT_CFG_HEADER_SIZE; + a->sep_ext.ext_cfgs.tail_offset = a->sep_ext.ext_cfgs.len; + } if ((rv = vnet_connect (a))) { diff --git a/src/vnet/session/session_types.h b/src/vnet/session/session_types.h index 683e5378d31..935f8f189ee 100644 --- a/src/vnet/session/session_types.h +++ b/src/vnet/session/session_types.h @@ -77,7 +77,7 @@ typedef struct _session_endpoint_cfg u8 original_tp; u64 parent_handle; session_endpoint_cfg_flags_t flags; - transport_endpt_ext_cfg_t *ext_cfg; + transport_endpt_ext_cfgs_t ext_cfgs; } session_endpoint_cfg_t; #define SESSION_IP46_ZERO \ @@ -112,7 +112,8 @@ typedef struct _session_endpoint_cfg .peer = TRANSPORT_ENDPOINT_NULL, .transport_proto = 0, \ .app_wrk_index = ENDPOINT_INVALID_INDEX, \ .opaque = ENDPOINT_INVALID_INDEX, \ - .parent_handle = SESSION_INVALID_HANDLE, .ext_cfg = 0, \ + .parent_handle = SESSION_INVALID_HANDLE, \ + .ext_cfgs = TRANSPORT_ENDPT_EXT_CFGS_NULL, \ } #define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep) diff --git a/src/vnet/session/transport_types.h b/src/vnet/session/transport_types.h index f6058c6cef6..8ea66142de7 100644 --- a/src/vnet/session/transport_types.h +++ b/src/vnet/session/transport_types.h @@ -300,10 +300,27 @@ typedef struct transport_endpt_ext_cfg_ union { transport_endpt_crypto_cfg_t crypto; + u32 opaque; /**< For general use */ u8 data[0]; }; } transport_endpt_ext_cfg_t; +#define TRANSPORT_ENDPT_EXT_CFG_HEADER_SIZE 4 + +typedef struct transport_endpt_ext_cfgs_ +{ + u32 len; /**< length of config data chunk */ + u32 tail_offset; /**< current tail in config data chunk */ + u8 *data; /**< start of config data chunk */ +} transport_endpt_ext_cfgs_t; + +#define TRANSPORT_ENDPT_EXT_CFGS_CHUNK_SIZE 512 + +#define TRANSPORT_ENDPT_EXT_CFGS_NULL \ + { \ + .len = 0, .tail_offset = 0, .data = 0, \ + } + typedef clib_bihash_24_8_t transport_endpoint_table_t; #define ENDPOINT_INVALID_INDEX ((u32)~0) diff --git a/src/vnet/tls/tls.c b/src/vnet/tls/tls.c index 8754b67ca31..12dcbb449e8 100644 --- a/src/vnet/tls/tls.c +++ b/src/vnet/tls/tls.c @@ -628,16 +628,18 @@ tls_connect (transport_endpoint_cfg_t * tep) application_t *app; tls_ctx_t *ctx; u32 ctx_index; + transport_endpt_ext_cfg_t *ext_cfg; int rv; sep = (session_endpoint_cfg_t *) tep; - if (!sep->ext_cfg) + ext_cfg = session_endpoint_get_ext_cfg (sep, TRANSPORT_ENDPT_EXT_CFG_CRYPTO); + if (!ext_cfg) return SESSION_E_NOEXTCFG; app_wrk = app_worker_get (sep->app_wrk_index); app = application_get (app_wrk->app_index); - ccfg = &sep->ext_cfg->crypto; + ccfg = &ext_cfg->crypto; engine_type = tls_get_engine_type (ccfg->crypto_engine, app->tls_engine); if (engine_type == CRYPTO_ENGINE_NONE) { @@ -709,16 +711,18 @@ tls_start_listen (u32 app_listener_index, transport_endpoint_cfg_t *tep) app_listener_t *al; tls_ctx_t *lctx; u32 lctx_index; + transport_endpt_ext_cfg_t *ext_cfg; int rv; sep = (session_endpoint_cfg_t *) tep; - if (!sep->ext_cfg) + ext_cfg = session_endpoint_get_ext_cfg (sep, TRANSPORT_ENDPT_EXT_CFG_CRYPTO); + if (!ext_cfg) return SESSION_E_NOEXTCFG; app_wrk = app_worker_get (sep->app_wrk_index); app = application_get (app_wrk->app_index); - ccfg = &sep->ext_cfg->crypto; + ccfg = &ext_cfg->crypto; engine_type = tls_get_engine_type (ccfg->crypto_engine, app->tls_engine); if (engine_type == CRYPTO_ENGINE_NONE) { @@ -1115,16 +1119,18 @@ dtls_connect (transport_endpoint_cfg_t *tep) application_t *app; tls_ctx_t *ctx; u32 ctx_handle; + transport_endpt_ext_cfg_t *ext_cfg; int rv; sep = (session_endpoint_cfg_t *) tep; - if (!sep->ext_cfg) + ext_cfg = session_endpoint_get_ext_cfg (sep, TRANSPORT_ENDPT_EXT_CFG_CRYPTO); + if (!ext_cfg) return -1; app_wrk = app_worker_get (sep->app_wrk_index); app = application_get (app_wrk->app_index); - ccfg = &sep->ext_cfg->crypto; + ccfg = &ext_cfg->crypto; engine_type = tls_get_engine_type (ccfg->crypto_engine, app->tls_engine); if (engine_type == CRYPTO_ENGINE_NONE) { |