Skip to content

Commit 3a706ac

Browse files
florincorasdwallacelf
authored andcommitted
quic: avoid lazy crypto engine init
Init the engines when the plugins start. Type: improvement Change-Id: I8191be86ccb719d314d075d4bbb2571df9041027 Signed-off-by: Florin Coras <fcoras@cisco.com>
1 parent 814f2ad commit 3a706ac

File tree

4 files changed

+41
-53
lines changed

4 files changed

+41
-53
lines changed

src/plugins/quic/quic.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,9 @@ typedef struct quic_main_
263263
vlib_node_registration_t *quic_input_node;
264264
u32 app_index;
265265
quic_worker_ctx_t *wrk_ctx;
266-
u8 vnet_crypto_init;
267-
u8 default_crypto_engine; /**< Used if you do connect with CRYPTO_ENGINE_NONE
268-
(0) */
269-
u64 max_packets_per_key; /**< number of packets that can be sent without a
270-
key update */
266+
u8 enable_vnet_crypto;
267+
u8 default_crypto_engine; /**< Used if you do connect with CRYPTO_ENGINE_NONE (0) */
268+
u64 max_packets_per_key; /**< number of packets that can be sent without a key update */
271269
u8 default_quic_cc;
272270
u8 enable_tx_pacing; /**< enable tx pacing for connections */
273271

