|
FD.io VPP
v21.10.1-2-g0a485f517
Vector Packet Processing
|
Go to the documentation of this file.
23 #define TLS_INVALID_HANDLE ~0
24 #define TLS_IDX_MASK 0x00FFFFFF
25 #define TLS_ENGINE_TYPE_SHIFT 28
33 .handle =
ctx->tls_session_handle,
98 memset (
ctx, 0xfb,
sizeof (*
ctx));
128 ctx_index =
ctx->c_c_index;
137 ctx_index =
ctx->c_c_index;
201 TLS_DBG (1,
"failed to allocate fifos");
227 if (
ctx->tls_type == TRANSPORT_PROTO_TLS)
229 ctx->no_app_session = 1;
235 if (
ctx->tls_type == TRANSPORT_PROTO_DTLS)
260 SESSION_E_NONE,
ctx->parent_app_api_context))
262 TLS_DBG (1,
"failed to notify app");
273 ctx->no_app_session = 1;
277 ctx->parent_app_api_context);
335 u32 ctx_index, engine_type;
343 u32 ctx_index, engine_type;
410 ctx->is_passive_close = 1;
411 tc = &
ctx->connection;
460 TLS_DBG (1,
"TCP disconnecting handle %x session %u", tls_session->
opaque,
467 ctx->is_passive_close = 1;
484 memcpy (
ctx, lctx,
sizeof (*lctx));
486 ctx->tls_ctx_handle = ctx_handle;
488 tls_session->
opaque = ctx_handle;
490 ctx->listener_ctx_index = tls_listener->
opaque;
500 TLS_DBG (1,
"Accept on listener %u new connection [%u]%x",
549 ctx->tls_ctx_handle = ctx_handle;
552 TLS_DBG (1,
"TCP connect for %u returned %u. New connection [%u]%x",
554 (
ctx) ? ctx_handle : ~0);
557 tls_session->
opaque = ctx_handle;
604 api_context = ho_ctx->parent_app_api_context;
634 if (!
ctx->no_app_session)
651 ctx->tls_ctx_handle = ctx_handle;
655 us->
flags &= ~SESSION_F_IS_MIGRATING;
660 ctx->no_app_session = 1;
677 ctx->tls_session_handle = new_sh;
679 ctx->is_migrated = 1;
683 (
void *) cloned_ctx);
718 return SESSION_E_NOEXTCFG;
723 ccfg = &sep->ext_cfg->crypto;
728 return SESSION_E_NOCRYPTOENG;
733 ctx->parent_app_wrk_index = sep->app_wrk_index;
734 ctx->parent_app_api_context = sep->opaque;
735 ctx->tcp_is_ip4 = sep->is_ip4;
736 ctx->tls_type = sep->transport_proto;
738 ctx->c_proto = TRANSPORT_PROTO_TLS;
747 ctx->tls_ctx_engine = engine_type;
750 cargs->sep.transport_proto = TRANSPORT_PROTO_TCP;
752 cargs->api_context = ctx_index;
753 cargs->sep_ext.ns_index = app->
ns_index;
758 ctx->tls_session_handle = cargs->sh;
760 TLS_DBG (1,
"New connect request %u engine %d", ctx_index, engine_type);
769 TLS_DBG (1,
"Disconnecting %x", ctx_handle);
795 return SESSION_E_NOEXTCFG;
800 ccfg = &sep->ext_cfg->crypto;
805 return SESSION_E_NOCRYPTOENG;
810 args->sep_ext = *sep;
811 args->sep_ext.ns_index = app->
ns_index;
812 args->sep_ext.transport_proto = TRANSPORT_PROTO_TCP;
813 if (sep->transport_proto == TRANSPORT_PROTO_DTLS)
815 args->sep_ext.transport_proto = TRANSPORT_PROTO_UDP;
822 tls_al_handle = args->handle;
825 tls_listener->
opaque = lctx_index;
830 lctx->parent_app_wrk_index = sep->app_wrk_index;
831 lctx->tls_session_handle = tls_al_handle;
833 lctx->tcp_is_ip4 = sep->is_ip4;
834 lctx->tls_ctx_engine = engine_type;
835 lctx->
tls_type = sep->transport_proto;
838 if (
tls_vfts[engine_type].ctx_start_listen (lctx))
841 .handle = lctx->tls_session_handle,
851 TLS_DBG (1,
"Started listening %d, engine type %d", lctx_index,
872 sep.fib_index = lc->fib_index;
873 sep.port = lc->lcl_port;
874 sep.is_ip4 = lc->is_ip4;
875 sep.transport_proto = lctx->
tls_type;
876 clib_memcpy (&sep.ip, &lc->lcl_ip, sizeof (lc->lcl_ip));
880 .handle = lctx->tls_session_handle,
887 engine_type = lctx->tls_ctx_engine;
899 return &
ctx->connection;
907 return &
ctx->connection;
917 return &
ctx->connection;
928 tcp_sh =
ctx->tls_session_handle;
941 >= SESSION_STATE_TRANSPORT_CLOSED))
952 u32 tcp_si, tcp_ti, ctx_index, ctx_engine;
956 proto =
ctx->tls_type == TRANSPORT_PROTO_TLS ?
"TLS" :
"DTLS";
960 format (s,
"[%d:%d][%s] app_wrk %u index %u engine %u ts %d:%d",
962 ctx->parent_app_wrk_index, ctx_index, ctx_engine, tcp_ti, tcp_si);
977 proto =
ctx->tls_type == TRANSPORT_PROTO_TLS ?
"TLS" :
"DTLS";
980 s =
format (s,
"[%d:%d][%s] app_wrk %u engine %u ts %d:%d",
982 ctx->parent_app_wrk_index,
ctx->tls_ctx_engine,
997 s =
format (s,
"%s",
"LISTEN");
1001 s =
format (s,
"%s",
"CLOSED");
1003 s =
format (s,
"%s",
"APP-CLOSED");
1004 else if (ts->
session_state >= SESSION_STATE_TRANSPORT_CLOSING)
1005 s =
format (s,
"%s",
"CLOSING");
1007 s =
format (s,
"%s",
"ESTABLISHED");
1009 s =
format (s,
"%s",
"HANDSHAKE");
1018 u32 ctx_index = va_arg (*args,
u32);
1020 u32 verbose = va_arg (*args,
u32);
1041 u32 tc_index = va_arg (*args,
u32);
1043 u32 verbose = va_arg (*args,
u32);
1055 u32 ho_index = va_arg (*args,
u32);
1063 s =
format (s,
"[%d:%d][%s] half-open app_wrk %u engine %u ts %d:%d",
1064 ho_ctx->c_thread_index, ho_ctx->c_s_index,
"TLS",
1065 ho_ctx->parent_app_wrk_index, ho_ctx->tls_ctx_engine,
1099 u32 add_segment_size = 256 << 20, first_seg_size = 32 << 20;
1104 u32 fifo_size = 128 << 12;
1160 .transport_options = {
1189 ccfg = &sep->ext_cfg->crypto;
1199 ctx->parent_app_wrk_index = sep->app_wrk_index;
1200 ctx->parent_app_api_context = sep->opaque;
1201 ctx->tcp_is_ip4 = sep->is_ip4;
1203 ctx->tls_type = sep->transport_proto;
1204 ctx->tls_ctx_handle = ctx_handle;
1205 ctx->c_proto = TRANSPORT_PROTO_DTLS;
1213 ctx->tls_ctx_engine = engine_type;
1216 cargs->sep.transport_proto = TRANSPORT_PROTO_UDP;
1218 cargs->api_context = ctx_handle;
1219 cargs->sep_ext.ns_index = app->
ns_index;
1224 TLS_DBG (1,
"New DTLS connect request %x engine %d", ctx_handle,
1254 u32 ho_index = va_arg (*args,
u32);
1262 s =
format (s,
"[%d:%d][%s] half-open app_wrk %u engine %u us %d:%d",
1263 ho_ctx->c_thread_index, ho_ctx->c_s_index,
"DTLS",
1264 ho_ctx->parent_app_wrk_index, ho_ctx->tls_ctx_engine,
1287 .transport_options = {
1340 if (
unformat (input,
"use-test-cert-in-ca"))
1349 if (
tmp >= 0x100000000ULL)
1352 (0,
"fifo-size %llu (0x%llx) too large",
tmp,
tmp);
int tls_app_tx_callback(session_t *tls_session)
int vnet_listen(vnet_listen_args_t *a)
u8 tls_engine
Preferred tls engine.
u32 tls_stop_listen(u32 lctx_index)
#define SESSION_CLI_STATE_LEN
static u8 svm_fifo_set_event(svm_fifo_t *f)
Set fifo event flag.
void tls_ctx_half_open_free(u32 ho_index)
enum crypto_engine_type_ crypto_engine_type_t
static u32 vlib_num_workers()
enum session_error_ session_error_t
static int tls_ctx_transport_close(tls_ctx_t *ctx)
int dtls_session_connected_cb(u32 app_wrk_index, u32 ctx_handle, session_t *us, session_error_t err)
int vnet_connect(vnet_connect_args_t *a)
static int tls_ctx_read(tls_ctx_t *ctx, session_t *tls_session)
description security check failed
@ APP_OPTIONS_RX_FIFO_SIZE
u32 session_index
Index in thread pool where session was allocated.
int tls_notify_app_connected(tls_ctx_t *ctx, session_error_t err)
int(* ctx_write)(tls_ctx_t *ctx, session_t *app_session, transport_send_params_t *sp)
u8 * format_dtls_half_open(u8 *s, va_list *args)
#define clib_memcpy(d, s, n)
int(* ctx_app_close)(tls_ctx_t *ctx)
#define SESSION_CLI_ID_LEN
void session_close(session_t *s)
Initialize session closing procedure.
static u8 * format_tls_ctx_state(u8 *s, va_list *args)
void tls_ctx_half_open_reader_unlock()
static void session_parse_handle(session_handle_t handle, u32 *index, u32 *thread_index)
void session_half_open_delete_notify(transport_connection_t *tc)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static u32 tls_ctx_alloc(crypto_engine_type_t engine_type)
void session_get_endpoint(session_t *s, transport_endpoint_t *tep, u8 is_lcl)
int vnet_unlisten(vnet_unlisten_args_t *a)
static u32 tls_ctx_attach(crypto_engine_type_t engine_type, u32 thread_index, void *ctx)
crypto_engine_type_t tls_get_available_engine(void)
static u64 listen_session_get_handle(session_t *s)
tls_ctx_t * listener_ctx_pool
int tls_add_vpp_q_rx_evt(session_t *s)
static void dtls_cleanup_ho(u32 ho_index)
#define clib_error_return(e, args...)
struct _session_endpoint_cfg session_endpoint_cfg_t
struct _transport_proto_vft transport_proto_vft_t
int tls_notify_app_accept(tls_ctx_t *ctx)
static session_t * listen_session_get(u32 ls_index)
#define SESSION_INVALID_INDEX
void tls_notify_app_enqueue(tls_ctx_t *ctx, session_t *app_session)
int session_half_open_migrated_notify(transport_connection_t *tc)
#define APP_INVALID_INDEX
int vnet_application_detach(vnet_app_detach_args_t *a)
Detach application from vpp.
u8 thread_index
Index of the thread that allocated the session.
#define pool_put(P, E)
Free an object E in pool P.
session_type_t session_type
Type built from transport and network protocol types.
tls_ctx_t * tls_ctx_half_open_get(u32 ctx_index)
transport_proto_t tls_type
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
void transport_connection_reschedule(transport_connection_t *tc)
void session_transport_closed_notify(transport_connection_t *tc)
Notification from transport that it is closed.
void tls_listener_ctx_free(tls_ctx_t *ctx)
transport_connection_t * tls_listener_get(u32 listener_index)
struct _vnet_unlisten_args_t vnet_unlisten_args_t
@ APP_OPTIONS_SEGMENT_SIZE
static u32 session_thread_from_handle(session_handle_t handle)
struct _vnet_app_detach_args_t vnet_app_detach_args_t
struct _transport_connection transport_connection_t
int tls_custom_tx_callback(void *session, transport_send_params_t *sp)
static void clib_rwlock_reader_lock(clib_rwlock_t *p)
int dtls_connect(transport_endpoint_cfg_t *tep)
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
static void clib_rwlock_reader_unlock(clib_rwlock_t *p)
u32 tls_listener_ctx_index(tls_ctx_t *ctx)
void session_free(session_t *s)
#define pool_put_index(p, i)
Free pool element with given index.
static void clib_rwlock_writer_unlock(clib_rwlock_t *p)
#define VLIB_EARLY_CONFIG_FUNCTION(x, n,...)
int(* session_accept_callback)(session_t *new_session)
Notify server of newly accepted session.
static const transport_proto_vft_t tls_proto
#define pool_get_aligned_will_expand(P, YESNO, A)
See if pool_get will expand the pool or not.
void tls_disconnect_transport(tls_ctx_t *ctx)
u8 hostname[256]
full domain len is 255 as per rfc 3986
static int tls_ctx_init_server(tls_ctx_t *ctx)
@ SESSION_CLEANUP_TRANSPORT
application_t * application_get(u32 app_index)
u32 tls_listener_ctx_alloc(void)
void tls_session_reset_callback(session_t *s)
u32 app_wrk_index
Index of the app worker that owns the session.
int app_worker_init_connected(app_worker_t *app_wrk, session_t *s)
#define TLS_DBG(_lvl, _fmt, _args...)
svm_fifo_t * rx_fifo
Pointers to rx/tx buffers.
static const transport_proto_vft_t dtls_proto
@ SESSION_IO_EVT_BUILTIN_RX
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define TRANSPORT_PACER_MIN_MSS
static int tls_add_app_q_evt(app_worker_t *app, session_t *app_session)
int tls_add_vpp_q_builtin_rx_evt(session_t *s)
int(* ctx_stop_listen)(tls_ctx_t *ctx)
static void tls_transport_listener_endpoint_get(u32 ctx_handle, transport_endpoint_t *tep, u8 is_lcl)
struct _vnet_disconnect_args_t vnet_disconnect_args_t
transport_connection_t * session_get_transport(session_t *s)
static_always_inline uword vlib_get_thread_index(void)
app_worker_t * app_worker_get_if_valid(u32 wrk_index)
static void tls_cleanup_ho(u32 ho_index)
struct _vnet_bind_args_t vnet_listen_args_t
u8 tls_ctx_handshake_is_over(tls_ctx_t *ctx)
static void clib_rwlock_writer_lock(clib_rwlock_t *p)
transport_connection_t connection
static transport_connection_t * dtls_half_open_get(u32 ho_index)
tls_ctx_t *(* ctx_get_w_thread)(u32 ctx_index, u8 thread_index)
static u8 vlib_thread_is_main_w_barrier(void)
static void dtls_cleanup_callback(u32 ctx_index, u32 thread_index)
u8 * format_tls_ctx(u8 *s, va_list *args)
static u32 transport_cl_thread(void)
int tls_add_segment_callback(u32 client_index, u64 segment_handle)
void(* ctx_free)(tls_ctx_t *ctx)
void session_send_rpc_evt_to_thread(u32 thread_index, void *fp, void *rpc_args)
static session_handle_t session_handle(session_t *s)
@ TRANSPORT_CFG_F_CONNECTED
u32 ns_index
Namespace the application belongs to.
void session_half_open_migrate_notify(transport_connection_t *tc)
void transport_register_protocol(transport_proto_t transport_proto, const transport_proto_vft_t *vft, fib_protocol_t fib_proto, u32 output_node)
Register transport virtual function table.
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
static session_t * session_get_from_handle(session_handle_t handle)
void session_cleanup_half_open(session_handle_t ho_handle)
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
int tls_session_accept_callback(session_t *tls_session)
int app_worker_init_accepted(session_t *s)
void tls_session_disconnect_callback(session_t *tls_session)
u8 * format_tls_listener(u8 *s, va_list *args)
static tls_engine_vft_t * tls_vfts
int tls_session_connected_cb(u32 tls_app_index, u32 ho_ctx_index, session_t *tls_session, session_error_t err)
static session_t * session_get(u32 si, u32 thread_index)
int vnet_disconnect_session(vnet_disconnect_args_t *a)
void session_transport_delete_notify(transport_connection_t *tc)
Notification from transport that connection is being deleted.
int app_worker_connect_notify(app_worker_t *app_wrk, session_t *s, session_error_t err, u32 opaque)
static void clib_rwlock_init(clib_rwlock_t *p)
static void tls_ctx_parse_handle(u32 ctx_handle, u32 *ctx_index, u32 *engine_type)
static void tls_session_cleanup_ho(session_t *s)
tls_ctx_t * half_open_ctx_pool
static crypto_engine_type_t tls_get_engine_type(crypto_engine_type_t requested, crypto_engine_type_t preferred)
int tls_del_segment_callback(u32 client_index, u64 segment_handle)
@ TRANSPORT_TX_INTERNAL
apps acting as transports
session_handle_t listener_handle
Parent listener session index if the result of an accept.
app_listener_t * app_listener_get_w_handle(session_handle_t handle)
Get app listener for listener session handle.
static session_type_t session_type_from_proto_and_ip(transport_proto_t proto, u8 is_ip4)
u8 * format_tls_half_open(u8 *s, va_list *args)
int tls_connect(transport_endpoint_cfg_t *tep)
int vnet_application_attach(vnet_app_attach_args_t *a)
Attach application to vpp.
@ TRANSPORT_SERVICE_VC
virtual circuit service
#define vec_free(V)
Free vector's memory (no header).
int(* ctx_init_server)(tls_ctx_t *ctx)
int(* ctx_transport_close)(tls_ctx_t *ctx)
static void tls_app_session_cleanup(session_t *s, session_cleanup_ntf_t ntf)
@ APP_OPTIONS_TX_FIFO_SIZE
int tls_session_connected_callback(u32 tls_app_index, u32 ho_ctx_index, session_t *tls_session, session_error_t err)
#define SESSION_ENDPOINT_NULL
@ TRANSPORT_CONNECTION_F_NO_LOOKUP
Don't register connection in lookup.
tls_main_t * vnet_tls_get_main(void)
@ APP_OPTIONS_ADD_SEGMENT_SIZE
static void * tls_ctx_detach(tls_ctx_t *ctx)
description fragment has unexpected format
static u8 * format_tls_listener_ctx(u8 *s, va_list *args)
int(* ctx_init_client)(tls_ctx_t *ctx)
tls_ctx_t *(* ctx_get)(u32 ctx_index)
static session_t * session_get_if_valid(u64 si, u32 thread_index)
u32 opaque
Opaque, for general use.
#define VLIB_INIT_FUNCTION(x)
static struct option options[]
int app_worker_lock_and_send_event(app_worker_t *app, session_t *s, u8 evt_type)
Send event to application.
static clib_error_t * tls_enable(vlib_main_t *vm, u8 is_en)
int(* ctx_read)(tls_ctx_t *ctx, session_t *tls_session)
app_worker_t * app_worker_get(u32 wrk_index)
void tls_disconnect(u32 ctx_handle, u32 thread_index)
u32 tls_start_listen(u32 app_listener_index, transport_endpoint_t *tep)
static void tls_transport_endpoint_get(u32 ctx_handle, u32 thread_index, transport_endpoint_t *tep, u8 is_lcl)
struct _session_endpoint session_endpoint_t
struct _vnet_connect_args vnet_connect_args_t
int tls_add_vpp_q_tx_evt(session_t *s)
u32 tls_ctx_half_open_alloc(void)
static int tls_ctx_app_close(tls_ctx_t *ctx)
static tls_main_t tls_main
static u32 tls_ctx_alloc_w_thread(crypto_engine_type_t engine_type, u32 thread_index)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static transport_proto_t session_get_transport_proto(session_t *s)
#define pool_get_zero(P, E)
Allocate an object E from a pool P and zero it.
static transport_connection_t * tls_half_open_get(u32 ho_index)
static clib_error_t * tls_config_fn(vlib_main_t *vm, unformat_input_t *input)
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
#define vec_terminate_c_string(V)
(If necessary) NULL terminate a vector containing a c-string.
void *(* ctx_detach)(tls_ctx_t *ctx)
int session_lookup_del_session_endpoint2(session_endpoint_t *sep)
#define TLS_ENGINE_TYPE_SHIFT
u8 * format_tls_connection(u8 *s, va_list *args)
transport_snd_flags_t flags
#define clib_warning(format, args...)
u32 tls_ctx_half_open_index(tls_ctx_t *ctx)
u32(* ctx_alloc_w_thread)(u32 thread_index)
tls_ctx_t * tls_listener_ctx_get(u32 ctx_index)
struct _vnet_app_attach_args_t vnet_app_attach_args_t
static clib_error_t * tls_init(vlib_main_t *vm)
u32 app_index
Index of owning app.
static session_cb_vft_t tls_app_cb_vft
void tls_register_engine(const tls_engine_vft_t *vft, crypto_engine_type_t type)
u32(* ctx_attach)(u32 thread_index, void *ctx)
static void dtls_migrate_ctx(void *arg)
void session_transport_reset_notify(transport_connection_t *tc)
Notify application that connection has been reset.
static vlib_thread_main_t * vlib_get_thread_main()
int app_worker_accept_notify(app_worker_t *app_wrk, session_t *s)
session_t * app_listener_get_session(app_listener_t *al)
u8(* ctx_handshake_is_over)(tls_ctx_t *ctx)
session_t * session_alloc(u32 thread_index)
int session_send_io_evt_to_thread(svm_fifo_t *f, session_evt_type_t evt_type)
volatile u8 session_state
State in session layer state machine.
clib_rwlock_t half_open_rwlock
u32 connection_index
Index of the transport connection associated to the session.
static void dtls_session_migrate_callback(session_t *us, session_handle_t new_sh)
static int tls_ctx_init_client(tls_ctx_t *ctx)
static int tls_ctx_write(tls_ctx_t *ctx, session_t *app_session, transport_send_params_t *sp)
void tls_ctx_free(tls_ctx_t *ctx)
transport_connection_t * tls_connection_get(u32 ctx_index, u32 thread_index)
vl_api_fib_path_type_t type
static session_t * listen_session_get_from_handle(session_handle_t handle)
int tls_app_rx_callback(session_t *tls_session)
static u32 svm_fifo_max_dequeue(svm_fifo_t *f)
Fifo max bytes to dequeue.
static tls_ctx_t * tls_ctx_get(u32 ctx_handle)
static tls_ctx_t * tls_ctx_get_w_thread(u32 ctx_handle, u8 thread_index)