src/plugins/quic/quic_cli.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -255,29 +255,23 @@ quic_plugin_crypto_command_fn (vlib_main_t *vm, unformat_input_t *input,
255255
{
256256
if (unformat (line_input, "vpp"))
257257
{
258+
if (!qm->enable_vnet_crypto)
259+
{
260+
e = clib_error_return (0, "vnet crypto was not enabled");
261+
goto done;
262+
}
258263
qm->default_crypto_engine = CRYPTO_ENGINE_VPP;
259-
qm->vnet_crypto_init = 0;
260264
}
261265
else if (unformat (line_input, "engine-lib"))
262266
{
263267
qm->default_crypto_engine =
264268
(qm->engine_type == QUIC_ENGINE_QUICLY) ?
265269
CRYPTO_ENGINE_PICOTLS :
266-
((qm->engine_type == QUIC_ENGINE_OPENSSL) ?
267-
CRYPTO_ENGINE_OPENSSL :
268-
CRYPTO_ENGINE_NONE);
269-
if (qm->default_crypto_engine != CRYPTO_ENGINE_NONE)
270-
{
271-
qm->vnet_crypto_init = 0;
272-
}
273-
else
270+
((qm->engine_type == QUIC_ENGINE_OPENSSL) ? CRYPTO_ENGINE_OPENSSL :
271+
CRYPTO_ENGINE_NONE);
272+
if (qm->default_crypto_engine == CRYPTO_ENGINE_NONE)
274273
{
275-
e = clib_error_return (0,
276-
"No quic engine available, using default "
277-
"crypto engine '%U' (%u)",
278-
format_crypto_engine,
279-
qm->default_crypto_engine,
280-
qm->default_crypto_engine);
274+
e = clib_error_return (0, "No quic engine available");
281275
goto done;
282276
}
283277
}
@@ -543,6 +537,8 @@ quic_config_fn (vlib_main_t *vm, unformat_input_t *input)
543537
qm->udp_fifo_prealloc = i;
544538
else if (unformat (line_input, "no-tx-pacing"))
545539
qm->enable_tx_pacing = 0;
540+
else if (unformat (line_input, "enable-vnet-crypto"))
541+
qm->enable_vnet_crypto = 1;
546542
/* TODO: add cli selection of quic_eng_<types> */
547543
else
548544
{

src/plugins/quic_quicly/quic_quicly_crypto.c

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ void
5151
quic_quicly_crypto_init (quic_quicly_main_t *qqm)
5252
{
5353
quic_quicly_crypto_main_t *qqcm = &quic_quicly_crypto_main;
54+
quic_main_t *qm = qqm->qm;
5455
u8 seed[32];
5556

5657
QUIC_DBG (2, "quic_quicly_crypto init");
58+
5759
qqcm->qqm = qqm;
5860

5961
if (syscall (SYS_getrandom, &seed, sizeof (seed), 0) != sizeof (seed))
@@ -62,6 +64,30 @@ quic_quicly_crypto_init (quic_quicly_main_t *qqm)
6264

6365
clib_bihash_init_24_8 (&qqcm->crypto_ctx_hash, "quic (quicly engine) crypto ctx", 64, 128 << 10);
6466
quic_quicly_register_cipher_suite (CRYPTO_ENGINE_PICOTLS, ptls_openssl_cipher_suites);
67+
68+
if (qm->enable_vnet_crypto)
69+
{
70+
if (vec_len (cm->engines) == 0)
71+
{
72+
clib_warning ("No crypto engines available");
73+
return;
74+
}
75+
if (quic_quicly_register_cipher_suite (CRYPTO_ENGINE_VPP, quic_quicly_crypto_cipher_suites))
76+
{
77+
u8 empty_key[32] = {};
78+
u32 i;
79+
vec_validate (qqcm->per_thread_crypto_ctxs, qm->num_threads);
80+
for (i = 0; i < qm->num_threads; i++)
81+
{
82+
qqcm->per_thread_crypto_ctxs[i] =
83+
vnet_crypto_ctx_create (VNET_CRYPTO_ALG_AES_256_CTR);
84+
if (qqcm->per_thread_crypto_ctxs[i])
85+
vnet_crypto_ctx_set_cipher_key (qqcm->per_thread_crypto_ctxs[i], empty_key, 32);
86+
}
87+
88+
qqcm->vnet_crypto_enabled = 1;
89+
}
90+
}
6591
}
6692

6793
void
@@ -293,38 +319,6 @@ quic_quicly_crypto_context_init_data (quic_quicly_crypto_ctx_t *crctx, quic_ctx_
293319

294320
QUIC_DBG (2, "Init crctx: crctx_ndx 0x%08lx", crctx->ctx.ctx_index);
295321

296-
if (PREDICT_FALSE (!qm->vnet_crypto_init))
297-
{
298-
qm->vnet_crypto_init = 1;
299-
if ((vec_len (cm->engines) == 0) ||
300-
(qm->default_crypto_engine == CRYPTO_ENGINE_PICOTLS))
301-
{
302-
qqcm->vnet_crypto_enabled = 0;
303-
(void) quic_quicly_register_cipher_suite (
304-
CRYPTO_ENGINE_PICOTLS, ptls_openssl_cipher_suites);
305-
}
306-
else
307-
{
308-
qqcm->vnet_crypto_enabled = 1;
309-
if (quic_quicly_register_cipher_suite (
310-
CRYPTO_ENGINE_VPP, quic_quicly_crypto_cipher_suites))
311-
{
312-
u8 empty_key[32] = {};
313-
u32 i;
314-
qm->default_crypto_engine = ctx->crypto_engine =
315-
CRYPTO_ENGINE_VPP;
316-
vec_validate (qqcm->per_thread_crypto_ctxs, qm->num_threads);
317-
for (i = 0; i < qm->num_threads; i++)
318-
{
319-
qqcm->per_thread_crypto_ctxs[i] =
320-
vnet_crypto_ctx_create (VNET_CRYPTO_ALG_AES_256_CTR);
321-
if (qqcm->per_thread_crypto_ctxs[i])
322-
vnet_crypto_ctx_set_cipher_key (qqcm->per_thread_crypto_ctxs[i], empty_key, 32);
323-
}
324-
}
325-
}
326-
}
327-
328322
quicly_ctx = &crctx->quicly_ctx;
329323
ptls_ctx = &crctx->ptls_ctx;
330324

src/plugins/quic_quicly/quic_quicly_crypto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ quic_quicly_crypto_context_reserve_data (quic_quicly_crypto_ctx_t *crctx)
9898

9999
#define quic_quicly_crypto_engine_is_vpp() \
100100
(quic_quicly_crypto_main.vnet_crypto_enabled && \
101-
quic_quicly_crypto_main.qqm->qm->default_crypto_engine)
101+
quic_quicly_crypto_main.qqm->qm->default_crypto_engine == CRYPTO_ENGINE_VPP)
102102

103103
extern quicly_crypto_engine_t quic_quicly_crypto_engine;
104104
extern ptls_cipher_suite_t *quic_quicly_crypto_cipher_suites[];

0 commit comments

Comments
 (0)