FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
quic.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <sys/socket.h>
17 
19 #include <vnet/session/transport.h>
20 #include <vnet/session/session.h>
21 #include <vlib/unix/plugin.h>
22 #include <vpp/app/version.h>
23 
24 #include <vppinfra/lock.h>
25 
26 #include <quic/quic.h>
27 #include <quic/certs.h>
28 #include <quic/error.h>
29 
30 #include <quicly/constants.h>
31 #include <quicly/defaults.h>
32 #include <picotls.h>
33 
34 #include <quic/quic_crypto.h>
35 
36 extern quicly_crypto_engine_t quic_crypto_engine;
37 
38 static char *quic_error_strings[] = {
39 #define quic_error(n,s) s,
40 #include <quic/quic_error.def>
41 #undef quic_error
42 };
43 
44 #define DEFAULT_MAX_PACKETS_PER_KEY 16777216
45 
47 static void quic_update_timer (quic_ctx_t * ctx);
49 static int quic_reset_connection (u64 udp_session_handle,
50  quic_rx_packet_ctx_t * pctx);
51 static void quic_proto_on_close (u32 ctx_index, u32 thread_index);
52 
53 static quicly_stream_open_t on_stream_open;
54 static quicly_closed_by_remote_t on_closed_by_remote;
55 static quicly_now_t quicly_vpp_now_cb;
56 
57 /* Crypto contexts */
58 
59 static inline void
61  quic_ctx_t * ctx)
62 {
63  application_t *app = application_get (ctx->parent_app_id);
64  kv->key[0] = ((u64) ctx->ckpair_index) << 32 | (u64) ctx->crypto_engine;
65  kv->key[1] = app->sm_properties.rx_fifo_size - 1;
66  kv->key[2] = app->sm_properties.tx_fifo_size - 1;
67 }
68 
69 static inline void
71  crypto_context_t * crctx)
72 {
75  kv->key[0] = ((u64) crctx->ckpair_index) << 32 | (u64) crctx->crypto_engine;
76  kv->key[1] = data->quicly_ctx.transport_params.max_stream_data.bidi_local;
77  kv->key[2] = data->quicly_ctx.transport_params.max_stream_data.bidi_remote;
78 }
79 
80 static void
82 {
83  quic_main_t *qm = &quic_main;
85  if (crctx->n_subscribers)
86  return;
88  clib_bihash_add_del_24_8 (&qm->wrk_ctx[thread_index].crypto_context_hash,
89  &kv, 0 /* is_add */ );
90  clib_mem_free (crctx->data);
92 }
93 
94 static int
96 {
97  quic_main_t *qm = &quic_main;
98  crypto_context_t *crctx;
101  int num_threads = 1 /* main thread */ + vtm->n_threads;
102  int i;
103 
104  for (i = 0; i < num_threads; i++)
105  {
106  /* *INDENT-OFF* */
107  pool_foreach (crctx, qm->wrk_ctx[i].crypto_ctx_pool) {
108  if (crctx->ckpair_index == ckpair->cert_key_index)
109  {
111  clib_bihash_add_del_24_8 (&qm->wrk_ctx[i].crypto_context_hash, &kv, 0 /* is_add */ );
112  }
113  }
114  /* *INDENT-ON* */
115  }
116  return 0;
117 }
118 
119 static crypto_context_t *
121 {
122  quic_main_t *qm = &quic_main;
123  crypto_context_t *crctx;
124  u32 idx;
125 
127  clib_memset (crctx, 0, sizeof (*crctx));
128  idx = (crctx - qm->wrk_ctx[thread_index].crypto_ctx_pool);
129  crctx->ctx_index = ((u32) thread_index) << 24 | idx;
130 
131  return crctx;
132 }
133 
134 static crypto_context_t *
136 {
137  quic_main_t *qm = &quic_main;
138  ASSERT (cr_index >> 24 == thread_index);
140  cr_index & 0x00ffffff);
141 }
142 
143 static clib_error_t *
145  unformat_input_t * input,
146  vlib_cli_command_t * cmd)
147 {
148  quic_main_t *qm = &quic_main;
149  crypto_context_t *crctx;
151  int i, num_threads = 1 /* main thread */ + vtm->n_threads;
152  for (i = 0; i < num_threads; i++)
153  {
154  /* *INDENT-OFF* */
155  pool_foreach (crctx, qm->wrk_ctx[i].crypto_ctx_pool) {
156  vlib_cli_output (vm, "[%d][Q]%U", i, format_crypto_context, crctx);
157  }
158  /* *INDENT-ON* */
159  }
160  return 0;
161 }
162 
163 static clib_error_t *
165  unformat_input_t * input,
166  vlib_cli_command_t * cmd)
167 {
168  quic_main_t *qm = &quic_main;
169  unformat_input_t _line_input, *line_input = &_line_input;
170  u64 tmp;
171 
172  if (!unformat_user (input, unformat_line_input, line_input))
173  return 0;
174 
175  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
176  {
177  if (unformat (line_input, "%U", unformat_memory_size, &tmp))
178  {
179  qm->max_packets_per_key = tmp;
180  }
181  else
182  return clib_error_return (0, "unknown input '%U'",
183  format_unformat_error, line_input);
184  }
185 
186  return 0;
187 }
188 
189 static clib_error_t *
191  vlib_cli_command_t *cmd)
192 {
193  unformat_input_t _line_input, *line_input = &_line_input;
194  quic_main_t *qm = &quic_main;
195  clib_error_t *e = 0;
196 
197  if (!unformat_user (input, unformat_line_input, line_input))
198  return 0;
199 
200  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
201  {
202  if (unformat (line_input, "reno"))
204  else if (unformat (line_input, "cubic"))
206  else
207  {
208  e = clib_error_return (0, "unknown input '%U'",
209  format_unformat_error, line_input);
210  goto done;
211  }
212  }
213 done:
214  unformat_free (line_input);
215  return e;
216 }
217 
218 static void
220 {
221  crypto_context_t *crctx;
222  crctx = quic_crypto_context_get (crypto_context_index, thread_index);
223  crctx->n_subscribers--;
225 }
226 
227 static int
229 {
230  quic_main_t *qm = &quic_main;
231  quicly_context_t *quicly_ctx;
232  ptls_iovec_t key_vec;
233  app_cert_key_pair_t *ckpair;
234  application_t *app;
236  ptls_context_t *ptls_ctx;
237 
238  QUIC_DBG (2, "Init quic crctx %d thread %d", crctx->ctx_index,
239  ctx->c_thread_index);
240 
241  data = clib_mem_alloc (sizeof (*data));
242  /* picotls depends on data being zeroed */
243  clib_memset (data, 0, sizeof (*data));
244  crctx->data = (void *) data;
245  quicly_ctx = &data->quicly_ctx;
246  ptls_ctx = &data->ptls_ctx;
247 
248  ptls_ctx->random_bytes = ptls_openssl_random_bytes;
249  ptls_ctx->get_time = &ptls_get_time;
250  ptls_ctx->key_exchanges = ptls_openssl_key_exchanges;
251  ptls_ctx->cipher_suites = qm->quic_ciphers[ctx->crypto_engine];
252  ptls_ctx->certificates.list = NULL;
253  ptls_ctx->certificates.count = 0;
254  ptls_ctx->esni = NULL;
255  ptls_ctx->on_client_hello = NULL;
256  ptls_ctx->emit_certificate = NULL;
257  ptls_ctx->sign_certificate = NULL;
258  ptls_ctx->verify_certificate = NULL;
259  ptls_ctx->ticket_lifetime = 86400;
260  ptls_ctx->max_early_data_size = 8192;
261  ptls_ctx->hkdf_label_prefix__obsolete = NULL;
262  ptls_ctx->require_dhe_on_psk = 1;
263  ptls_ctx->encrypt_ticket = &qm->session_cache.super;
264  clib_memcpy (quicly_ctx, &quicly_spec_context, sizeof (quicly_context_t));
265 
266  quicly_ctx->max_packets_per_key = qm->max_packets_per_key;
267  quicly_ctx->tls = ptls_ctx;
268  quicly_ctx->stream_open = &on_stream_open;
269  quicly_ctx->closed_by_remote = &on_closed_by_remote;
270  quicly_ctx->now = &quicly_vpp_now_cb;
271  quicly_amend_ptls_context (quicly_ctx->tls);
272 
273  if (qm->vnet_crypto_enabled &&
275  quicly_ctx->crypto_engine = &quic_crypto_engine;
276  else
277  quicly_ctx->crypto_engine = &quicly_default_crypto_engine;
278 
279  quicly_ctx->transport_params.max_data = QUIC_INT_MAX;
280  quicly_ctx->transport_params.max_streams_uni = (uint64_t) 1 << 60;
281  quicly_ctx->transport_params.max_streams_bidi = (uint64_t) 1 << 60;
282  quicly_ctx->transport_params.max_idle_timeout = qm->connection_timeout;
283 
284  if (qm->default_quic_cc == QUIC_CC_CUBIC)
285  quicly_ctx->init_cc = &quicly_cc_cubic_init;
286  else if (qm->default_quic_cc == QUIC_CC_RENO)
287  quicly_ctx->init_cc = &quicly_cc_reno_init;
288 
289  app = application_get (ctx->parent_app_id);
290  quicly_ctx->transport_params.max_stream_data.bidi_local =
291  app->sm_properties.rx_fifo_size - 1;
292  quicly_ctx->transport_params.max_stream_data.bidi_remote =
293  app->sm_properties.tx_fifo_size - 1;
294  quicly_ctx->transport_params.max_stream_data.uni = QUIC_INT_MAX;
295 
296  quicly_ctx->transport_params.max_udp_payload_size = QUIC_MAX_PACKET_SIZE;
297  if (!app->quic_iv_set)
298  {
299  ptls_openssl_random_bytes (app->quic_iv, QUIC_IV_LEN - 1);
300  app->quic_iv[QUIC_IV_LEN - 1] = 0;
301  app->quic_iv_set = 1;
302  }
303 
304  clib_memcpy (data->cid_key, app->quic_iv, QUIC_IV_LEN);
305  key_vec = ptls_iovec_init (data->cid_key, QUIC_IV_LEN);
306  quicly_ctx->cid_encryptor =
307  quicly_new_default_cid_encryptor (&ptls_openssl_bfecb,
308  &ptls_openssl_aes128ecb,
309  &ptls_openssl_sha256, key_vec);
310 
312  if (!ckpair || !ckpair->key || !ckpair->cert)
313  {
314  QUIC_DBG (1, "Wrong ckpair id %d\n", crctx->ckpair_index);
315  return -1;
316  }
317  if (load_bio_private_key (quicly_ctx->tls, (char *) ckpair->key))
318  {
319  QUIC_DBG (1, "failed to read private key from app configuration\n");
320  return -1;
321  }
322  if (load_bio_certificate_chain (quicly_ctx->tls, (char *) ckpair->cert))
323  {
324  QUIC_DBG (1, "failed to load certificate\n");
325  return -1;
326  }
327  return 0;
328 
329 }
330 
331 static int
333 {
334  quic_main_t *qm = &quic_main;
335  crypto_context_t *crctx;
337 
338  if (ctx->crypto_engine == CRYPTO_ENGINE_NONE)
339  {
340  QUIC_DBG (2, "No crypto engine specified, using %d",
342  ctx->crypto_engine = qm->default_crypto_engine;
343  }
344  if (!clib_bitmap_get (qm->available_crypto_engines, ctx->crypto_engine))
345  {
346  QUIC_DBG (1, "Quic does not support crypto engine %d",
347  ctx->crypto_engine);
348  return SESSION_E_NOCRYPTOENG;
349  }
350 
351  /* Check for exisiting crypto ctx */
353  if (clib_bihash_search_24_8
354  (&qm->wrk_ctx[ctx->c_thread_index].crypto_context_hash, &kv, &kv) == 0)
355  {
356  crctx = quic_crypto_context_get (kv.value, ctx->c_thread_index);
357  QUIC_DBG (2, "Found exisiting crypto context %d", kv.value);
358  ctx->crypto_context_index = kv.value;
359  crctx->n_subscribers++;
360  return 0;
361  }
362 
363  crctx = quic_crypto_context_alloc (ctx->c_thread_index);
364  ctx->crypto_context_index = crctx->ctx_index;
365  kv.value = crctx->ctx_index;
366  crctx->crypto_engine = ctx->crypto_engine;
367  crctx->ckpair_index = ctx->ckpair_index;
368  if (quic_init_crypto_context (crctx, ctx))
369  goto error;
370  if (vnet_app_add_cert_key_interest (ctx->ckpair_index, qm->app_index))
371  goto error;
372  crctx->n_subscribers++;
373  clib_bihash_add_del_24_8 (&qm->
374  wrk_ctx[ctx->c_thread_index].crypto_context_hash,
375  &kv, 1 /* is_add */ );
376  return 0;
377 
378 error:
379  quic_crypto_context_free_if_needed (crctx, ctx->c_thread_index);
380  return SESSION_E_NOCRYPTOCKP;
381 }
382 
383 /* Helper functions */
384 
385 static u32
387 {
388  quic_main_t *qm = &quic_main;
389  quic_ctx_t *ctx;
390 
392 
393  clib_memset (ctx, 0, sizeof (quic_ctx_t));
394  ctx->c_thread_index = thread_index;
395  ctx->timer_handle = QUIC_TIMER_HANDLE_INVALID;
396  QUIC_DBG (3, "Allocated quic_ctx %u on thread %u",
398  return ctx - qm->ctx_pool[thread_index];
399 }
400 
401 static void
403 {
404  QUIC_DBG (2, "Free ctx %u %x", ctx->c_thread_index, ctx->c_c_index);
405  u32 thread_index = ctx->c_thread_index;
406  QUIC_ASSERT (ctx->timer_handle == QUIC_TIMER_HANDLE_INVALID);
407  if (CLIB_DEBUG)
408  clib_memset (ctx, 0xfb, sizeof (*ctx));
410 }
411 
412 static quic_ctx_t *
414 {
415  return pool_elt_at_index (quic_main.ctx_pool[thread_index], ctx_index);
416 }
417 
418 static quic_ctx_t *
420 {
422  return 0;
423  return pool_elt_at_index (quic_main.ctx_pool[thread_index], ctx_index);
424 }
425 
426 quic_ctx_t *
427 quic_get_conn_ctx (quicly_conn_t * conn)
428 {
429  u64 conn_data;
430  conn_data = (u64) * quicly_get_data (conn);
431  return quic_ctx_get (conn_data & UINT32_MAX, conn_data >> 32);
432 }
433 
434 static void
435 quic_store_conn_ctx (quicly_conn_t * conn, quic_ctx_t * ctx)
436 {
437  *quicly_get_data (conn) =
438  (void *) (((u64) ctx->c_thread_index) << 32 | (u64) ctx->c_c_index);
439 }
440 
441 static inline int
443 {
444  return (ctx->flags & QUIC_F_IS_STREAM);
445 }
446 
447 static inline int
449 {
450  return (ctx->flags & QUIC_F_IS_LISTENER);
451 }
452 
453 static inline int
455 {
457 }
458 
459 static inline session_t *
460 get_stream_session_and_ctx_from_stream (quicly_stream_t * stream,
461  quic_ctx_t ** ctx)
462 {
463  quic_stream_data_t *stream_data;
464 
465  stream_data = (quic_stream_data_t *) stream->data;
466  *ctx = quic_ctx_get (stream_data->ctx_id, stream_data->thread_index);
467  return session_get ((*ctx)->c_s_index, stream_data->thread_index);
468 }
469 
470 static inline void
472  const quicly_cid_plaintext_t * id)
473 {
474  kv->key[0] = ((u64) id->master_id) << 32 | (u64) id->thread_id;
475  kv->key[1] = id->node_id;
476 }
477 
478 static int
480 {
481  u32 max_enqueue;
483  max_enqueue = svm_fifo_max_enqueue (udp_session->tx_fifo);
484  return clib_min (max_enqueue / packet_size, QUIC_SEND_PACKET_VEC_SIZE);
485 }
486 
487 static quicly_context_t *
489 {
490  crypto_context_t *crctx =
491  quic_crypto_context_get (ctx->crypto_context_index, ctx->c_thread_index);
493  (quic_crypto_context_data_t *) crctx->data;
494  return &data->quicly_ctx;
495 }
496 
497 static quicly_context_t *
498 quic_get_quicly_ctx_from_udp (u64 udp_session_handle)
499 {
500  session_t *udp_session = session_get_from_handle (udp_session_handle);
501  quic_ctx_t *ctx =
502  quic_ctx_get (udp_session->opaque, udp_session->thread_index);
504 }
505 
506 static inline void
508 {
509  int rv = 0;
510  if (svm_fifo_set_event (udp_session->tx_fifo))
511  rv = session_send_io_evt_to_thread (udp_session->tx_fifo,
513  if (PREDICT_FALSE (rv))
514  clib_warning ("Event enqueue errored %d", rv);
515 }
516 
517 static inline void
519 {
520  tw_timer_wheel_1t_3w_1024sl_ov_t *tw;
521  if (ctx->timer_handle == QUIC_TIMER_HANDLE_INVALID)
522  return;
523  tw = &quic_main.wrk_ctx[ctx->c_thread_index].timer_wheel;
524  tw_timer_stop_1t_3w_1024sl_ov (tw, ctx->timer_handle);
525  ctx->timer_handle = QUIC_TIMER_HANDLE_INVALID;
526  QUIC_DBG (4, "Stopping timer for ctx %u", ctx->c_c_index);
527 }
528 
529 /* QUIC protocol actions */
530 
531 static void
532 quic_ack_rx_data (session_t * stream_session)
533 {
534  u32 max_deq;
535  quic_ctx_t *sctx;
536  svm_fifo_t *f;
537  quicly_stream_t *stream;
538  quic_stream_data_t *stream_data;
539 
540  sctx = quic_ctx_get (stream_session->connection_index,
541  stream_session->thread_index);
543  stream = sctx->stream;
544  stream_data = (quic_stream_data_t *) stream->data;
545 
546  f = stream_session->rx_fifo;
547  max_deq = svm_fifo_max_dequeue (f);
548 
549  QUIC_ASSERT (stream_data->app_rx_data_len >= max_deq);
550  quicly_stream_sync_recvbuf (stream, stream_data->app_rx_data_len - max_deq);
551  QUIC_DBG (3, "Acking %u bytes", stream_data->app_rx_data_len - max_deq);
552  stream_data->app_rx_data_len = max_deq;
553 }
554 
555 static void
557 {
558  QUIC_DBG (2, "Disconnecting transport 0x%lx", ctx->udp_session_handle);
560  .handle = ctx->udp_session_handle,
561  .app_index = quic_main.app_index,
562  };
563 
564  if (vnet_disconnect_session (&a))
565  clib_warning ("UDP session 0x%lx disconnect errored",
566  ctx->udp_session_handle);
567 }
568 
569 static void
571 {
573  quicly_conn_t *conn;
574 
575  if (ctx->conn == NULL)
576  {
577  QUIC_DBG (2, "Skipping redundant delete of connection %u",
578  ctx->c_c_index);
579  return;
580  }
581  QUIC_DBG (2, "Deleting connection %u", ctx->c_c_index);
582 
585 
586  /* Delete the connection from the connection map */
587  conn = ctx->conn;
588  ctx->conn = NULL;
589  quic_make_connection_key (&kv, quicly_get_master_id (conn));
590  QUIC_DBG (2, "Deleting conn with id %lu %lu from map", kv.key[0],
591  kv.key[1]);
592  clib_bihash_add_del_16_8 (&quic_main.connection_hash, &kv, 0 /* is_add */ );
593 
595 
596  if (conn)
597  quicly_free (conn);
598  session_transport_delete_notify (&ctx->connection);
599 }
600 
601 void
603 {
606 }
607 
608 /**
609  * Called when quicly return an error
610  * This function interacts tightly with quic_proto_on_close
611  */
612 static void
614 {
615  QUIC_DBG (2, "QUIC connection %u/%u closed", ctx->c_thread_index,
616  ctx->c_c_index);
617 
618  /* TODO if connection is not established, just delete the session? */
619  /* Actually should send connect or accept error */
620 
621  switch (ctx->conn_state)
622  {
624  /* Error on an opened connection (timeout...)
625  This puts the session in closing state, we should receive a notification
626  when the app has closed its session */
627  session_transport_reset_notify (&ctx->connection);
628  /* This ensures we delete the connection when the app confirms the close */
630  break;
633  /* quic_proto_on_close will eventually be called when the app confirms the close
634  , we delete the connection at that point */
635  break;
637  /* App already confirmed close, we can delete the connection */
639  break;
644  break;
645  default:
646  QUIC_DBG (0, "BUG %d", ctx->conn_state);
647  break;
648  }
649 }
650 
651 static int
652 quic_send_datagram (session_t *udp_session, struct iovec *packet,
653  quicly_address_t *dest, quicly_address_t *src)
654 {
655  u32 max_enqueue, len;
657  svm_fifo_t *f;
659  int ret;
660 
661  len = packet->iov_len;
662  f = udp_session->tx_fifo;
663  tc = session_get_transport (udp_session);
664  max_enqueue = svm_fifo_max_enqueue (f);
665  if (max_enqueue < SESSION_CONN_HDR_LEN + len)
666  {
667  QUIC_ERR ("Too much data to send, max_enqueue %u, len %u",
668  max_enqueue, len + SESSION_CONN_HDR_LEN);
669  return QUIC_ERROR_FULL_FIFO;
670  }
671 
672  /* Build packet header for fifo */
673  hdr.data_length = len;
674  hdr.data_offset = 0;
675  hdr.is_ip4 = tc->is_ip4;
676  clib_memcpy (&hdr.lcl_ip, &tc->lcl_ip, sizeof (ip46_address_t));
677  hdr.lcl_port = tc->lcl_port;
678 
679  /* Read dest address from quicly-provided sockaddr */
680  if (hdr.is_ip4)
681  {
682  QUIC_ASSERT (dest->sa.sa_family == AF_INET);
683  struct sockaddr_in *sa4 = (struct sockaddr_in *) &dest->sa;
684  hdr.rmt_port = sa4->sin_port;
685  hdr.rmt_ip.ip4.as_u32 = sa4->sin_addr.s_addr;
686  }
687  else
688  {
689  QUIC_ASSERT (dest->sa.sa_family == AF_INET6);
690  struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) &dest->sa;
691  hdr.rmt_port = sa6->sin6_port;
692  clib_memcpy_fast (&hdr.rmt_ip.ip6, &sa6->sin6_addr, 16);
693  }
694 
695  svm_fifo_seg_t segs[2] = { { (u8 *) &hdr, sizeof (hdr) },
696  { packet->iov_base, len } };
697 
698  ret = svm_fifo_enqueue_segments (f, segs, 2, 0 /* allow partial */);
699  if (PREDICT_FALSE (ret < 0))
700  {
701  QUIC_ERR ("Not enough space to enqueue dgram");
702  return QUIC_ERROR_FULL_FIFO;
703  }
704 
705  quic_increment_counter (QUIC_ERROR_TX_PACKETS, 1);
706 
707  return 0;
708 }
709 
710 static int
712 {
713  struct iovec packets[QUIC_SEND_PACKET_VEC_SIZE];
714  uint8_t
716  ->transport_params.max_udp_payload_size];
717  session_t *udp_session;
718  quicly_conn_t *conn;
719  size_t num_packets, i, max_packets;
720  quicly_address_t dest, src;
721  u32 n_sent = 0;
722  int err = 0;
723 
724  /* We have sctx, get qctx */
725  if (quic_ctx_is_stream (ctx))
726  ctx = quic_ctx_get (ctx->quic_connection_ctx_id, ctx->c_thread_index);
727 
729 
730  udp_session = session_get_from_handle_if_valid (ctx->udp_session_handle);
731  if (!udp_session)
732  goto quicly_error;
733 
734  conn = ctx->conn;
735  if (!conn)
736  return 0;
737 
738  do
739  {
740  /* TODO : quicly can assert it can send min_packets up to 2 */
741  max_packets = quic_sendable_packet_count (udp_session);
742  if (max_packets < 2)
743  break;
744 
745  num_packets = max_packets;
746  if ((err = quicly_send (conn, &dest, &src, packets, &num_packets, buf,
747  sizeof (buf))))
748  goto quicly_error;
749 
750  for (i = 0; i != num_packets; ++i)
751  {
752 
753  if ((err =
754  quic_send_datagram (udp_session, &packets[i], &dest, &src)))
755  goto quicly_error;
756 
757  }
758  n_sent += num_packets;
759  }
760  while (num_packets > 0 && num_packets == max_packets);
761 
762  quic_set_udp_tx_evt (udp_session);
763 
764  QUIC_DBG (3, "%u[TX] %u[RX]", svm_fifo_max_dequeue (udp_session->tx_fifo),
765  svm_fifo_max_dequeue (udp_session->rx_fifo));
767  return n_sent;
768 
769 quicly_error:
770  if (err && err != QUICLY_ERROR_PACKET_IGNORED
771  && err != QUICLY_ERROR_FREE_CONNECTION)
772  clib_warning ("Quic error '%U'.", quic_format_err, err);
774  return 0;
775 }
776 
777 /* Quicly callbacks */
778 
779 static void
780 quic_on_stream_destroy (quicly_stream_t * stream, int err)
781 {
782  quic_stream_data_t *stream_data = (quic_stream_data_t *) stream->data;
783  quic_ctx_t *sctx = quic_ctx_get (stream_data->ctx_id,
784  stream_data->thread_index);
785  session_t *stream_session = session_get (sctx->c_s_index,
786  sctx->c_thread_index);
787  QUIC_DBG (2, "DESTROYED_STREAM: session 0x%lx (%U)",
788  session_handle (stream_session), quic_format_err, err);
789 
790  stream_session->session_state = SESSION_STATE_CLOSED;
791  session_transport_delete_notify (&sctx->connection);
792 
793  quic_increment_counter (QUIC_ERROR_CLOSED_STREAM, 1);
794  quic_ctx_free (sctx);
795  clib_mem_free (stream->data);
796 }
797 
798 static void
799 quic_on_stop_sending (quicly_stream_t * stream, int err)
800 {
801 #if QUIC_DEBUG >= 2
802  quic_stream_data_t *stream_data = (quic_stream_data_t *) stream->data;
803  quic_ctx_t *sctx = quic_ctx_get (stream_data->ctx_id,
804  stream_data->thread_index);
805  session_t *stream_session = session_get (sctx->c_s_index,
806  sctx->c_thread_index);
807  clib_warning ("(NOT IMPLEMENTD) STOP_SENDING: session 0x%lx (%U)",
808  session_handle (stream_session), quic_format_err, err);
809 #endif
810  /* TODO : handle STOP_SENDING */
811 }
812 
813 static void
814 quic_on_receive_reset (quicly_stream_t * stream, int err)
815 {
816  quic_stream_data_t *stream_data = (quic_stream_data_t *) stream->data;
817  quic_ctx_t *sctx = quic_ctx_get (stream_data->ctx_id,
818  stream_data->thread_index);
819 #if QUIC_DEBUG >= 2
820  session_t *stream_session = session_get (sctx->c_s_index,
821  sctx->c_thread_index);
822  clib_warning ("RESET_STREAM: session 0x%lx (%U)",
823  session_handle (stream_session), quic_format_err, err);
824 #endif
825  session_transport_closing_notify (&sctx->connection);
826 }
827 
828 static void
829 quic_on_receive (quicly_stream_t * stream, size_t off, const void *src,
830  size_t len)
831 {
832  QUIC_DBG (3, "received data: %lu bytes, offset %lu", len, off);
833  u32 max_enq, rlen, rv;
834  quic_ctx_t *sctx;
835  session_t *stream_session;
836  app_worker_t *app_wrk;
837  svm_fifo_t *f;
838  quic_stream_data_t *stream_data;
839 
840  if (!len)
841  return;
842 
843  stream_data = (quic_stream_data_t *) stream->data;
844  sctx = quic_ctx_get (stream_data->ctx_id, stream_data->thread_index);
845  stream_session = session_get (sctx->c_s_index, stream_data->thread_index);
846  f = stream_session->rx_fifo;
847 
848  max_enq = svm_fifo_max_enqueue_prod (f);
849  QUIC_DBG (3, "Enqueuing %u at off %u in %u space", len, off, max_enq);
850  /* Handle duplicate packet/chunk from quicly */
851  if (off < stream_data->app_rx_data_len)
852  {
853  QUIC_DBG (3, "Session [idx %u, app_wrk %u, thread %u, rx-fifo 0x%llx]: "
854  "DUPLICATE PACKET (max_enq %u, len %u, "
855  "app_rx_data_len %u, off %u, ToBeNQ %u)",
856  stream_session->session_index,
857  stream_session->app_wrk_index,
858  stream_session->thread_index, f,
859  max_enq, len, stream_data->app_rx_data_len, off,
860  off - stream_data->app_rx_data_len + len);
861  return;
862  }
863  if (PREDICT_FALSE ((off - stream_data->app_rx_data_len + len) > max_enq))
864  {
865  QUIC_ERR ("Session [idx %u, app_wrk %u, thread %u, rx-fifo 0x%llx]: "
866  "RX FIFO IS FULL (max_enq %u, len %u, "
867  "app_rx_data_len %u, off %u, ToBeNQ %u)",
868  stream_session->session_index,
869  stream_session->app_wrk_index,
870  stream_session->thread_index, f,
871  max_enq, len, stream_data->app_rx_data_len, off,
872  off - stream_data->app_rx_data_len + len);
873  return; /* This shouldn't happen */
874  }
875  if (off == stream_data->app_rx_data_len)
876  {
877  /* Streams live on the same thread so (f, stream_data) should stay consistent */
878  rlen = svm_fifo_enqueue (f, len, (u8 *) src);
879  QUIC_DBG (3, "Session [idx %u, app_wrk %u, ti %u, rx-fifo 0x%llx]: "
880  "Enqueuing %u (rlen %u) at off %u in %u space, ",
881  stream_session->session_index,
882  stream_session->app_wrk_index,
883  stream_session->thread_index, f, len, rlen, off, max_enq);
884  stream_data->app_rx_data_len += rlen;
885  QUIC_ASSERT (rlen >= len);
886  app_wrk = app_worker_get_if_valid (stream_session->app_wrk_index);
887  if (PREDICT_TRUE (app_wrk != 0))
888  {
889  rv = app_worker_lock_and_send_event (app_wrk, stream_session,
891  if (rv)
892  QUIC_ERR ("Failed to ping app for RX");
893  }
894  quic_ack_rx_data (stream_session);
895  }
896  else
897  {
899  off - stream_data->app_rx_data_len,
900  len, (u8 *) src);
901  QUIC_ASSERT (rlen == 0);
902  }
903  return;
904 }
905 
906 void
907 quic_fifo_egress_shift (quicly_stream_t * stream, size_t delta)
908 {
909  quic_stream_data_t *stream_data;
910  session_t *stream_session;
911  quic_ctx_t *ctx;
912  svm_fifo_t *f;
913  u32 rv;
914 
915  stream_data = (quic_stream_data_t *) stream->data;
916  stream_session = get_stream_session_and_ctx_from_stream (stream, &ctx);
917  f = stream_session->tx_fifo;
918 
919  QUIC_ASSERT (stream_data->app_tx_data_len >= delta);
920  stream_data->app_tx_data_len -= delta;
921  ctx->bytes_written += delta;
922  rv = svm_fifo_dequeue_drop (f, delta);
923  QUIC_ASSERT (rv == delta);
924 
925  rv = quicly_stream_sync_sendbuf (stream, 0);
926  QUIC_ASSERT (!rv);
927 }
928 
929 void
930 quic_fifo_egress_emit (quicly_stream_t * stream, size_t off, void *dst,
931  size_t * len, int *wrote_all)
932 {
933  quic_stream_data_t *stream_data;
934  quic_ctx_t *ctx;
935  session_t *stream_session;
936  svm_fifo_t *f;
937  u32 deq_max;
938 
939  stream_data = (quic_stream_data_t *) stream->data;
940  stream_session = get_stream_session_and_ctx_from_stream (stream, &ctx);
941  f = stream_session->tx_fifo;
942 
943  QUIC_DBG (3, "Emitting %u, offset %u", *len, off);
944 
945  deq_max = svm_fifo_max_dequeue_cons (f);
946  QUIC_ASSERT (off <= deq_max);
947  if (off + *len < deq_max)
948  {
949  *wrote_all = 0;
950  }
951  else
952  {
953  *wrote_all = 1;
954  *len = deq_max - off;
955  }
956  QUIC_ASSERT (*len > 0);
957 
958  if (off + *len > stream_data->app_tx_data_len)
959  stream_data->app_tx_data_len = off + *len;
960 
961  svm_fifo_peek (f, off, *len, dst);
962 }
963 
964 static const quicly_stream_callbacks_t quic_stream_callbacks = {
965  .on_destroy = quic_on_stream_destroy,
966  .on_send_shift = quic_fifo_egress_shift,
967  .on_send_emit = quic_fifo_egress_emit,
968  .on_send_stop = quic_on_stop_sending,
969  .on_receive = quic_on_receive,
970  .on_receive_reset = quic_on_receive_reset
971 };
972 
973 static int
974 quic_on_stream_open (quicly_stream_open_t * self, quicly_stream_t * stream)
975 {
976  /* Return code for this function ends either
977  * - in quicly_receive : if not QUICLY_ERROR_PACKET_IGNORED, will close connection
978  * - in quicly_open_stream, returned directly
979  */
980 
981  session_t *stream_session, *quic_session;
982  quic_stream_data_t *stream_data;
983  app_worker_t *app_wrk;
984  quic_ctx_t *qctx, *sctx;
985  u32 sctx_id;
986  int rv;
987 
988  QUIC_DBG (2, "on_stream_open called");
989  stream->data = clib_mem_alloc (sizeof (quic_stream_data_t));
990  stream->callbacks = &quic_stream_callbacks;
991  /* Notify accept on parent qsession, but only if this is not a locally
992  * initiated stream */
993  if (quicly_stream_is_self_initiated (stream))
994  return 0;
995 
996  sctx_id = quic_ctx_alloc (vlib_get_thread_index ());
997  qctx = quic_get_conn_ctx (stream->conn);
998 
999  /* Might need to signal that the connection is ready if the first thing the
1000  * server does is open a stream */
1002  /* ctx might be invalidated */
1003  qctx = quic_get_conn_ctx (stream->conn);
1004 
1005  stream_session = session_alloc (qctx->c_thread_index);
1006  QUIC_DBG (2, "ACCEPTED stream_session 0x%lx ctx %u",
1007  session_handle (stream_session), sctx_id);
1008  sctx = quic_ctx_get (sctx_id, qctx->c_thread_index);
1009  sctx->parent_app_wrk_id = qctx->parent_app_wrk_id;
1010  sctx->parent_app_id = qctx->parent_app_id;
1011  sctx->quic_connection_ctx_id = qctx->c_c_index;
1012  sctx->c_c_index = sctx_id;
1013  sctx->c_s_index = stream_session->session_index;
1014  sctx->stream = stream;
1015  sctx->c_flags |= TRANSPORT_CONNECTION_F_NO_LOOKUP;
1016  sctx->flags |= QUIC_F_IS_STREAM;
1018  if (quicly_stream_is_unidirectional (stream->stream_id))
1019  stream_session->flags |= SESSION_F_UNIDIRECTIONAL;
1020 
1021  stream_data = (quic_stream_data_t *) stream->data;
1022  stream_data->ctx_id = sctx_id;
1023  stream_data->thread_index = sctx->c_thread_index;
1024  stream_data->app_rx_data_len = 0;
1025  stream_data->app_tx_data_len = 0;
1026 
1027  sctx->c_s_index = stream_session->session_index;
1028  stream_session->session_state = SESSION_STATE_CREATED;
1029  stream_session->app_wrk_index = sctx->parent_app_wrk_id;
1030  stream_session->connection_index = sctx->c_c_index;
1031  stream_session->session_type =
1032  session_type_from_proto_and_ip (TRANSPORT_PROTO_QUIC, qctx->udp_is_ip4);
1033  quic_session = session_get (qctx->c_s_index, qctx->c_thread_index);
1034  stream_session->listener_handle = listen_session_get_handle (quic_session);
1035 
1036  app_wrk = app_worker_get (stream_session->app_wrk_index);
1037  if ((rv = app_worker_init_connected (app_wrk, stream_session)))
1038  {
1039  QUIC_ERR ("failed to allocate fifos");
1040  quicly_reset_stream (stream, QUIC_APP_ALLOCATION_ERROR);
1041  return 0; /* Frame is still valid */
1042  }
1043  svm_fifo_add_want_deq_ntf (stream_session->rx_fifo,
1046 
1047  if ((rv = app_worker_accept_notify (app_wrk, stream_session)))
1048  {
1049  QUIC_ERR ("failed to notify accept worker app");
1050  quicly_reset_stream (stream, QUIC_APP_ACCEPT_NOTIFY_ERROR);
1051  return 0; /* Frame is still valid */
1052  }
1053 
1054  return 0;
1055 }
1056 
1057 static void
1058 quic_on_closed_by_remote (quicly_closed_by_remote_t *self, quicly_conn_t *conn,
1059  int code, uint64_t frame_type, const char *reason,
1060  size_t reason_len)
1061 {
1062  quic_ctx_t *ctx = quic_get_conn_ctx (conn);
1063 #if QUIC_DEBUG >= 2
1064  session_t *quic_session = session_get (ctx->c_s_index, ctx->c_thread_index);
1065  clib_warning ("Session 0x%lx closed by peer (%U) %.*s ",
1066  session_handle (quic_session), quic_format_err, code,
1067  reason_len, reason);
1068 #endif
1069  ctx->conn_state = QUIC_CONN_STATE_PASSIVE_CLOSING;
1070  session_transport_closing_notify (&ctx->connection);
1071 }
1072 
1073 /* Timer handling */
1074 
1075 static int64_t
1077 {
1079 }
1080 
1081 static int64_t
1082 quic_get_time (quicly_now_t * self)
1083 {
1086 }
1087 
1088 static u32
1090 {
1092  f64 time = vlib_time_now (vlib_main);
1093  quic_main.wrk_ctx[thread_index].time_now = (int64_t) (time * 1000.f);
1095 }
1096 
1097 /* Transport proto callback */
1098 static void
1100 {
1101  tw_timer_wheel_1t_3w_1024sl_ov_t *tw;
1102 
1105  tw_timer_expire_timers_1t_3w_1024sl_ov (tw, now);
1106 }
1107 
1108 static void
1110 {
1111  quic_ctx_t *ctx;
1112  QUIC_DBG (4, "Timer expired for conn %u at %ld", conn_index,
1113  quic_get_time (NULL));
1114  ctx = quic_ctx_get (conn_index, vlib_get_thread_index ());
1115  ctx->timer_handle = QUIC_TIMER_HANDLE_INVALID;
1117 }
1118 
1119 static void
1121 {
1122  tw_timer_wheel_1t_3w_1024sl_ov_t *tw;
1123  int64_t next_timeout, next_interval;
1124  session_t *quic_session;
1125  int rv;
1126 
1127  /* This timeout is in ms which is the unit of our timer */
1128  next_timeout = quicly_get_first_timeout (ctx->conn);
1129  next_interval = next_timeout - quic_get_time (NULL);
1130 
1131  if (next_timeout == 0 || next_interval <= 0)
1132  {
1133  if (ctx->c_s_index == QUIC_SESSION_INVALID)
1134  {
1135  next_interval = 1;
1136  }
1137  else
1138  {
1139  quic_session = session_get (ctx->c_s_index, ctx->c_thread_index);
1140  if (svm_fifo_set_event (quic_session->tx_fifo))
1141  {
1142  rv = session_send_io_evt_to_thread_custom (quic_session,
1143  quic_session->thread_index,
1145  if (PREDICT_FALSE (rv))
1146  QUIC_ERR ("Failed to enqueue builtin_tx %d", rv);
1147  }
1148  return;
1149  }
1150  }
1151 
1152  ASSERT (vlib_get_thread_index () == ctx->c_thread_index ||
1153  vlib_get_thread_index () == 0);
1154  tw = &quic_main.wrk_ctx[ctx->c_thread_index].timer_wheel;
1155 
1156  QUIC_DBG (4, "Timer set to %ld (int %ld) for ctx %u", next_timeout,
1157  next_interval, ctx->c_c_index);
1158 
1159  if (ctx->timer_handle == QUIC_TIMER_HANDLE_INVALID)
1160  {
1161  if (next_timeout == INT64_MAX)
1162  {
1163  QUIC_DBG (4, "timer for ctx %u already stopped", ctx->c_c_index);
1164  return;
1165  }
1166  ctx->timer_handle = tw_timer_start_1t_3w_1024sl_ov (tw, ctx->c_c_index,
1167  0, next_interval);
1168  }
1169  else
1170  {
1171  if (next_timeout == INT64_MAX)
1172  {
1174  }
1175  else
1176  tw_timer_update_1t_3w_1024sl_ov (tw, ctx->timer_handle,
1177  next_interval);
1178  }
1179  return;
1180 }
1181 
1182 static void
1184 {
1185  int i;
1186 
1187  for (i = 0; i < vec_len (expired_timers); i++)
1188  {
1189  quic_timer_expired (expired_timers[i]);
1190  }
1191 }
1192 
1193 /* Transport proto functions */
1194 static int
1196 {
1197  uint64_t quic_session_handle;
1198  session_t *stream_session;
1199  quic_stream_data_t *stream_data;
1200  quicly_stream_t *stream;
1201  quicly_conn_t *conn;
1202  app_worker_t *app_wrk;
1203  quic_ctx_t *qctx, *sctx;
1204  u32 sctx_index;
1205  u8 is_unidir;
1206  int rv;
1207 
1208  /* Find base session to which the user want to attach a stream */
1209  quic_session_handle = session_handle (quic_session);
1210  QUIC_DBG (2, "Opening new stream (qsession %u)", quic_session_handle);
1211 
1212  if (session_type_transport_proto (quic_session->session_type) !=
1213  TRANSPORT_PROTO_QUIC)
1214  {
1215  QUIC_ERR ("received incompatible session");
1216  return -1;
1217  }
1218 
1219  app_wrk = app_worker_get_if_valid (quic_session->app_wrk_index);
1220  if (!app_wrk)
1221  {
1222  QUIC_ERR ("Invalid app worker :(");
1223  return -1;
1224  }
1225 
1226  sctx_index = quic_ctx_alloc (quic_session->thread_index); /* Allocate before we get pointers */
1227  sctx = quic_ctx_get (sctx_index, quic_session->thread_index);
1228  qctx = quic_ctx_get (quic_session->connection_index,
1229  quic_session->thread_index);
1230  if (quic_ctx_is_stream (qctx))
1231  {
1232  QUIC_ERR ("session is a stream");
1233  quic_ctx_free (sctx);
1234  return -1;
1235  }
1236 
1237  sctx->parent_app_wrk_id = qctx->parent_app_wrk_id;
1238  sctx->parent_app_id = qctx->parent_app_id;
1239  sctx->quic_connection_ctx_id = qctx->c_c_index;
1240  sctx->c_c_index = sctx_index;
1241  sctx->c_flags |= TRANSPORT_CONNECTION_F_NO_LOOKUP;
1242  sctx->flags |= QUIC_F_IS_STREAM;
1243 
1244  conn = qctx->conn;
1245 
1246  if (!conn || !quicly_connection_is_ready (conn))
1247  return -1;
1248 
1249  is_unidir = sep->transport_flags & TRANSPORT_CFG_F_UNIDIRECTIONAL;
1250  if ((rv = quicly_open_stream (conn, &stream, is_unidir)))
1251  {
1252  QUIC_DBG (2, "Stream open failed with %d", rv);
1253  return -1;
1254  }
1255  quic_increment_counter (QUIC_ERROR_OPENED_STREAM, 1);
1256 
1257  sctx->stream = stream;
1259 
1260  QUIC_DBG (2, "Opened stream %d, creating session", stream->stream_id);
1261 
1262  stream_session = session_alloc (qctx->c_thread_index);
1263  QUIC_DBG (2, "Allocated stream_session 0x%lx ctx %u",
1264  session_handle (stream_session), sctx_index);
1265  stream_session->app_wrk_index = app_wrk->wrk_index;
1266  stream_session->connection_index = sctx_index;
1267  stream_session->listener_handle = quic_session_handle;
1268  stream_session->session_type =
1269  session_type_from_proto_and_ip (TRANSPORT_PROTO_QUIC, qctx->udp_is_ip4);
1270  if (is_unidir)
1271  stream_session->flags |= SESSION_F_UNIDIRECTIONAL;
1272 
1273  sctx->c_s_index = stream_session->session_index;
1274  stream_data = (quic_stream_data_t *) stream->data;
1275  stream_data->ctx_id = sctx->c_c_index;
1276  stream_data->thread_index = sctx->c_thread_index;
1277  stream_data->app_rx_data_len = 0;
1278  stream_data->app_tx_data_len = 0;
1279  stream_session->session_state = SESSION_STATE_READY;
1280 
1281  /* For now we only reset streams. Cleanup will be triggered by timers */
1282  if ((rv = app_worker_init_connected (app_wrk, stream_session)))
1283  {
1284  QUIC_ERR ("failed to app_worker_init_connected");
1285  quicly_reset_stream (stream, QUIC_APP_CONNECT_NOTIFY_ERROR);
1286  return app_worker_connect_notify (app_wrk, NULL, rv, sep->opaque);
1287  }
1288 
1289  svm_fifo_add_want_deq_ntf (stream_session->rx_fifo,
1292 
1293  if (app_worker_connect_notify (app_wrk, stream_session, SESSION_E_NONE,
1294  sep->opaque))
1295  {
1296  QUIC_ERR ("failed to notify app");
1297  quic_increment_counter (QUIC_ERROR_CLOSED_STREAM, 1);
1298  quicly_reset_stream (stream, QUIC_APP_CONNECT_NOTIFY_ERROR);
1299  return -1;
1300  }
1301 
1302  return 0;
1303 }
1304 
1305 static int
1307 {
1308  vnet_connect_args_t _cargs, *cargs = &_cargs;
1310  quic_main_t *qm = &quic_main;
1311  u32 ctx_index, thread_index;
1312  quic_ctx_t *ctx;
1313  app_worker_t *app_wrk;
1314  application_t *app;
1315  int error;
1316 
1317  if (!sep->ext_cfg)
1318  return SESSION_E_NOEXTCFG;
1319 
1320  /* Use pool on thread 1 if we have workers because of UDP */
1322  ccfg = &sep->ext_cfg->crypto;
1323 
1324  clib_memset (cargs, 0, sizeof (*cargs));
1325  ctx_index = quic_ctx_alloc (thread_index);
1326  ctx = quic_ctx_get (ctx_index, thread_index);
1327  ctx->parent_app_wrk_id = sep->app_wrk_index;
1328  ctx->c_s_index = QUIC_SESSION_INVALID;
1329  ctx->c_c_index = ctx_index;
1330  ctx->udp_is_ip4 = sep->is_ip4;
1331  ctx->timer_handle = QUIC_TIMER_HANDLE_INVALID;
1332  ctx->conn_state = QUIC_CONN_STATE_HANDSHAKE;
1333  ctx->client_opaque = sep->opaque;
1335  if (ccfg->hostname[0])
1336  ctx->srv_hostname = format (0, "%s", ccfg->hostname);
1337  else
1338  /* needed by quic for crypto + determining client / server */
1339  ctx->srv_hostname = format (0, "%U", format_ip46_address,
1340  &sep->ip, sep->is_ip4);
1341  vec_terminate_c_string (ctx->srv_hostname);
1342 
1343  clib_memcpy (&cargs->sep_ext, sep, sizeof (session_endpoint_cfg_t));
1344  cargs->sep.transport_proto = TRANSPORT_PROTO_UDP;
1345  cargs->app_index = qm->app_index;
1346  cargs->api_context = ctx_index;
1347 
1348  app_wrk = app_worker_get (sep->app_wrk_index);
1349  app = application_get (app_wrk->app_index);
1350  ctx->parent_app_id = app_wrk->app_index;
1351  cargs->sep_ext.ns_index = app->ns_index;
1352  cargs->sep_ext.transport_flags = TRANSPORT_CFG_F_CONNECTED;
1353 
1354  ctx->crypto_engine = ccfg->crypto_engine;
1355  ctx->ckpair_index = ccfg->ckpair_index;
1357  return error;
1358 
1359  if ((error = vnet_connect (cargs)))
1360  return error;
1361 
1362  return 0;
1363 }
1364 
1365 static int
1367 {
1368  QUIC_DBG (2, "Called quic_connect");
1370  session_t *quic_session;
1371  sep = (session_endpoint_cfg_t *) tep;
1372 
1373  quic_session = session_get_from_handle_if_valid (sep->parent_handle);
1374  if (quic_session)
1375  return quic_connect_stream (quic_session, sep);
1376  else
1377  return quic_connect_connection (sep);
1378 }
1379 
1380 static void
1382 {
1383  int err;
1385  if (!ctx)
1386  return;
1387  session_t *stream_session = session_get (ctx->c_s_index,
1388  ctx->c_thread_index);
1389 #if QUIC_DEBUG >= 2
1390  clib_warning ("Closing session 0x%lx", session_handle (stream_session));
1391 #endif
1392  if (quic_ctx_is_stream (ctx))
1393  {
1394  quicly_stream_t *stream = ctx->stream;
1395  if (!quicly_stream_has_send_side (quicly_is_client (stream->conn),
1396  stream->stream_id))
1397  return;
1398  quicly_sendstate_shutdown (&stream->sendstate, ctx->bytes_written +
1400  (stream_session->tx_fifo));
1401  err = quicly_stream_sync_sendbuf (stream, 1);
1402  if (err)
1403  {
1404  QUIC_DBG (1, "sendstate_shutdown failed for stream session %lu",
1405  session_handle (stream_session));
1406  quicly_reset_stream (stream, QUIC_APP_ERROR_CLOSE_NOTIFY);
1407  }
1409  return;
1410  }
1411 
1412  switch (ctx->conn_state)
1413  {
1416  case QUIC_CONN_STATE_READY:
1417  ctx->conn_state = QUIC_CONN_STATE_ACTIVE_CLOSING;
1418  quicly_conn_t *conn = ctx->conn;
1419  /* Start connection closing. Keep sending packets until quicly_send
1420  returns QUICLY_ERROR_FREE_CONNECTION */
1421 
1422  quic_increment_counter (QUIC_ERROR_CLOSED_CONNECTION, 1);
1423  quicly_close (conn, QUIC_APP_ERROR_CLOSE_NOTIFY, "Closed by peer");
1424  /* This also causes all streams to be closed (and the cb called) */
1426  break;
1429  /* send_packets will eventually return an error, we delete the conn at
1430  that point */
1431  break;
1434  break;
1436  break;
1437  default:
1438  QUIC_ERR ("Trying to close conn in state %d", ctx->conn_state);
1439  break;
1440  }
1441 }
1442 
1443 static u32
1444 quic_start_listen (u32 quic_listen_session_index, transport_endpoint_t * tep)
1445 {
1446  vnet_listen_args_t _bargs, *args = &_bargs;
1448  quic_main_t *qm = &quic_main;
1449  session_handle_t udp_handle;
1451  session_t *udp_listen_session;
1452  app_worker_t *app_wrk;
1453  application_t *app;
1454  quic_ctx_t *lctx;
1455  u32 lctx_index;
1456  app_listener_t *app_listener;
1457  int rv;
1458 
1459  sep = (session_endpoint_cfg_t *) tep;
1460  if (!sep->ext_cfg)
1461  return SESSION_E_NOEXTCFG;
1462 
1463  ccfg = &sep->ext_cfg->crypto;
1464  app_wrk = app_worker_get (sep->app_wrk_index);
1465  app = application_get (app_wrk->app_index);
1466  QUIC_DBG (2, "Called quic_start_listen for app %d", app_wrk->app_index);
1467 
1468  clib_memset (args, 0, sizeof (*args));
1469  args->app_index = qm->app_index;
1470  args->sep_ext = *sep;
1471  args->sep_ext.ns_index = app->ns_index;
1472  args->sep_ext.transport_proto = TRANSPORT_PROTO_UDP;
1473  args->sep_ext.transport_flags = TRANSPORT_CFG_F_CONNECTED;
1474  if ((rv = vnet_listen (args)))
1475  return rv;
1476 
1477  lctx_index = quic_ctx_alloc (0);
1478  udp_handle = args->handle;
1479  app_listener = app_listener_get_w_handle (udp_handle);
1480  udp_listen_session = app_listener_get_session (app_listener);
1481  udp_listen_session->opaque = lctx_index;
1482 
1483  lctx = quic_ctx_get (lctx_index, 0);
1484  lctx->flags |= QUIC_F_IS_LISTENER;
1485 
1486  clib_memcpy (&lctx->c_rmt_ip, &args->sep.peer.ip, sizeof (ip46_address_t));
1487  clib_memcpy (&lctx->c_lcl_ip, &args->sep.ip, sizeof (ip46_address_t));
1488  lctx->c_rmt_port = args->sep.peer.port;
1489  lctx->c_lcl_port = args->sep.port;
1490  lctx->c_is_ip4 = args->sep.is_ip4;
1491  lctx->c_fib_index = args->sep.fib_index;
1492  lctx->c_proto = TRANSPORT_PROTO_QUIC;
1493  lctx->parent_app_wrk_id = sep->app_wrk_index;
1494  lctx->parent_app_id = app_wrk->app_index;
1495  lctx->udp_session_handle = udp_handle;
1496  lctx->c_s_index = quic_listen_session_index;
1497  lctx->crypto_engine = ccfg->crypto_engine;
1498  lctx->ckpair_index = ccfg->ckpair_index;
1499  if ((rv = quic_acquire_crypto_context (lctx)))
1500  return rv;
1501 
1502  QUIC_DBG (2, "Listening UDP session 0x%lx",
1503  session_handle (udp_listen_session));
1504  QUIC_DBG (2, "Listening QUIC session 0x%lx", quic_listen_session_index);
1505  return lctx_index;
1506 }
1507 
1508 static u32
1509 quic_stop_listen (u32 lctx_index)
1510 {
1511  QUIC_DBG (2, "Called quic_stop_listen");
1512  quic_ctx_t *lctx;
1513  lctx = quic_ctx_get (lctx_index, 0);
1516  .handle = lctx->udp_session_handle,
1517  .app_index = quic_main.app_index,
1518  .wrk_map_index = 0 /* default wrk */
1519  };
1520  if (vnet_unlisten (&a))
1521  clib_warning ("unlisten errored");
1522 
1524  0 /* thread_index */ );
1525  quic_ctx_free (lctx);
1526  return 0;
1527 }
1528 
1529 static transport_connection_t *
1531 {
1532  quic_ctx_t *ctx;
1533  ctx = quic_ctx_get (ctx_index, thread_index);
1534  return &ctx->connection;
1535 }
1536 
1537 static transport_connection_t *
1538 quic_listener_get (u32 listener_index)
1539 {
1540  QUIC_DBG (2, "Called quic_listener_get");
1541  quic_ctx_t *ctx;
1542  ctx = quic_ctx_get (listener_index, 0);
1543  return &ctx->connection;
1544 }
1545 
1546 static u8 *
1547 format_quic_ctx (u8 * s, va_list * args)
1548 {
1549  quic_ctx_t *ctx = va_arg (*args, quic_ctx_t *);
1550  u32 verbose = va_arg (*args, u32);
1551  u8 *str = 0;
1552 
1553  if (!ctx)
1554  return s;
1555  str = format (str, "[#%d][Q] ", ctx->c_thread_index);
1556 
1557  if (quic_ctx_is_listener (ctx))
1558  str = format (str, "Listener, UDP %ld", ctx->udp_session_handle);
1559  else if (quic_ctx_is_stream (ctx))
1560  str = format (str, "Stream %ld conn %d",
1561  ctx->stream->stream_id, ctx->quic_connection_ctx_id);
1562  else /* connection */
1563  str = format (str, "Conn %d UDP %d", ctx->c_c_index,
1564  ctx->udp_session_handle);
1565 
1566  str = format (str, " app %d wrk %d", ctx->parent_app_id,
1567  ctx->parent_app_wrk_id);
1568 
1569  if (verbose == 1)
1570  s = format (s, "%-" SESSION_CLI_ID_LEN "s%-" SESSION_CLI_STATE_LEN "d",
1571  str, ctx->conn_state);
1572  else
1573  s = format (s, "%s\n", str);
1574  vec_free (str);
1575  return s;
1576 }
1577 
1578 static u8 *
1579 format_quic_connection (u8 * s, va_list * args)
1580 {
1581  u32 qc_index = va_arg (*args, u32);
1582  u32 thread_index = va_arg (*args, u32);
1583  u32 verbose = va_arg (*args, u32);
1584  quic_ctx_t *ctx = quic_ctx_get (qc_index, thread_index);
1585  s = format (s, "%U", format_quic_ctx, ctx, verbose);
1586  return s;
1587 }
1588 
1589 static u8 *
1590 format_quic_half_open (u8 * s, va_list * args)
1591 {
1592  u32 qc_index = va_arg (*args, u32);
1593  u32 thread_index = va_arg (*args, u32);
1594  quic_ctx_t *ctx = quic_ctx_get (qc_index, thread_index);
1595  s = format (s, "[#%d][Q] half-open app %u", thread_index,
1596  ctx->parent_app_id);
1597  return s;
1598 }
1599 
1600 /* TODO improve */
1601 static u8 *
1602 format_quic_listener (u8 * s, va_list * args)
1603 {
1604  u32 tci = va_arg (*args, u32);
1605  u32 thread_index = va_arg (*args, u32);
1606  u32 verbose = va_arg (*args, u32);
1608  s = format (s, "%U", format_quic_ctx, ctx, verbose);
1609  return s;
1610 }
1611 
1612 /* Session layer callbacks */
1613 
1614 static inline void
1615 quic_build_sockaddr (struct sockaddr *sa, socklen_t * salen,
1616  ip46_address_t * addr, u16 port, u8 is_ip4)
1617 {
1618  if (is_ip4)
1619  {
1620  struct sockaddr_in *sa4 = (struct sockaddr_in *) sa;
1621  sa4->sin_family = AF_INET;
1622  sa4->sin_port = port;
1623  sa4->sin_addr.s_addr = addr->ip4.as_u32;
1624  *salen = sizeof (struct sockaddr_in);
1625  }
1626  else
1627  {
1628  struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) sa;
1629  sa6->sin6_family = AF_INET6;
1630  sa6->sin6_port = port;
1631  clib_memcpy (&sa6->sin6_addr, &addr->ip6, 16);
1632  *salen = sizeof (struct sockaddr_in6);
1633  }
1634 }
1635 
1636 static void
1638 {
1639  session_t *quic_session;
1640  app_worker_t *app_wrk;
1641  u32 ctx_id = ctx->c_c_index;
1642  u32 thread_index = ctx->c_thread_index;
1643  int rv;
1644 
1645  quic_session = session_alloc (thread_index);
1646 
1647  QUIC_DBG (2, "Allocated quic session 0x%lx", session_handle (quic_session));
1648  ctx->c_s_index = quic_session->session_index;
1649  quic_session->app_wrk_index = ctx->parent_app_wrk_id;
1650  quic_session->connection_index = ctx->c_c_index;
1651  quic_session->listener_handle = SESSION_INVALID_HANDLE;
1652  quic_session->session_type =
1653  session_type_from_proto_and_ip (TRANSPORT_PROTO_QUIC, ctx->udp_is_ip4);
1654 
1655  /* If quic session connected fails, immediatly close connection */
1656  app_wrk = app_worker_get (ctx->parent_app_wrk_id);
1657  if ((rv = app_worker_init_connected (app_wrk, quic_session)))
1658  {
1659  QUIC_ERR ("failed to app_worker_init_connected");
1661  app_worker_connect_notify (app_wrk, NULL, rv, ctx->client_opaque);
1662  return;
1663  }
1664 
1665  quic_session->session_state = SESSION_STATE_CONNECTING;
1666  if ((rv = app_worker_connect_notify (app_wrk, quic_session,
1667  SESSION_E_NONE, ctx->client_opaque)))
1668  {
1669  QUIC_ERR ("failed to notify app %d", rv);
1671  return;
1672  }
1673 
1674  /* If the app opens a stream in its callback it may invalidate ctx */
1675  ctx = quic_ctx_get (ctx_id, thread_index);
1676  /*
1677  * app_worker_connect_notify() might have reallocated pool, reload
1678  * quic_session pointer
1679  */
1680  quic_session = session_get (ctx->c_s_index, thread_index);
1681  quic_session->session_state = SESSION_STATE_LISTENING;
1682 }
1683 
1684 static void
1686 {
1687  /* Called when we need to trigger quic session connected
1688  * we may call this function on the server side / at
1689  * stream opening */
1690 
1691  /* Conn may be set to null if the connection is terminated */
1692  if (!ctx->conn || ctx->conn_state != QUIC_CONN_STATE_HANDSHAKE)
1693  return;
1694  if (!quicly_connection_is_ready (ctx->conn))
1695  return;
1696  ctx->conn_state = QUIC_CONN_STATE_READY;
1697  if (!quicly_is_client (ctx->conn))
1698  return;
1700 }
1701 
1702 static inline void
1703 quic_update_conn_ctx (quicly_conn_t * conn, quicly_context_t * quicly_context)
1704 {
1705  /* we need to update the quicly_conn on migrate
1706  * as it contains a pointer to the crypto context */
1707  ptls_context_t **tls;
1708  quicly_context_t **_quicly_context;
1709  _quicly_context = (quicly_context_t **) conn;
1710  *_quicly_context = quicly_context;
1711  tls = (ptls_context_t **) quicly_get_tls (conn);
1712  *tls = quicly_context->tls;
1713 }
1714 
1715 static void
1717 {
1718  u32 new_ctx_id, thread_index = vlib_get_thread_index ();
1719  quic_ctx_t *temp_ctx, *new_ctx;
1721  quicly_conn_t *conn;
1722  quicly_context_t *quicly_context;
1723  session_t *udp_session;
1724 
1725  temp_ctx = arg;
1726  new_ctx_id = quic_ctx_alloc (thread_index);
1727  new_ctx = quic_ctx_get (new_ctx_id, thread_index);
1728 
1729  QUIC_DBG (2, "Received conn %u (now %u)", temp_ctx->c_thread_index,
1730  new_ctx_id);
1731 
1732  clib_memcpy (new_ctx, temp_ctx, sizeof (quic_ctx_t));
1733  clib_mem_free (temp_ctx);
1734 
1735  new_ctx->c_thread_index = thread_index;
1736  new_ctx->c_c_index = new_ctx_id;
1737  quic_acquire_crypto_context (new_ctx);
1738 
1739  conn = new_ctx->conn;
1740  quicly_context = quic_get_quicly_ctx_from_ctx (new_ctx);
1741  quic_update_conn_ctx (conn, quicly_context);
1742 
1743  quic_store_conn_ctx (conn, new_ctx);
1744  quic_make_connection_key (&kv, quicly_get_master_id (conn));
1745  kv.value = ((u64) thread_index) << 32 | (u64) new_ctx_id;
1746  QUIC_DBG (2, "Registering conn with id %lu %lu", kv.key[0], kv.key[1]);
1747  clib_bihash_add_del_16_8 (&quic_main.connection_hash, &kv, 1 /* is_add */ );
1749  quic_update_timer (new_ctx);
1750 
1751  /* Trigger write on this connection if necessary */
1752  udp_session = session_get_from_handle (new_ctx->udp_session_handle);
1753  udp_session->opaque = new_ctx_id;
1754  udp_session->flags &= ~SESSION_F_IS_MIGRATING;
1755  if (svm_fifo_max_dequeue (udp_session->tx_fifo))
1756  quic_set_udp_tx_evt (udp_session);
1757 }
1758 
1759 static void
1760 quic_transfer_connection (u32 ctx_index, u32 dest_thread)
1761 {
1762  quic_ctx_t *ctx, *temp_ctx;
1764 
1765  QUIC_DBG (2, "Transferring conn %u to thread %u", ctx_index, dest_thread);
1766 
1767  temp_ctx = clib_mem_alloc (sizeof (quic_ctx_t));
1768  QUIC_ASSERT (temp_ctx != NULL);
1769  ctx = quic_ctx_get (ctx_index, thread_index);
1770 
1771  clib_memcpy (temp_ctx, ctx, sizeof (quic_ctx_t));
1772 
1774  quic_release_crypto_context (ctx->crypto_context_index, thread_index);
1775  quic_ctx_free (ctx);
1776 
1777  /* Send connection to destination thread */
1779  (void *) temp_ctx);
1780 }
1781 
1782 static int
1783 quic_udp_session_connected_callback (u32 quic_app_index, u32 ctx_index,
1784  session_t * udp_session,
1785  session_error_t err)
1786 {
1787  QUIC_DBG (2, "UDP Session is now connected (id %u)",
1788  udp_session->session_index);
1789  /* This should always be called before quic_connect returns since UDP always
1790  * connects instantly. */
1792  struct sockaddr_in6 sa6;
1793  struct sockaddr *sa = (struct sockaddr *) &sa6;
1794  socklen_t salen;
1796  app_worker_t *app_wrk;
1797  quicly_conn_t *conn;
1798  quic_ctx_t *ctx;
1799  u32 thread_index;
1800  int ret;
1801  quicly_context_t *quicly_ctx;
1802 
1803  /* Allocate session on whatever thread udp used, i.e., probably first
1804  * worker, although this may be main thread. If it is main, it's done
1805  * with a worker barrier */
1806  thread_index = udp_session->thread_index;
1807  ASSERT (thread_index == 0 || thread_index == 1);
1808  ctx = quic_ctx_get (ctx_index, thread_index);
1809  if (err)
1810  {
1811  u32 api_context;
1812  app_wrk = app_worker_get_if_valid (ctx->parent_app_wrk_id);
1813  if (app_wrk)
1814  {
1815  api_context = ctx->c_s_index;
1816  app_worker_connect_notify (app_wrk, 0, SESSION_E_NONE, api_context);
1817  }
1818  return 0;
1819  }
1820 
1821  QUIC_DBG (2, "New ctx [%u]%x", thread_index, (ctx) ? ctx_index : ~0);
1822 
1823  ctx->udp_session_handle = session_handle (udp_session);
1824  udp_session->opaque = ctx_index;
1825 
1826  /* Init QUIC lib connection
1827  * Generate required sockaddr & salen */
1828  tc = session_get_transport (udp_session);
1829  quic_build_sockaddr (sa, &salen, &tc->rmt_ip, tc->rmt_port, tc->is_ip4);
1830 
1831  quicly_ctx = quic_get_quicly_ctx_from_ctx (ctx);
1832  ret = quicly_connect (&ctx->conn, quicly_ctx, (char *) ctx->srv_hostname,
1833  sa, NULL, &quic_main.wrk_ctx[thread_index].next_cid,
1834  ptls_iovec_init (NULL, 0), &quic_main.hs_properties,
1835  NULL);
1836  ++quic_main.wrk_ctx[thread_index].next_cid.master_id;
1837  /* Save context handle in quicly connection */
1838  quic_store_conn_ctx (ctx->conn, ctx);
1839  assert (ret == 0);
1840 
1841  /* Register connection in connections map */
1842  conn = ctx->conn;
1843  quic_make_connection_key (&kv, quicly_get_master_id (conn));
1844  kv.value = ((u64) thread_index) << 32 | (u64) ctx_index;
1845  QUIC_DBG (2, "Registering conn with id %lu %lu", kv.key[0], kv.key[1]);
1846  clib_bihash_add_del_16_8 (&quic_main.connection_hash, &kv, 1 /* is_add */ );
1847 
1849 
1850  return ret;
1851 }
1852 
1853 static void
1855 {
1856  clib_warning ("UDP session disconnected???");
1857 }
1858 
1859 static void
1862 {
1863  quic_ctx_t *ctx;
1864 
1865  if (ntf != SESSION_CLEANUP_SESSION)
1866  return;
1867 
1868  ctx = quic_ctx_get (udp_session->opaque, udp_session->thread_index);
1870  quic_release_crypto_context (ctx->crypto_context_index,
1871  ctx->c_thread_index);
1872  quic_ctx_free (ctx);
1873 }
1874 
1875 static void
1877 {
1878  clib_warning ("UDP session reset???");
1879 }
1880 
1881 static void
1883 {
1884  u32 new_thread = session_thread_from_handle (new_sh);
1885  quic_ctx_t *ctx;
1886 
1887  QUIC_DBG (2, "Session %x migrated to %lx", s->session_index, new_sh);
1889  ctx = quic_ctx_get (s->opaque, s->thread_index);
1890  QUIC_ASSERT (ctx->udp_session_handle == session_handle (s));
1891 
1892  ctx->udp_session_handle = new_sh;
1893 #if QUIC_DEBUG >= 1
1894  s->opaque = 0xfeedface;
1895 #endif
1896  quic_transfer_connection (ctx->c_c_index, new_thread);
1897 }
1898 
1899 int
1901 {
1902  /* New UDP connection, try to accept it */
1903  u32 ctx_index;
1904  quic_ctx_t *ctx, *lctx;
1905  session_t *udp_listen_session;
1907 
1908  udp_listen_session =
1910 
1911  ctx_index = quic_ctx_alloc (thread_index);
1912  ctx = quic_ctx_get (ctx_index, thread_index);
1913  ctx->c_thread_index = udp_session->thread_index;
1914  ctx->c_c_index = ctx_index;
1915  ctx->c_s_index = QUIC_SESSION_INVALID;
1916  ctx->udp_session_handle = session_handle (udp_session);
1917  QUIC_DBG (2, "ACCEPTED UDP 0x%lx", ctx->udp_session_handle);
1918  ctx->listener_ctx_id = udp_listen_session->opaque;
1919  lctx = quic_ctx_get (udp_listen_session->opaque,
1920  udp_listen_session->thread_index);
1921  ctx->udp_is_ip4 = lctx->c_is_ip4;
1922  ctx->parent_app_id = lctx->parent_app_id;
1923  ctx->parent_app_wrk_id = lctx->parent_app_wrk_id;
1924  ctx->timer_handle = QUIC_TIMER_HANDLE_INVALID;
1925  ctx->conn_state = QUIC_CONN_STATE_OPENED;
1927 
1928  ctx->crypto_engine = lctx->crypto_engine;
1929  ctx->ckpair_index = lctx->ckpair_index;
1931  udp_session->opaque = ctx_index;
1932  udp_session->session_state = SESSION_STATE_READY;
1933 
1934  /* TODO timeout to delete these if they never connect */
1935  return 0;
1936 }
1937 
1938 static int
1939 quic_add_segment_callback (u32 client_index, u64 seg_handle)
1940 {
1941  /* No-op for builtin */
1942  return 0;
1943 }
1944 
1945 static int
1946 quic_del_segment_callback (u32 client_index, u64 seg_handle)
1947 {
1948  /* No-op for builtin */
1949  return 0;
1950 }
1951 
1952 static int
1954 {
1955  quic_ctx_t *ctx;
1956  session_t *stream_session = session_get (tc->s_index, tc->thread_index);
1957  QUIC_DBG (3, "Received app READ notification");
1958  quic_ack_rx_data (stream_session);
1959  svm_fifo_reset_has_deq_ntf (stream_session->rx_fifo);
1960 
1961  /* Need to send packets (acks may never be sent otherwise) */
1962  ctx = quic_ctx_get (stream_session->connection_index,
1963  stream_session->thread_index);
1965  return 0;
1966 }
1967 
1968 static int
1970 {
1971  session_t *stream_session = (session_t *) s;
1972  quic_stream_data_t *stream_data;
1973  quicly_stream_t *stream;
1974  quic_ctx_t *ctx;
1975  u32 max_deq;
1976  int rv;
1977 
1978  if (PREDICT_FALSE
1979  (stream_session->session_state >= SESSION_STATE_TRANSPORT_CLOSING))
1980  return 0;
1981  ctx = quic_ctx_get (stream_session->connection_index,
1982  stream_session->thread_index);
1984  {
1985  goto tx_end; /* Most probably a reschedule */
1986  }
1987 
1988  QUIC_DBG (3, "Stream TX event");
1989  quic_ack_rx_data (stream_session);
1990  stream = ctx->stream;
1991  if (!quicly_sendstate_is_open (&stream->sendstate))
1992  {
1993  QUIC_ERR ("Warning: tried to send on closed stream");
1994  return 0;
1995  }
1996 
1997  stream_data = (quic_stream_data_t *) stream->data;
1998  max_deq = svm_fifo_max_dequeue (stream_session->tx_fifo);
1999  QUIC_ASSERT (max_deq >= stream_data->app_tx_data_len);
2000  if (max_deq == stream_data->app_tx_data_len)
2001  {
2002  QUIC_DBG (3, "TX but no data %d / %d", max_deq,
2003  stream_data->app_tx_data_len);
2004  return 0;
2005  }
2006  stream_data->app_tx_data_len = max_deq;
2007  rv = quicly_stream_sync_sendbuf (stream, 1);
2008  QUIC_ASSERT (!rv);
2009 
2010 tx_end:
2011  return quic_send_packets (ctx);
2012 }
2013 
2014 /*
2015  * Returns 0 if a matching connection is found and is on the right thread.
2016  * Otherwise returns -1.
2017  * If a connection is found, even on the wrong thread, ctx_thread and ctx_index
2018  * will be set.
2019  */
2020 static inline int
2021 quic_find_packet_ctx (quic_rx_packet_ctx_t * pctx, u32 caller_thread_index)
2022 {
2024  clib_bihash_16_8_t *h;
2025  quic_ctx_t *ctx;
2026  u32 index, thread_id;
2027 
2029  quic_make_connection_key (&kv, &pctx->packet.cid.dest.plaintext);
2030  QUIC_DBG (3, "Searching conn with id %lu %lu", kv.key[0], kv.key[1]);
2031 
2032  if (clib_bihash_search_16_8 (h, &kv, &kv))
2033  {
2034  QUIC_DBG (3, "connection not found");
2035  return QUIC_PACKET_TYPE_NONE;
2036  }
2037 
2038  index = kv.value & UINT32_MAX;
2039  thread_id = kv.value >> 32;
2040  /* Check if this connection belongs to this thread, otherwise
2041  * ask for it to be moved */
2042  if (thread_id != caller_thread_index)
2043  {
2044  QUIC_DBG (2, "Connection is on wrong thread");
2045  /* Cannot make full check with quicly_is_destination... */
2046  pctx->ctx_index = index;
2047  pctx->thread_index = thread_id;
2048  return QUIC_PACKET_TYPE_MIGRATE;
2049  }
2051  if (!ctx->conn)
2052  {
2053  QUIC_ERR ("ctx has no conn");
2054  return QUIC_PACKET_TYPE_NONE;
2055  }
2056  if (!quicly_is_destination (ctx->conn, NULL, &pctx->sa, &pctx->packet))
2057  return QUIC_PACKET_TYPE_NONE;
2058 
2059  QUIC_DBG (3, "Connection found");
2060  pctx->ctx_index = index;
2061  pctx->thread_index = thread_id;
2062  return QUIC_PACKET_TYPE_RECEIVE;
2063 }
2064 
2065 static void
2067 {
2068  quicly_context_t *quicly_ctx;
2069  session_t *quic_session;
2071  app_worker_t *app_wrk;
2072  quicly_conn_t *conn;
2073  quic_ctx_t *ctx;
2074  quic_ctx_t *lctx;
2075  int rv;
2076 
2077  /* new connection, accept and create context if packet is valid
2078  * TODO: check if socket is actually listening? */
2079  ctx = quic_ctx_get (pctx->ctx_index, pctx->thread_index);
2080  if (ctx->c_s_index != QUIC_SESSION_INVALID)
2081  {
2082  QUIC_DBG (2, "already accepted ctx 0x%x", ctx->c_s_index);
2083  return;
2084  }
2085 
2086  quicly_ctx = quic_get_quicly_ctx_from_ctx (ctx);
2087  if ((rv = quicly_accept (&conn, quicly_ctx, NULL, &pctx->sa,
2088  &pctx->packet, NULL,
2090  NULL)))
2091  {
2092  /* Invalid packet, pass */
2093  assert (conn == NULL);
2094  QUIC_ERR ("Accept failed with %U", quic_format_err, rv);
2095  /* TODO: cleanup created quic ctx and UDP session */
2096  return;
2097  }
2098  assert (conn != NULL);
2099 
2100  ++quic_main.wrk_ctx[pctx->thread_index].next_cid.master_id;
2101  /* Save ctx handle in quicly connection */
2102  quic_store_conn_ctx (conn, ctx);
2103  ctx->conn = conn;
2104 
2105  quic_session = session_alloc (ctx->c_thread_index);
2106  QUIC_DBG (2, "Allocated quic_session, 0x%lx ctx %u",
2107  session_handle (quic_session), ctx->c_c_index);
2108  quic_session->session_state = SESSION_STATE_LISTENING;
2109  ctx->c_s_index = quic_session->session_index;
2110 
2111  lctx = quic_ctx_get (ctx->listener_ctx_id, 0);
2112 
2113  quic_session->app_wrk_index = lctx->parent_app_wrk_id;
2114  quic_session->connection_index = ctx->c_c_index;
2115  quic_session->session_type =
2116  session_type_from_proto_and_ip (TRANSPORT_PROTO_QUIC, ctx->udp_is_ip4);
2117  quic_session->listener_handle = lctx->c_s_index;
2118 
2119  /* Register connection in connections map */
2120  quic_make_connection_key (&kv, quicly_get_master_id (conn));
2121  kv.value = ((u64) pctx->thread_index) << 32 | (u64) pctx->ctx_index;
2122  clib_bihash_add_del_16_8 (&quic_main.connection_hash, &kv, 1 /* is_add */ );
2123  QUIC_DBG (2, "Registering conn with id %lu %lu", kv.key[0], kv.key[1]);
2124 
2125  /* If notify fails, reset connection immediatly */
2126  if ((rv = app_worker_init_accepted (quic_session)))
2127  {
2128  QUIC_ERR ("failed to allocate fifos");
2130  return;
2131  }
2132 
2133  app_wrk = app_worker_get (quic_session->app_wrk_index);
2134  if ((rv = app_worker_accept_notify (app_wrk, quic_session)))
2135  {
2136  QUIC_ERR ("failed to notify accept worker app");
2138  return;
2139  }
2140 
2141  ctx->conn_state = QUIC_CONN_STATE_READY;
2142 }
2143 
2144 static int
2145 quic_reset_connection (u64 udp_session_handle, quic_rx_packet_ctx_t * pctx)
2146 {
2147  /* short header packet; potentially a dead connection. No need to check the
2148  * length of the incoming packet, because loop is prevented by authenticating
2149  * the CID (by checking node_id and thread_id). If the peer is also sending a
2150  * reset, then the next CID is highly likely to contain a non-authenticating
2151  * CID, ... */
2152  QUIC_DBG (2, "Sending stateless reset");
2153  int rv;
2154  session_t *udp_session;
2155  quicly_context_t *quicly_ctx;
2156  if (pctx->packet.cid.dest.plaintext.node_id != 0
2157  || pctx->packet.cid.dest.plaintext.thread_id != 0)
2158  return 0;
2159  quicly_ctx = quic_get_quicly_ctx_from_udp (udp_session_handle);
2160  quic_ctx_t *qctx = quic_ctx_get (pctx->ctx_index, pctx->thread_index);
2161 
2162  quicly_address_t src;
2163  uint8_t payload[quicly_ctx->transport_params.max_udp_payload_size];
2164  size_t payload_len =
2165  quicly_send_stateless_reset (quicly_ctx, &src.sa, payload);
2166  if (payload_len == 0)
2167  return 1;
2168 
2169  struct iovec packet;
2170  packet.iov_len = payload_len;
2171  packet.iov_base = payload;
2172 
2173  struct _st_quicly_conn_public_t *conn =
2174  (struct _st_quicly_conn_public_t *) qctx->conn;
2175 
2176  udp_session = session_get_from_handle (udp_session_handle);
2177  rv = quic_send_datagram (udp_session, &packet, &conn->remote.address,
2178  &conn->local.address);
2179  quic_set_udp_tx_evt (udp_session);
2180  return rv;
2181 }
2182 
2183 static int
2185  u32 fifo_offset, quic_rx_packet_ctx_t * pctx)
2186 {
2187  size_t plen;
2188  u32 full_len, ret;
2190  u32 cur_deq = svm_fifo_max_dequeue (f) - fifo_offset;
2191  quicly_context_t *quicly_ctx;
2192  session_t *udp_session;
2193  int rv;
2194 
2195  ret = svm_fifo_peek (f, fifo_offset,
2196  SESSION_CONN_HDR_LEN, (u8 *) & pctx->ph);
2198  QUIC_ASSERT (pctx->ph.data_offset == 0);
2199  full_len = pctx->ph.data_length + SESSION_CONN_HDR_LEN;
2200  if (full_len > cur_deq)
2201  {
2202  QUIC_ERR ("Not enough data in fifo RX");
2203  return 1;
2204  }
2205 
2206  /* Quicly can read len bytes from the fifo at offset:
2207  * ph.data_offset + SESSION_CONN_HDR_LEN */
2208  ret = svm_fifo_peek (f, SESSION_CONN_HDR_LEN + fifo_offset,
2209  pctx->ph.data_length, pctx->data);
2210  if (ret != pctx->ph.data_length)
2211  {
2212  QUIC_ERR ("Not enough data peeked in RX");
2213  return 1;
2214  }
2215 
2216  quic_increment_counter (QUIC_ERROR_RX_PACKETS, 1);
2217  quic_build_sockaddr (&pctx->sa, &pctx->salen, &pctx->ph.rmt_ip,
2218  pctx->ph.rmt_port, pctx->ph.is_ip4);
2219  quicly_ctx = quic_get_quicly_ctx_from_udp (udp_session_handle);
2220 
2221  size_t off = 0;
2222  plen = quicly_decode_packet (quicly_ctx, &pctx->packet, pctx->data,
2223  pctx->ph.data_length, &off);
2224 
2225  if (plen == SIZE_MAX)
2226  {
2227  return 1;
2228  }
2229 
2232  {
2234 
2237  {
2238  quic_ctx_t *qctx = quic_ctx_get (pctx->ctx_index, thread_index);
2239  quic_crypto_decrypt_packet (qctx, pctx);
2240  }
2241  return 0;
2242  }
2243  else if (rv == QUIC_PACKET_TYPE_MIGRATE)
2244  {
2246  /* Connection found but on wrong thread, ask move */
2247  }
2248  else if (QUICLY_PACKET_IS_LONG_HEADER (pctx->packet.octets.base[0]))
2249  {
2251  udp_session = session_get_from_handle (udp_session_handle);
2252  pctx->ctx_index = udp_session->opaque;
2253  pctx->thread_index = thread_index;
2254  }
2255  else
2256  {
2257  pctx->ptype = QUIC_PACKET_TYPE_RESET;
2258  }
2259  return 1;
2260 }
2261 
2262 static int
2264 {
2265  /* Read data from UDP rx_fifo and pass it to the quicly conn. */
2266  quic_ctx_t *ctx = NULL, *prev_ctx = NULL;
2267  svm_fifo_t *f = udp_session->rx_fifo;
2268  u32 max_deq;
2269  u64 udp_session_handle = session_handle (udp_session);
2270  int rv = 0;
2272  u32 cur_deq, fifo_offset, max_packets, i;
2273 
2275 
2276  if (udp_session->flags & SESSION_F_IS_MIGRATING)
2277  {
2278  QUIC_DBG (3, "RX on migrating udp session");
2279  return 0;
2280  }
2281 
2282 rx_start:
2283  max_deq = svm_fifo_max_dequeue (f);
2284  if (max_deq == 0)
2285  return 0;
2286 
2287  fifo_offset = 0;
2288  max_packets = QUIC_RCV_MAX_PACKETS;
2289 
2290 #if CLIB_DEBUG > 0
2291  clib_memset (packets_ctx, 0xfa,
2293 #endif
2294  for (i = 0; i < max_packets; i++)
2295  {
2296  packets_ctx[i].thread_index = UINT32_MAX;
2297  packets_ctx[i].ctx_index = UINT32_MAX;
2298  packets_ctx[i].ptype = QUIC_PACKET_TYPE_DROP;
2299 
2300  cur_deq = max_deq - fifo_offset;
2301  if (cur_deq == 0)
2302  {
2303  max_packets = i + 1;
2304  break;
2305  }
2306  if (cur_deq < SESSION_CONN_HDR_LEN)
2307  {
2308  fifo_offset = max_deq;
2309  max_packets = i + 1;
2310  QUIC_ERR ("Fifo %d < header size in RX", cur_deq);
2311  break;
2312  }
2313  rv = quic_process_one_rx_packet (udp_session_handle, f,
2314  fifo_offset, &packets_ctx[i]);
2315  if (packets_ctx[i].ptype != QUIC_PACKET_TYPE_MIGRATE)
2316  fifo_offset += SESSION_CONN_HDR_LEN + packets_ctx[i].ph.data_length;
2317  if (rv)
2318  {
2319  max_packets = i + 1;
2320  break;
2321  }
2322  }
2323 
2324  for (i = 0; i < max_packets; i++)
2325  {
2326  switch (packets_ctx[i].ptype)
2327  {
2329  ctx = quic_ctx_get (packets_ctx[i].ctx_index, thread_index);
2330  rv = quicly_receive (ctx->conn, NULL, &packets_ctx[i].sa,
2331  &packets_ctx[i].packet);
2332  if (rv && rv != QUICLY_ERROR_PACKET_IGNORED)
2333  {
2334  QUIC_ERR ("quicly_receive return error %U",
2335  quic_format_err, rv);
2336  }
2337  break;
2339  quic_accept_connection (&packets_ctx[i]);
2340  break;
2342  quic_reset_connection (udp_session_handle, &packets_ctx[i]);
2343  break;
2344  }
2345  }
2346  ctx = prev_ctx = NULL;
2347  for (i = 0; i < max_packets; i++)
2348  {
2349  prev_ctx = ctx;
2350  switch (packets_ctx[i].ptype)
2351  {
2353  ctx = quic_ctx_get (packets_ctx[i].ctx_index,
2354  packets_ctx[i].thread_index);
2356  ctx = quic_ctx_get (packets_ctx[i].ctx_index,
2357  packets_ctx[i].thread_index);
2358  break;
2360  ctx = quic_ctx_get (packets_ctx[i].ctx_index,
2361  packets_ctx[i].thread_index);
2362  break;
2363  default:
2364  continue; /* this exits the for loop since other packet types are
2365  necessarily the last in the batch */
2366  }
2367  if (ctx != prev_ctx)
2369  }
2370 
2371  udp_session = session_get_from_handle (udp_session_handle); /* session alloc might have happened */
2372  f = udp_session->rx_fifo;
2373  svm_fifo_dequeue_drop (f, fifo_offset);
2374 
2375  if (svm_fifo_max_dequeue (f))
2376  goto rx_start;
2377 
2378  return 0;
2379 }
2380 
2381 always_inline void
2383  transport_endpoint_t * tep, u8 is_lcl)
2384 {
2385  session_t *udp_session;
2386  if (!quic_ctx_is_stream (ctx))
2387  {
2388  udp_session = session_get_from_handle (ctx->udp_session_handle);
2389  session_get_endpoint (udp_session, tep, is_lcl);
2390  }
2391 }
2392 
2393 static void
2395  transport_endpoint_t * tep, u8 is_lcl)
2396 {
2397  quic_ctx_t *ctx;
2398  app_listener_t *app_listener;
2399  session_t *udp_listen_session;
2400  ctx = quic_ctx_get (listener_index, vlib_get_thread_index ());
2401  if (quic_ctx_is_listener (ctx))
2402  {
2403  app_listener = app_listener_get_w_handle (ctx->udp_session_handle);
2404  udp_listen_session = app_listener_get_session (app_listener);
2405  return session_get_endpoint (udp_listen_session, tep, is_lcl);
2406  }
2407  quic_common_get_transport_endpoint (ctx, tep, is_lcl);
2408 }
2409 
2410 static void
2412  transport_endpoint_t * tep, u8 is_lcl)
2413 {
2414  quic_ctx_t *ctx;
2415  ctx = quic_ctx_get (ctx_index, thread_index);
2416  quic_common_get_transport_endpoint (ctx, tep, is_lcl);
2417 }
2418 
2419 /* *INDENT-OFF* */
2422  .session_disconnect_callback = quic_udp_session_disconnect_callback,
2423  .session_connected_callback = quic_udp_session_connected_callback,
2424  .session_reset_callback = quic_udp_session_reset_callback,
2425  .session_migrate_callback = quic_udp_session_migrate_callback,
2426  .add_segment_callback = quic_add_segment_callback,
2427  .del_segment_callback = quic_del_segment_callback,
2428  .builtin_app_rx_callback = quic_udp_session_rx_callback,
2429  .session_cleanup_callback = quic_udp_session_cleanup_callback,
2430  .app_cert_key_pair_delete_callback = quic_app_cert_key_pair_delete_callback,
2431 };
2432 
2434  .connect = quic_connect,
2435  .close = quic_proto_on_close,
2436  .start_listen = quic_start_listen,
2437  .stop_listen = quic_stop_listen,
2438  .get_connection = quic_connection_get,
2439  .get_listener = quic_listener_get,
2440  .update_time = quic_update_time,
2441  .app_rx_evt = quic_custom_app_rx_callback,
2442  .custom_tx = quic_custom_tx_callback,
2443  .format_connection = format_quic_connection,
2444  .format_half_open = format_quic_half_open,
2445  .format_listener = format_quic_listener,
2446  .get_transport_endpoint = quic_get_transport_endpoint,
2447  .get_transport_listener_endpoint = quic_get_transport_listener_endpoint,
2448  .transport_options = {
2449  .name = "quic",
2450  .short_name = "Q",
2451  .tx_type = TRANSPORT_TX_INTERNAL,
2452  .service_type = TRANSPORT_SERVICE_APP,
2453  },
2454 };
2455 /* *INDENT-ON* */
2456 
2457 static quicly_stream_open_t on_stream_open = { quic_on_stream_open };
2458 static quicly_closed_by_remote_t on_closed_by_remote = {
2460 };
2461 static quicly_now_t quicly_vpp_now_cb = { quic_get_time };
2462 
2463 static void
2465  ptls_cipher_suite_t ** ciphers)
2466 {
2467  quic_main_t *qm = &quic_main;
2470  qm->quic_ciphers[type] = ciphers;
2471 }
2472 
2473 static void
2475 {
2476  quic_main_t *qm = &quic_main;
2477  segment_manager_props_t *seg_mgr_props =
2479 
2480  if (!seg_mgr_props)
2481  {
2482  clib_warning
2483  ("error while getting segment_manager_props_t, can't update fifo-size");
2484  return;
2485  }
2486 
2487  seg_mgr_props->tx_fifo_size = qm->udp_fifo_size;
2488  seg_mgr_props->rx_fifo_size = qm->udp_fifo_size;
2489 }
2490 
2491 static clib_error_t *
2493 {
2494  u32 segment_size = 256 << 20;
2496  tw_timer_wheel_1t_3w_1024sl_ov_t *tw;
2497  vnet_app_attach_args_t _a, *a = &_a;
2499  quic_main_t *qm = &quic_main;
2500  u32 num_threads, i;
2501 
2502  num_threads = 1 /* main thread */ + vtm->n_threads;
2503 
2504  clib_memset (a, 0, sizeof (*a));
2505  clib_memset (options, 0, sizeof (options));
2506 
2507  a->session_cb_vft = &quic_app_cb_vft;
2508  a->api_client_index = APP_INVALID_INDEX;
2509  a->options = options;
2510  a->name = format (0, "quic");
2511  a->options[APP_OPTIONS_SEGMENT_SIZE] = segment_size;
2512  a->options[APP_OPTIONS_ADD_SEGMENT_SIZE] = segment_size;
2513  a->options[APP_OPTIONS_RX_FIFO_SIZE] = qm->udp_fifo_size;
2514  a->options[APP_OPTIONS_TX_FIFO_SIZE] = qm->udp_fifo_size;
2516  a->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
2517  a->options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
2518  a->options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_IS_TRANSPORT_APP;
2519 
2520  if (vnet_application_attach (a))
2521  {
2522  clib_warning ("failed to attach quic app");
2523  return clib_error_return (0, "failed to attach quic app");
2524  }
2525 
2526  vec_validate (qm->ctx_pool, num_threads - 1);
2527  vec_validate (qm->wrk_ctx, num_threads - 1);
2528 
2529  for (i = 0; i < num_threads; i++)
2530  {
2531  qm->wrk_ctx[i].next_cid.thread_id = i;
2532  tw = &qm->wrk_ctx[i].timer_wheel;
2533  tw_timer_wheel_init_1t_3w_1024sl_ov (tw, quic_expired_timers_dispatch,
2534  1e-3 /* timer period 1ms */ , ~0);
2535  tw->last_run_time = vlib_time_now (vlib_get_main ());
2536  clib_bihash_init_24_8 (&qm->wrk_ctx[i].crypto_context_hash,
2537  "quic crypto contexts", 64, 128 << 10);
2538  }
2539 
2540  clib_bihash_init_16_8 (&qm->connection_hash, "quic connections", 1024,
2541  4 << 20);
2542 
2543  qm->app_index = a->app_index;
2547 
2548  transport_register_protocol (TRANSPORT_PROTO_QUIC, &quic_proto,
2549  FIB_PROTOCOL_IP4, ~0);
2550  transport_register_protocol (TRANSPORT_PROTO_QUIC, &quic_proto,
2551  FIB_PROTOCOL_IP6, ~0);
2552 
2556  ptls_openssl_cipher_suites);
2558 
2560  if (vec_len (cm->engines) == 0)
2561  qm->vnet_crypto_enabled = 0;
2562  else
2563  qm->vnet_crypto_enabled = 1;
2564  if (qm->vnet_crypto_enabled == 1)
2565  {
2566  u8 empty_key[32] = {};
2570  vec_validate (qm->per_thread_crypto_key_indices, num_threads);
2571  for (i = 0; i < num_threads; i++)
2572  {
2574  vm, VNET_CRYPTO_ALG_AES_256_CTR, empty_key, 32);
2575  }
2576  }
2577 
2580 
2581  vec_free (a->name);
2582  return 0;
2583 }
2584 
2586 
2587 static clib_error_t *
2589  unformat_input_t * input,
2590  vlib_cli_command_t * cmd)
2591 {
2592  unformat_input_t _line_input, *line_input = &_line_input;
2593  quic_main_t *qm = &quic_main;
2594  clib_error_t *e = 0;
2595 
2596  if (!unformat_user (input, unformat_line_input, line_input))
2597  return 0;
2598 
2599  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2600  {
2601  if (unformat (line_input, "vpp"))
2603  else if (unformat (line_input, "picotls"))
2605  else
2606  {
2607  e = clib_error_return (0, "unknown input '%U'",
2608  format_unformat_error, line_input);
2609  goto done;
2610  }
2611  }
2612 done:
2613  unformat_free (line_input);
2614  return e;
2615 }
2616 
2618 static clib_error_t *
2620  unformat_input_t * input,
2621  vlib_cli_command_t * cmd)
2622 {
2623  quic_main_t *qm = &quic_main;
2624  unformat_input_t _line_input, *line_input = &_line_input;
2625  uword tmp;
2626 
2627  if (!unformat_user (input, unformat_line_input, line_input))
2628  return 0;
2629 
2630  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2631  {
2632  if (unformat (line_input, "%U", unformat_memory_size, &tmp))
2633  {
2634  if (tmp >= 0x100000000ULL)
2635  {
2636  return clib_error_return
2637  (0, "fifo-size %llu (0x%llx) too large", tmp, tmp);
2638  }
2639  qm->udp_fifo_size = tmp;
2641  }
2642  else
2643  return clib_error_return (0, "unknown input '%U'",
2644  format_unformat_error, line_input);
2645  }
2646 
2647  return 0;
2648 }
2649 
2650 static inline u64
2652 {
2653  vlib_node_t *n;
2654  vlib_main_t *vm;
2655  vlib_error_main_t *em;
2656 
2657  u32 code, i;
2658  u64 c, sum = 0;
2659  int index = 0;
2660 
2661  vm = vlib_get_main ();
2662  em = &vm->error_main;
2663  n = vlib_get_node (vm, quic_input_node.index);
2664  code = event_code;
2666  {
2667  em = &this_vlib_main->error_main;
2668  i = n->error_heap_index + code;
2669  c = em->counters[i];
2670 
2671  if (i < vec_len (em->counters_last_clear))
2672  c -= em->counters_last_clear[i];
2673  sum += c;
2674  index++;
2675  }
2676  return sum;
2677 }
2678 
2679 static void
2681 {
2682  u32 num_workers = vlib_num_workers ();
2683  quic_main_t *qm = &quic_main;
2684  quic_ctx_t *ctx = NULL;
2685  quicly_stats_t st, agg_stats;
2686  u32 i, nconn = 0, nstream = 0;
2687 
2688  clib_memset (&agg_stats, 0, sizeof (agg_stats));
2689  for (i = 0; i < num_workers + 1; i++)
2690  {
2691  /* *INDENT-OFF* */
2692  pool_foreach (ctx, qm->ctx_pool[i])
2693  {
2694  if (quic_ctx_is_conn (ctx) && ctx->conn)
2695  {
2696  quicly_get_stats (ctx->conn, &st);
2697  agg_stats.rtt.smoothed += st.rtt.smoothed;
2698  agg_stats.rtt.minimum += st.rtt.minimum;
2699  agg_stats.rtt.variance += st.rtt.variance;
2700  agg_stats.num_packets.received += st.num_packets.received;
2701  agg_stats.num_packets.sent += st.num_packets.sent;
2702  agg_stats.num_packets.lost += st.num_packets.lost;
2703  agg_stats.num_packets.ack_received += st.num_packets.ack_received;
2704  agg_stats.num_bytes.received += st.num_bytes.received;
2705  agg_stats.num_bytes.sent += st.num_bytes.sent;
2706  nconn++;
2707  }
2708  else if (quic_ctx_is_stream (ctx))
2709  nstream++;
2710  }
2711  /* *INDENT-ON* */
2712  }
2713  vlib_cli_output (vm, "-------- Connections --------");
2714  vlib_cli_output (vm, "Current: %u", nconn);
2715  vlib_cli_output (vm, "Opened: %d",
2716  quic_get_counter_value (QUIC_ERROR_OPENED_CONNECTION));
2717  vlib_cli_output (vm, "Closed: %d",
2718  quic_get_counter_value (QUIC_ERROR_CLOSED_CONNECTION));
2719  vlib_cli_output (vm, "---------- Streams ----------");
2720  vlib_cli_output (vm, "Current: %u", nstream);
2721  vlib_cli_output (vm, "Opened: %d",
2722  quic_get_counter_value (QUIC_ERROR_OPENED_STREAM));
2723  vlib_cli_output (vm, "Closed: %d",
2724  quic_get_counter_value (QUIC_ERROR_CLOSED_STREAM));
2725  vlib_cli_output (vm, "---------- Packets ----------");
2726  vlib_cli_output (vm, "RX Total: %d",
2727  quic_get_counter_value (QUIC_ERROR_RX_PACKETS));
2728  vlib_cli_output (vm, "RX 0RTT: %d",
2729  quic_get_counter_value (QUIC_ERROR_ZERO_RTT_RX_PACKETS));
2730  vlib_cli_output (vm, "RX 1RTT: %d",
2731  quic_get_counter_value (QUIC_ERROR_ONE_RTT_RX_PACKETS));
2732  vlib_cli_output (vm, "TX Total: %d",
2733  quic_get_counter_value (QUIC_ERROR_TX_PACKETS));
2734  vlib_cli_output (vm, "----------- Stats -----------");
2735  vlib_cli_output (vm, "Min RTT %f",
2736  nconn > 0 ? agg_stats.rtt.minimum / nconn : 0);
2737  vlib_cli_output (vm, "Smoothed RTT %f",
2738  nconn > 0 ? agg_stats.rtt.smoothed / nconn : 0);
2739  vlib_cli_output (vm, "Variance on RTT %f",
2740  nconn > 0 ? agg_stats.rtt.variance / nconn : 0);
2741  vlib_cli_output (vm, "Packets Received %lu",
2742  agg_stats.num_packets.received);
2743  vlib_cli_output (vm, "Packets Sent %lu", agg_stats.num_packets.sent);
2744  vlib_cli_output (vm, "Packets Lost %lu", agg_stats.num_packets.lost);
2745  vlib_cli_output (vm, "Packets Acks %lu",
2746  agg_stats.num_packets.ack_received);
2747  vlib_cli_output (vm, "RX bytes %lu", agg_stats.num_bytes.received);
2748  vlib_cli_output (vm, "TX bytes %lu", agg_stats.num_bytes.sent);
2749 }
2750 
2751 static u8 *
2752 quic_format_quicly_conn_id (u8 * s, va_list * args)
2753 {
2754  quicly_cid_plaintext_t *mid = va_arg (*args, quicly_cid_plaintext_t *);
2755  s = format (s, "C%x_%x", mid->master_id, mid->thread_id);
2756  return s;
2757 }
2758 
2759 static u8 *
2760 quic_format_quicly_stream_id (u8 * s, va_list * args)
2761 {
2762  quicly_stream_t *stream = va_arg (*args, quicly_stream_t *);
2763  s =
2764  format (s, "%U S%lx", quic_format_quicly_conn_id,
2765  quicly_get_master_id (stream->conn), stream->stream_id);
2766  return s;
2767 }
2768 
2769 static u8 *
2770 quic_format_listener_ctx (u8 * s, va_list * args)
2771 {
2772  quic_ctx_t *ctx = va_arg (*args, quic_ctx_t *);
2773  s = format (s, "[#%d][%x][Listener]", ctx->c_thread_index, ctx->c_c_index);
2774  return s;
2775 }
2776 
2777 static u8 *
2778 quic_format_connection_ctx (u8 * s, va_list * args)
2779 {
2780  quic_ctx_t *ctx = va_arg (*args, quic_ctx_t *);
2781  quicly_stats_t quicly_stats;
2782 
2783  s = format (s, "[#%d][%x]", ctx->c_thread_index, ctx->c_c_index);
2784 
2785  if (!ctx->conn)
2786  {
2787  s = format (s, "- no conn -\n");
2788  return s;
2789  }
2790  s = format (s, "[%U]",
2791  quic_format_quicly_conn_id, quicly_get_master_id (ctx->conn));
2792  quicly_get_stats (ctx->conn, &quicly_stats);
2793 
2794  s = format (s, "[RTT >%3d, ~%3d, V%3d, last %3d]",
2795  quicly_stats.rtt.minimum, quicly_stats.rtt.smoothed,
2796  quicly_stats.rtt.variance, quicly_stats.rtt.latest);
2797  s = format (s, " TX:%d RX:%d loss:%d ack:%d",
2798  quicly_stats.num_packets.sent,
2799  quicly_stats.num_packets.received,
2800  quicly_stats.num_packets.lost,
2801  quicly_stats.num_packets.ack_received);
2802  s =
2803  format (s, "\ncwnd:%u ssthresh:%u recovery_end:%lu", quicly_stats.cc.cwnd,
2804  quicly_stats.cc.ssthresh, quicly_stats.cc.recovery_end);
2805 
2806  quicly_context_t *quicly_ctx = quic_get_quicly_ctx_from_ctx (ctx);
2807  if (quicly_ctx->init_cc == &quicly_cc_cubic_init)
2808  {
2809  s = format (
2810  s,
2811  "\nk:%d w_max:%u w_last_max:%u avoidance_start:%ld last_sent_time:%ld",
2812  quicly_stats.cc.state.cubic.k, quicly_stats.cc.state.cubic.w_max,
2813  quicly_stats.cc.state.cubic.w_last_max,
2814  quicly_stats.cc.state.cubic.avoidance_start,
2815  quicly_stats.cc.state.cubic.last_sent_time);
2816  }
2817  else if (quicly_ctx->init_cc == &quicly_cc_reno_init)
2818  {
2819  s = format (s, " stash:%u", quicly_stats.cc.state.reno.stash);
2820  }
2821 
2822  return s;
2823 }
2824 
2825 static u8 *
2826 quic_format_stream_ctx (u8 * s, va_list * args)
2827 {
2828  quic_ctx_t *ctx = va_arg (*args, quic_ctx_t *);
2829  session_t *stream_session;
2830  quicly_stream_t *stream = ctx->stream;
2831  u32 txs, rxs;
2832 
2833  s = format (s, "[#%d][%x]", ctx->c_thread_index, ctx->c_c_index);
2834  s = format (s, "[%U]", quic_format_quicly_stream_id, stream);
2835 
2836  stream_session = session_get_if_valid (ctx->c_s_index, ctx->c_thread_index);
2837  if (!stream_session)
2838  {
2839  s = format (s, "- no session -\n");
2840  return s;
2841  }
2842  txs = svm_fifo_max_dequeue (stream_session->tx_fifo);
2843  rxs = svm_fifo_max_dequeue (stream_session->rx_fifo);
2844  s = format (s, "[rx %d tx %d]\n", rxs, txs);
2845  return s;
2846 }
2847 
2848 static clib_error_t *
2850  unformat_input_t * input,
2851  vlib_cli_command_t * cmd)
2852 {
2853  unformat_input_t _line_input, *line_input = &_line_input;
2854  u8 show_listeners = 0, show_conn = 0, show_stream = 0;
2855  u32 num_workers = vlib_num_workers ();
2856  quic_main_t *qm = &quic_main;
2857  clib_error_t *error = 0;
2858  quic_ctx_t *ctx = NULL;
2859 
2861 
2862  if (!unformat_user (input, unformat_line_input, line_input))
2863  {
2865  return 0;
2866  }
2867 
2868  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2869  {
2870  if (unformat (line_input, "listener"))
2871  show_listeners = 1;
2872  else if (unformat (line_input, "conn"))
2873  show_conn = 1;
2874  else if (unformat (line_input, "stream"))
2875  show_stream = 1;
2876  else
2877  {
2878  error = clib_error_return (0, "unknown input `%U'",
2879  format_unformat_error, line_input);
2880  goto done;
2881  }
2882  }
2883 
2884  for (int i = 0; i < num_workers + 1; i++)
2885  {
2886  /* *INDENT-OFF* */
2887  pool_foreach (ctx, qm->ctx_pool[i])
2888  {
2889  if (quic_ctx_is_stream (ctx) && show_stream)
2891  else if (quic_ctx_is_listener (ctx) && show_listeners)
2893  else if (quic_ctx_is_conn (ctx) && show_conn)
2895  }
2896  /* *INDENT-ON* */
2897  }
2898 
2899 done:
2900  unformat_free (line_input);
2901  return error;
2902 }
2903 
2904 /* *INDENT-OFF* */
2906  .path = "quic set crypto api",
2907  .short_help = "quic set crypto api [picotls|vpp]",
2908  .function = quic_plugin_crypto_command_fn,
2909 };
2911 {
2912  .path = "quic set fifo-size",
2913  .short_help = "quic set fifo-size N[K|M|G] (default 64K)",
2915 };
2917 {
2918  .path = "show quic",
2919  .short_help = "show quic",
2921 };
2923 {
2924  .path = "show quic crypto context",
2925  .short_help = "list quic crypto contextes",
2927 };
2929 {
2930  .path = "set quic max_packets_per_key",
2931  .short_help = "set quic max_packets_per_key 16777216",
2932  .function = quic_set_max_packets_per_key_fn,
2933 };
2935  .path = "set quic cc",
2936  .short_help = "set quic cc [reno|cubic]",
2937  .function = quic_set_cc_fn,
2938 };
2940 {
2941  .version = VPP_BUILD_VER,
2942  .description = "Quic transport protocol",
2943  .default_disabled = 1,
2944 };
2945 /* *INDENT-ON* */
2946 
2947 static clib_error_t *
2949 {
2950  unformat_input_t _line_input, *line_input = &_line_input;
2951  quic_main_t *qm = &quic_main;
2952  clib_error_t *error = 0;
2953  uword tmp;
2954  u32 i;
2955 
2957  qm->udp_fifo_prealloc = 0;
2959 
2960  if (!unformat_user (input, unformat_line_input, line_input))
2961  return 0;
2962 
2963  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2964  {
2965  if (unformat (input, "fifo-size %U", unformat_memory_size, &tmp))
2966  {
2967  if (tmp >= 0x100000000ULL)
2968  {
2969  error = clib_error_return (0,
2970  "fifo-size %llu (0x%llx) too large",
2971  tmp, tmp);
2972  goto done;
2973  }
2974  qm->udp_fifo_size = tmp;
2975  }
2976  else if (unformat (input, "conn-timeout %u", &i))
2977  qm->connection_timeout = i;
2978  else if (unformat (input, "fifo-prealloc %u", &i))
2979  qm->udp_fifo_prealloc = i;
2980  else
2981  {
2982  error = clib_error_return (0, "unknown input '%U'",
2983  format_unformat_error, line_input);
2984  goto done;
2985  }
2986  }
2987 done:
2988  unformat_free (line_input);
2989  return error;
2990 }
2991 
2993 
2994 static uword
2996  vlib_frame_t * frame)
2997 {
2998  return 0;
2999 }
3000 
3001 /* *INDENT-OFF* */
3003 {
3004  .function = quic_node_fn,
3005  .name = "quic-input",
3006  .vector_size = sizeof (u32),
3008  .n_errors = ARRAY_LEN (quic_error_strings),
3009  .error_strings = quic_error_strings,
3010 };
3011 /* *INDENT-ON* */
3012 
3013 /*
3014  * fd.io coding-style-patch-verification: ON
3015  *
3016  * Local Variables:
3017  * eval: (c-set-style "gnu")
3018  * End:
3019  */
format_quic_listener
static u8 * format_quic_listener(u8 *s, va_list *args)
Definition: quic.c:1602
quic_node_fn
static uword quic_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: quic.c:2995
quic_rx_packet_ctx_::sa
struct sockaddr sa
Definition: quic.h:236
vnet_listen
int vnet_listen(vnet_listen_args_t *a)
Definition: application.c:1294
tmp
u32 * tmp
Definition: interface_output.c:1096
vlib_error_main_t
Definition: error.h:61
QUIC_CONN_STATE_PASSIVE_CLOSING_APP_CLOSED
@ QUIC_CONN_STATE_PASSIVE_CLOSING_APP_CLOSED
Definition: quic.h:115
SESSION_CLI_STATE_LEN
#define SESSION_CLI_STATE_LEN
Definition: session_types.h:508
certs.h
svm_fifo_set_event
static u8 svm_fifo_set_event(svm_fifo_t *f)
Set fifo event flag.
Definition: svm_fifo.h:733
crypto_ctx_::data
void * data
protocol specific data
Definition: application_interface.h:199
QUIC_APP_ALLOCATION_ERROR
#define QUIC_APP_ALLOCATION_ERROR
Definition: quic.h:66
crypto_engine_type_t
enum crypto_engine_type_ crypto_engine_type_t
quic_ctx_::udp_session_handle
session_handle_t udp_session_handle
Definition: quic.h:167
vlib_num_workers
static u32 vlib_num_workers()
Definition: threads.h:333
app_worker_::wrk_index
u32 wrk_index
Worker index in global worker pool.
Definition: application.h:37
quic_worker_ctx_::timer_wheel
tw_timer_wheel_1t_3w_1024sl_ov_t timer_wheel
worker timer wheel
Definition: quic.h:222
quic_udp_session_cleanup_callback
static void quic_udp_session_cleanup_callback(session_t *udp_session, session_cleanup_ntf_t ntf)
Definition: quic.c:1860
session_error_t
enum session_error_ session_error_t
session_dgram_header_::data_length
u32 data_length
Definition: session_types.h:439
CRYPTO_ENGINE_PICOTLS
@ CRYPTO_ENGINE_PICOTLS
Definition: application_interface.h:180
quic_plugin_crypto_command_fn
static clib_error_t * quic_plugin_crypto_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: quic.c:2588
clib_bihash_kv_16_8_t::value
u64 value
Definition: bihash_16_8.h:43
quic_timer_expired
static void quic_timer_expired(u32 conn_index)
Definition: quic.c:1109
quic_receive_connection
static void quic_receive_connection(void *arg)
Definition: quic.c:1716
unformat_user
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
quic_connect_connection
static int quic_connect_connection(session_endpoint_cfg_t *sep)
Definition: quic.c:1306
thread_index
u32 thread_index
Definition: nat44_ei_hairpinning.c:495
quic_stream_data_::thread_index
u32 thread_index
Definition: quic.h:206
format_quic_ctx
static u8 * format_quic_ctx(u8 *s, va_list *args)
Definition: quic.c:1547
vnet_connect
int vnet_connect(vnet_connect_args_t *a)
Definition: application.c:1348
certificate_
Definition: application_interface.h:24
CRYPTO_ENGINE_VPP
@ CRYPTO_ENGINE_VPP
Definition: application_interface.h:179
assert
#define assert(x)
Definition: dlmalloc.c:31
session_dgram_header_
Definition: session_types.h:437
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
format_crypto_context
u8 * format_crypto_context(u8 *s, va_list *args)
Definition: application.c:1772
quic_config_fn
static clib_error_t * quic_config_fn(vlib_main_t *vm, unformat_input_t *input)
Definition: quic.c:2948
APP_OPTIONS_RX_FIFO_SIZE
@ APP_OPTIONS_RX_FIFO_SIZE
Definition: application_interface.h:210
session_::session_index
u32 session_index
Index in thread pool where session was allocated.
Definition: session_types.h:188
vlib_main_t::clib_time
clib_time_t clib_time
Definition: main.h:106
quic_worker_ctx_::crypto_ctx_pool
crypto_context_t * crypto_ctx_pool
per thread pool of crypto contexes
Definition: quic.h:224
quic_get_transport_endpoint
static void quic_get_transport_endpoint(u32 ctx_index, u32 thread_index, transport_endpoint_t *tep, u8 is_lcl)
Definition: quic.c:2411
clib_memcpy
#define clib_memcpy(d, s, n)
Definition: string.h:197
format_quic_connection
static u8 * format_quic_connection(u8 *s, va_list *args)
Definition: quic.c:1579
SESSION_CLI_ID_LEN
#define SESSION_CLI_ID_LEN
Definition: session_types.h:507
SVM_FIFO_WANT_DEQ_NOTIF_IF_FULL
@ SVM_FIFO_WANT_DEQ_NOTIF_IF_FULL
Notify on transition from full.
Definition: svm_fifo.h:36
quic_increment_counter
void quic_increment_counter(u8 evt, u8 val)
Definition: quic.c:602
quic_plugin_crypto_command
static vlib_cli_command_t quic_plugin_crypto_command
(constructor) VLIB_CLI_COMMAND (quic_plugin_crypto_command)
Definition: quic.c:2905
quic_crypto_context_data_
Definition: quic.h:211
application_::quic_iv
char quic_iv[17]
quic initialization vector
Definition: application.h:140
quic_get_quicly_ctx_from_udp
static quicly_context_t * quic_get_quicly_ctx_from_udp(u64 udp_session_handle)
Definition: quic.c:498
quic_format_quicly_stream_id
static u8 * quic_format_quicly_stream_id(u8 *s, va_list *args)
Definition: quic.c:2760
session_transport_closing_notify
void session_transport_closing_notify(transport_connection_t *tc)
Notification from transport that connection is being closed.
Definition: session.c:1062
svm_fifo_enqueue_with_offset
int svm_fifo_enqueue_with_offset(svm_fifo_t *f, u32 offset, u32 len, u8 *src)
Enqueue a future segment.
Definition: svm_fifo.c:906
quic_ctx_
Definition: quic.h:144
f
vlib_frame_t * f
Definition: interface_output.c:1098
quic_ctx_is_conn
static int quic_ctx_is_conn(quic_ctx_t *ctx)
Definition: quic.c:454
quic_set_cc_fn
static clib_error_t * quic_set_cc_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: quic.c:190
unformat_line_input
unformat_function_t unformat_line_input
Definition: format.h:275
quic_worker_ctx_::time_now
int64_t time_now
worker time
Definition: quic.h:221
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
session_get_endpoint
void session_get_endpoint(session_t *s, transport_endpoint_t *tep, u8 is_lcl)
Definition: session.c:1754
quic_crypto_context_get
static crypto_context_t * quic_crypto_context_get(u32 cr_index, u32 thread_index)
Definition: quic.c:135
vnet_unlisten
int vnet_unlisten(vnet_unlisten_args_t *a)
Definition: application.c:1387
quic_on_stream_open
static int quic_on_stream_open(quicly_stream_open_t *self, quicly_stream_t *stream)
Definition: quic.c:974
QUIC_MAX_PACKET_SIZE
#define QUIC_MAX_PACKET_SIZE
Definition: quic.h:41
quic_fifo_egress_emit
void quic_fifo_egress_emit(quicly_stream_t *stream, size_t off, void *dst, size_t *len, int *wrote_all)
Definition: quic.c:930
vnet_crypto_main_t
Definition: crypto.h:451
listen_session_get_handle
static u64 listen_session_get_handle(session_t *s)
Definition: session.h:623
session_::tx_fifo
svm_fifo_t * tx_fifo
Definition: session_types.h:179
QUIC_TIMER_HANDLE_INVALID
#define QUIC_TIMER_HANDLE_INVALID
Definition: quic.h:39
quic_udp_session_connected_callback
static int quic_udp_session_connected_callback(u32 quic_app_index, u32 ctx_index, session_t *udp_session, session_error_t err)
Definition: quic.c:1783
QUIC_APP_CONNECT_NOTIFY_ERROR
#define QUIC_APP_CONNECT_NOTIFY_ERROR
Definition: quic.h:68
quic_ctx_::ckpair_index
u32 ckpair_index
Definition: quic.h:171
svm_fifo_peek
int svm_fifo_peek(svm_fifo_t *f, u32 offset, u32 len, u8 *dst)
Peek data from fifo.
Definition: svm_fifo.c:1141
quic_store_conn_ctx
static void quic_store_conn_ctx(quicly_conn_t *conn, quic_ctx_t *ctx)
Definition: quic.c:435
VLIB_NODE_TYPE_INTERNAL
@ VLIB_NODE_TYPE_INTERNAL
Definition: node.h:72
clib_mem_free
static void clib_mem_free(void *p)
Definition: mem.h:314
QUIC_CONN_STATE_PASSIVE_CLOSING_QUIC_CLOSED
@ QUIC_CONN_STATE_PASSIVE_CLOSING_QUIC_CLOSED
Definition: quic.h:116
quic_rx_packet_ctx_::ptype
u8 ptype
Definition: quic.h:240
load_bio_certificate_chain
int load_bio_certificate_chain(ptls_context_t *ctx, const char *cert_data)
Definition: certs.c:178
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
quic_disconnect_transport
static void quic_disconnect_transport(quic_ctx_t *ctx)
Definition: quic.c:556
quic_main_::session_cache
quic_session_cache_t session_cache
Definition: quic.h:259
quic_stream_data_::app_rx_data_len
u32 app_rx_data_len
bytes received, to be read by external app
Definition: quic.h:207
session_
Definition: session_types.h:175
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
session_endpoint_cfg_t
struct _session_endpoint_cfg session_endpoint_cfg_t
quic_get_quicly_ctx_from_ctx
static quicly_context_t * quic_get_quicly_ctx_from_ctx(quic_ctx_t *ctx)
Definition: quic.c:488
QUIC_CC_CUBIC
@ QUIC_CC_CUBIC
Definition: quic.h:139
vlib_cli_command_t::path
char * path
Definition: cli.h:96
quic_send_datagram
static int quic_send_datagram(session_t *udp_session, struct iovec *packet, quicly_address_t *dest, quicly_address_t *src)
Definition: quic.c:652
session_handle_t
u64 session_handle_t
Definition: session_types.h:111
quic_set_time_now
static u32 quic_set_time_now(u32 thread_index)
Definition: quic.c:1089
clib_bihash_kv_24_8_t
Definition: bihash_24_8.h:40
quic_update_conn_ctx
static void quic_update_conn_ctx(quicly_conn_t *conn, quicly_context_t *quicly_context)
Definition: quic.c:1703
application_::quic_iv_set
u8 quic_iv_set
Definition: application.h:141
quic_init
static clib_error_t * quic_init(vlib_main_t *vm)
Definition: quic.c:2492
quic_connection_delete
static void quic_connection_delete(quic_ctx_t *ctx)
Definition: quic.c:570
transport_proto_vft_t
struct _transport_proto_vft transport_proto_vft_t
quic_check_quic_session_connected
static void quic_check_quic_session_connected(quic_ctx_t *ctx)
Definition: quic.c:1685
vlib_main_t::error_main
vlib_error_main_t error_main
Definition: main.h:179
u16
unsigned short u16
Definition: types.h:57
error.h
quic_update_fifo_size
static void quic_update_fifo_size()
Definition: quic.c:2474
APP_INVALID_INDEX
#define APP_INVALID_INDEX
Definition: application.h:226
quic_set_max_packets_per_key_fn
static clib_error_t * quic_set_max_packets_per_key_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: quic.c:164
SESSION_IO_EVT_RX
@ SESSION_IO_EVT_RX
Definition: session_types.h:328
quic_crypto_context_make_key_from_crctx
static void quic_crypto_context_make_key_from_crctx(clib_bihash_kv_24_8_t *kv, crypto_context_t *crctx)
Definition: quic.c:70
session_::thread_index
u8 thread_index
Index of the thread that allocated the session.
Definition: session_types.h:194
pool_put
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:305
quic_crypto_cipher_suites
ptls_cipher_suite_t * quic_crypto_cipher_suites[]
Definition: quic_crypto.c:543
session_::session_type
session_type_t session_type
Type built from transport and network protocol types.
Definition: session_types.h:182
quic_ctx_alloc
static u32 quic_ctx_alloc(u32 thread_index)
Definition: quic.c:386
quic_show_ctx_command
static vlib_cli_command_t quic_show_ctx_command
(constructor) VLIB_CLI_COMMAND (quic_show_ctx_command)
Definition: quic.c:2916
quic_rx_packet_ctx_::thread_index
u32 thread_index
Definition: quic.h:233
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
get_stream_session_and_ctx_from_stream
static session_t * get_stream_session_and_ctx_from_stream(quicly_stream_t *stream, quic_ctx_t **ctx)
Definition: quic.c:460
quic_stop_listen
static u32 quic_stop_listen(u32 lctx_index)
Definition: quic.c:1509
SESSION_IO_EVT_BUILTIN_TX
@ SESSION_IO_EVT_BUILTIN_TX
Definition: session_types.h:332
format_quic_half_open
static u8 * format_quic_half_open(u8 *s, va_list *args)
Definition: quic.c:1590
quic_crypto_context_make_key_from_ctx
static void quic_crypto_context_make_key_from_ctx(clib_bihash_kv_24_8_t *kv, quic_ctx_t *ctx)
Definition: quic.c:60
packet
description malformed packet
Definition: map.api:445
certificate_::key
u8 * key
Definition: application_interface.h:28
port
u16 port
Definition: lb_types.api:73
plugin.h
quic_ctx_::parent_app_id
u32 parent_app_id
Definition: quic.h:170
vnet_unlisten_args_t
struct _vnet_unlisten_args_t vnet_unlisten_args_t
crypto_ctx_::n_subscribers
u32 n_subscribers
refcount of sessions using said context
Definition: application_interface.h:196
application_
Definition: application.h:108
APP_OPTIONS_SEGMENT_SIZE
@ APP_OPTIONS_SEGMENT_SIZE
Definition: application_interface.h:207
session_thread_from_handle
static u32 session_thread_from_handle(session_handle_t handle)
Definition: session_types.h:295
load_bio_private_key
int load_bio_private_key(ptls_context_t *ctx, const char *pk_data)
Definition: certs.c:192
quic_ctx_get_if_valid
static quic_ctx_t * quic_ctx_get_if_valid(u32 ctx_index, u32 thread_index)
Definition: quic.c:419
transport_connection_t
struct _transport_connection transport_connection_t
unformat_input_t
struct _unformat_input_t unformat_input_t
session_type_transport_proto
static transport_proto_t session_type_transport_proto(session_type_t st)
Definition: session_types.h:230
quic_udp_session_disconnect_callback
static void quic_udp_session_disconnect_callback(session_t *s)
Definition: quic.c:1854
addr
vhost_vring_addr_t addr
Definition: vhost_user.h:130
vlib_frame_t
Definition: node.h:372
clib_bitmap_alloc
#define clib_bitmap_alloc(v, n_bits)
Allocate a bitmap with the supplied number of bits.
Definition: bitmap.h:109
quic_ctx_::parent_app_wrk_id
u32 parent_app_wrk_id
Definition: quic.h:169
transport_endpoint_pair_
Definition: transport_types.h:216
clib_memcpy_fast
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
Definition: string.h:92
quic_ctx_is_listener
static int quic_ctx_is_listener(quic_ctx_t *ctx)
Definition: quic.c:448
quic_udp_session_accepted_callback
int quic_udp_session_accepted_callback(session_t *udp_session)
Definition: quic.c:1900
APP_OPTIONS_N_OPTIONS
@ APP_OPTIONS_N_OPTIONS
Definition: application_interface.h:223
quic_ctx_::timer_handle
u32 timer_handle
Definition: quic.h:168
h
h
Definition: flowhash_template.h:372
error
Definition: cJSON.c:88
SESSION_CONN_HDR_LEN
#define SESSION_CONN_HDR_LEN
Definition: session_types.h:449
VLIB_EARLY_CONFIG_FUNCTION
#define VLIB_EARLY_CONFIG_FUNCTION(x, n,...)
Definition: init.h:220
quic_ctx_::flags
u8 flags
Definition: quic.h:174
clib_time_t::seconds_per_clock
f64 seconds_per_clock
Definition: time.h:58
session_cb_vft_::session_accept_callback
int(* session_accept_callback)(session_t *new_session)
Notify server of newly accepted session.
Definition: application_interface.h:41
quic_main_::connection_timeout
u32 connection_timeout
Definition: quic.h:263
transport_endpt_crypto_cfg_::hostname
u8 hostname[256]
full domain len is 255 as per rfc 3986
Definition: transport_types.h:277
quic_main_
Definition: quic.h:244
quic_stop_ctx_timer
static void quic_stop_ctx_timer(quic_ctx_t *ctx)
Definition: quic.c:518
on_closed_by_remote
static quicly_closed_by_remote_t on_closed_by_remote
Definition: quic.c:54
quic_set_udp_tx_evt
static void quic_set_udp_tx_evt(session_t *udp_session)
Definition: quic.c:507
svm_fifo_t
struct _svm_fifo svm_fifo_t
quic_custom_app_rx_callback
static int quic_custom_app_rx_callback(transport_connection_t *tc)
Definition: quic.c:1953
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
pool_is_free_index
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:302
quic_plugin_set_fifo_size_command_fn
static clib_error_t * quic_plugin_set_fifo_size_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: quic.c:2619
QUIC_PACKET_TYPE_ACCEPT
@ QUIC_PACKET_TYPE_ACCEPT
Definition: quic.h:125
quic_ctx_::crypto_context_index
u32 crypto_context_index
Definition: quic.h:173
quic_on_receive
static void quic_on_receive(quicly_stream_t *stream, size_t off, const void *src, size_t len)
Definition: quic.c:829
application_get
application_t * application_get(u32 app_index)
Definition: application.c:710
foreach_vlib_main
#define foreach_vlib_main()
Definition: threads.h:216
QUIC_SEND_PACKET_VEC_SIZE
#define QUIC_SEND_PACKET_VEC_SIZE
Definition: quic.h:45
quic_udp_session_migrate_callback
static void quic_udp_session_migrate_callback(session_t *s, session_handle_t new_sh)
Definition: quic.c:1882
session_cb_vft_
Definition: application_interface.h:32
session_::app_wrk_index
u32 app_wrk_index
Index of the app worker that owns the session.
Definition: session_types.h:191
pool_foreach
#define pool_foreach(VAR, POOL)
Iterate through pool.
Definition: pool.h:534
app_worker_init_connected
int app_worker_init_connected(app_worker_t *app_wrk, session_t *s)
Definition: application_worker.c:358
quic_listener_get
static transport_connection_t * quic_listener_get(u32 listener_index)
Definition: quic.c:1538
quic_stream_data_
Definition: quic.h:203
svm_fifo_seg_
Definition: svm_fifo.h:52
app_crypto_engine_n_types
u8 app_crypto_engine_n_types(void)
Definition: application.c:2125
session_::rx_fifo
svm_fifo_t * rx_fifo
Pointers to rx/tx buffers.
Definition: session_types.h:178
unformat_memory_size
unformat_function_t unformat_memory_size
Definition: format.h:288
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
unformat_free
static void unformat_free(unformat_input_t *i)
Definition: format.h:155
QUIC_PACKET_TYPE_RECEIVE
@ QUIC_PACKET_TYPE_RECEIVE
Definition: quic.h:123
session_dgram_header_::lcl_port
u16 lcl_port
Definition: session_types.h:444
clib_bitmap_get
static uword clib_bitmap_get(uword *ai, uword i)
Gets the ith bit value from a bitmap.
Definition: bitmap.h:197
len
u8 len
Definition: ip_types.api:103
vlib_error_main_t::counters
u64 * counters
Definition: error.h:64
quic_get_thread_time
static int64_t quic_get_thread_time(u8 thread_index)
Definition: quic.c:1076
QUIC_DEFAULT_CONN_TIMEOUT
#define QUIC_DEFAULT_CONN_TIMEOUT
Definition: quic.h:52
vnet_disconnect_args_t
struct _vnet_disconnect_args_t vnet_disconnect_args_t
quic_register_cipher_suite
static void quic_register_cipher_suite(crypto_engine_type_t type, ptls_cipher_suite_t **ciphers)
Definition: quic.c:2464
quic_app_cb_vft
static session_cb_vft_t quic_app_cb_vft
Definition: quic.c:2420
quic_main_::wrk_ctx
quic_worker_ctx_t * wrk_ctx
Definition: quic.h:248
application_get_segment_manager_properties
segment_manager_props_t * application_get_segment_manager_properties(u32 app_index)
Definition: application.c:1662
session_get_transport
transport_connection_t * session_get_transport(session_t *s)
Definition: session.c:1743
QUIC_DBG
#define QUIC_DBG(_lvl, _fmt, _args...)
Definition: quic.h:79
quic_main_::quic_ciphers
ptls_cipher_suite_t *** quic_ciphers
available ciphers by crypto engine
Definition: quic.h:252
svm_fifo_max_enqueue
static u32 svm_fifo_max_enqueue(svm_fifo_t *f)
Definition: svm_fifo.h:621
QUIC_CC_RENO
@ QUIC_CC_RENO
Definition: quic.h:138
QUIC_PACKET_TYPE_RESET
@ QUIC_PACKET_TYPE_RESET
Definition: quic.h:126
segment_manager_props_t
struct _segment_manager_props segment_manager_props_t
quic_custom_tx_callback
static int quic_custom_tx_callback(void *s, transport_send_params_t *sp)
Definition: quic.c:1969
QUIC_APP_ACCEPT_NOTIFY_ERROR
#define QUIC_APP_ACCEPT_NOTIFY_ERROR
Definition: quic.h:67
lock.h
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
vlib_get_thread_index
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:187
app_worker_get_if_valid
app_worker_t * app_worker_get_if_valid(u32 wrk_index)
Definition: application_worker.c:47
QUIC_RCV_MAX_PACKETS
#define QUIC_RCV_MAX_PACKETS
Definition: quic.h:50
session_send_io_evt_to_thread_custom
int session_send_io_evt_to_thread_custom(void *data, u32 thread_index, session_evt_type_t evt_type)
Definition: session.c:91
ARRAY_LEN
#define ARRAY_LEN(x)
Definition: clib.h:70
vnet_listen_args_t
struct _vnet_bind_args_t vnet_listen_args_t
QUIC_F_IS_STREAM
@ QUIC_F_IS_STREAM
Definition: quic.h:132
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
quic_find_packet_ctx
static int quic_find_packet_ctx(quic_rx_packet_ctx_t *pctx, u32 caller_thread_index)
Definition: quic.c:2021
vlib_config_function_runtime_t
Definition: init.h:68
quic_main_::hs_properties
ptls_handshake_properties_t hs_properties
Definition: quic.h:258
c
svmdb_client_t * c
Definition: vpp_get_metrics.c:48
quic_on_quic_session_connected
static void quic_on_quic_session_connected(quic_ctx_t *ctx)
Definition: quic.c:1637
QUIC_F_IS_LISTENER
@ QUIC_F_IS_LISTENER
Definition: quic.h:133
quic_main_::vnet_crypto_enabled
u8 vnet_crypto_enabled
Definition: quic.h:265
quic_transfer_connection
static void quic_transfer_connection(u32 ctx_index, u32 dest_thread)
Definition: quic.c:1760
QUIC_DEFAULT_FIFO_SIZE
#define QUIC_DEFAULT_FIFO_SIZE
Definition: quic.h:44
quic_format_err
u8 * quic_format_err(u8 *s, va_list *args)
Definition: error.c:22
uword
u64 uword
Definition: types.h:112
quic_connect_stream
static int quic_connect_stream(session_t *quic_session, session_endpoint_cfg_t *sep)
Definition: quic.c:1195
if
if(node->flags &VLIB_NODE_FLAG_TRACE) vnet_interface_output_trace(vm
svm_fifo_enqueue_segments
int svm_fifo_enqueue_segments(svm_fifo_t *f, const svm_fifo_seg_t segs[], u32 n_segs, u8 allow_partial)
Enqueue array of svm_fifo_seg_t in order.
Definition: svm_fifo.c:972
TRANSPORT_SERVICE_APP
@ TRANSPORT_SERVICE_APP
app transport service
Definition: transport_types.h:41
vlib_node_increment_counter
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1244
clib_bihash_kv_24_8_t::value
u64 value
Definition: bihash_24_8.h:43
vlib_get_node
static vlib_node_t * vlib_get_node(vlib_main_t *vm, u32 i)
Get vlib node by index.
Definition: node_funcs.h:86
quic_udp_session_reset_callback
static void quic_udp_session_reset_callback(session_t *s)
Definition: quic.c:1876
transport_cl_thread
static u32 transport_cl_thread(void)
Definition: session.h:613
quic_main_::ctx_pool
quic_ctx_t ** ctx_pool
Definition: quic.h:247
quic_on_stop_sending
static void quic_on_stop_sending(quicly_stream_t *stream, int err)
Definition: quic.c:799
quic_crypto_context_alloc
static crypto_context_t * quic_crypto_context_alloc(u8 thread_index)
Definition: quic.c:120
session_send_rpc_evt_to_thread
void session_send_rpc_evt_to_thread(u32 thread_index, void *fp, void *rpc_args)
Definition: session.c:116
svm_fifo_dequeue_drop
int svm_fifo_dequeue_drop(svm_fifo_t *f, u32 len)
Dequeue and drop bytes from fifo.
Definition: svm_fifo.c:1168
QUIC_PACKET_TYPE_NONE
@ QUIC_PACKET_TYPE_NONE
Definition: quic.h:122
f64
double f64
Definition: types.h:142
quic_format_connection_ctx
static u8 * quic_format_connection_ctx(u8 *s, va_list *args)
Definition: quic.c:2778
quic_get_time
static int64_t quic_get_time(quicly_now_t *self)
Definition: quic.c:1082
session_handle
static session_handle_t session_handle(session_t *s)
Definition: session_types.h:283
svm_fifo_enqueue
int svm_fifo_enqueue(svm_fifo_t *f, u32 len, const u8 *src)
Enqueue data to fifo.
Definition: svm_fifo.c:847
TRANSPORT_CFG_F_CONNECTED
@ TRANSPORT_CFG_F_CONNECTED
Definition: transport_types.h:202
application_::ns_index
u32 ns_index
Namespace the application belongs to.
Definition: application.h:129
session_dgram_header_::data_offset
u32 data_offset
Definition: session_types.h:440
transport_endpt_crypto_cfg_::ckpair_index
u32 ckpair_index
Definition: transport_types.h:275
transport_register_protocol
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.
Definition: transport.c:246
cm
vnet_feature_config_main_t * cm
Definition: nat44_ei_hairpinning.c:594
quic_main_::udp_fifo_prealloc
u32 udp_fifo_prealloc
Definition: quic.h:262
quic_stream_data_::app_tx_data_len
u32 app_tx_data_len
bytes sent
Definition: quic.h:208
format_unformat_error
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
pool_get
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:255
quic_worker_ctx_::next_cid
quicly_cid_plaintext_t next_cid
Definition: quic.h:223
session_get_from_handle
static session_t * session_get_from_handle(session_handle_t handle)
Definition: session.h:357
quic_worker_ctx_::crypto_context_hash
clib_bihash_24_8_t crypto_context_hash
per thread [params:crypto_ctx_index] hash
Definition: quic.h:225
session_get_from_handle_if_valid
static session_t * session_get_from_handle_if_valid(session_handle_t handle)
Definition: session.h:366
vec_validate
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
Definition: vec.h:523
app_worker_init_accepted
int app_worker_init_accepted(session_t *s)
Definition: application_worker.c:328
quic_on_closed_by_remote
static void quic_on_closed_by_remote(quicly_closed_by_remote_t *self, quicly_conn_t *conn, int code, uint64_t frame_type, const char *reason, size_t reason_len)
Definition: quic.c:1058
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
src
vl_api_address_t src
Definition: gre.api:54
SESSION_IO_EVT_TX
@ SESSION_IO_EVT_TX
Definition: session_types.h:329
quic_main_::max_packets_per_key
u64 max_packets_per_key
number of packets that can be sent without a key update
Definition: quic.h:255
quic_rx_packet_ctx_::data
u8 data[QUIC_MAX_PACKET_SIZE]
Definition: quic.h:231
quic_crypto_context_free_if_needed
static void quic_crypto_context_free_if_needed(crypto_context_t *crctx, u8 thread_index)
Definition: quic.c:81
clib_bitmap_set
static uword * clib_bitmap_set(uword *ai, uword i, uword value)
Sets the ith bit of a bitmap to new_value Removes trailing zeros from the bitmap.
Definition: bitmap.h:167
transport_endpt_crypto_cfg_::crypto_engine
u8 crypto_engine
Definition: transport_types.h:276
quic_ctx_::conn
quicly_conn_t * conn
QUIC ctx case.
Definition: quic.h:151
FIB_PROTOCOL_IP4
@ FIB_PROTOCOL_IP4
Definition: fib_types.h:36
clib_min
#define clib_min(x, y)
Definition: clib.h:342
quic_rx_packet_ctx_::packet
quicly_decoded_packet_t packet
Definition: quic.h:230
quic_plugin_set_fifo_size_command
static vlib_cli_command_t quic_plugin_set_fifo_size_command
(constructor) VLIB_CLI_COMMAND (quic_plugin_set_fifo_size_command)
Definition: quic.c:2910
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
session_get
static session_t * session_get(u32 si, u32 thread_index)
Definition: session.h:337
vnet_disconnect_session
int vnet_disconnect_session(vnet_disconnect_args_t *a)
Definition: application.c:1439
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
QUIC_PACKET_TYPE_MIGRATE
@ QUIC_PACKET_TYPE_MIGRATE
Definition: quic.h:124
session_transport_delete_notify
void session_transport_delete_notify(transport_connection_t *tc)
Notification from transport that connection is being deleted.
Definition: session.c:1084
app_worker_connect_notify
int app_worker_connect_notify(app_worker_t *app_wrk, session_t *s, session_error_t err, u32 opaque)
Definition: application_worker.c:375
quic_ctx_free
static void quic_ctx_free(quic_ctx_t *ctx)
Definition: quic.c:402
quic_build_sockaddr
static void quic_build_sockaddr(struct sockaddr *sa, socklen_t *salen, ip46_address_t *addr, u16 port, u8 is_ip4)
Definition: quic.c:1615
quic_crypto_engine
quicly_crypto_engine_t quic_crypto_engine
Definition: quic_crypto.c:547
quic_format_quicly_conn_id
static u8 * quic_format_quicly_conn_id(u8 *s, va_list *args)
Definition: quic.c:2752
quic_crypto.h
APP_OPTIONS_PREALLOC_FIFO_PAIRS
@ APP_OPTIONS_PREALLOC_FIFO_PAIRS
Definition: application_interface.h:212
quic_show_aggregated_stats
static void quic_show_aggregated_stats(vlib_main_t *vm)
Definition: quic.c:2680
quic_show_connections_command_fn
static clib_error_t * quic_show_connections_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: quic.c:2849
crypto_main
vnet_crypto_main_t crypto_main
Definition: crypto.c:20
TRANSPORT_TX_INTERNAL
@ TRANSPORT_TX_INTERNAL
apps acting as transports
Definition: transport_types.h:32
session_::listener_handle
session_handle_t listener_handle
Parent listener session index if the result of an accept.
Definition: session_types.h:208
app_listener_get_w_handle
app_listener_t * app_listener_get_w_handle(session_handle_t handle)
Get app listener for listener session handle.
Definition: application.c:88
session_type_from_proto_and_ip
static session_type_t session_type_from_proto_and_ip(transport_proto_t proto, u8 is_ip4)
Definition: session_types.h:224
vnet_application_attach
int vnet_application_attach(vnet_app_attach_args_t *a)
Attach application to vpp.
Definition: application.c:1142
transport_send_params_
Definition: transport.h:45
data
u8 data[128]
Definition: ipsec_types.api:95
quic_accept_connection
static void quic_accept_connection(quic_rx_packet_ctx_t *pctx)
Definition: quic.c:2066
quic_error.def
id
u8 id[64]
Definition: dhcp.api:160
quic_main_::default_quic_cc
u8 default_quic_cc
Definition: quic.h:256
quic_expired_timers_dispatch
static void quic_expired_timers_dispatch(u32 *expired_timers)
Definition: quic.c:1183
QUIC_CONN_STATE_OPENED
@ QUIC_CONN_STATE_OPENED
Definition: quic.h:111
vnet_crypto_key_add
u32 vnet_crypto_key_add(vlib_main_t *vm, vnet_crypto_alg_t alg, u8 *data, u16 length)
Definition: crypto.c:360
quic_stream_data_::ctx_id
u32 ctx_id
Definition: quic.h:205
quic_on_stream_destroy
static void quic_on_stream_destroy(quicly_stream_t *stream, int err)
Definition: quic.c:780
QUIC_ERR
#define QUIC_ERR(_fmt, _args...)
Definition: quic.h:92
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
quic_start_listen
static u32 quic_start_listen(u32 quic_listen_session_index, transport_endpoint_t *tep)
Definition: quic.c:1444
index
u32 index
Definition: flow_types.api:221
crypto_ctx_::ctx_index
u32 ctx_index
index in crypto context pool
Definition: application_interface.h:195
quic_proto
static const transport_proto_vft_t quic_proto
Definition: quic.c:2433
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
APP_OPTIONS_TX_FIFO_SIZE
@ APP_OPTIONS_TX_FIFO_SIZE
Definition: application_interface.h:211
quic_ctx_::stream
quicly_stream_t * stream
STREAM ctx case.
Definition: quic.h:161
QUIC_ASSERT
#define QUIC_ASSERT(truth)
Definition: quic.h:85
TRANSPORT_CONNECTION_F_NO_LOOKUP
@ TRANSPORT_CONNECTION_F_NO_LOOKUP
Don't register connection in lookup.
Definition: transport_types.h:52
clib_bihash_kv_16_8_t
Definition: bihash_16_8.h:40
DEFAULT_MAX_PACKETS_PER_KEY
#define DEFAULT_MAX_PACKETS_PER_KEY
Definition: quic.c:44
QUIC_INT_MAX
#define QUIC_INT_MAX
Definition: quic.h:43
svm_fifo_max_enqueue_prod
static u32 svm_fifo_max_enqueue_prod(svm_fifo_t *f)
Maximum number of bytes that can be enqueued into fifo.
Definition: svm_fifo.h:607
vlib_error_main_t::counters_last_clear
u64 * counters_last_clear
Definition: error.h:67
APP_OPTIONS_ADD_SEGMENT_SIZE
@ APP_OPTIONS_ADD_SEGMENT_SIZE
Definition: application_interface.h:208
u64
unsigned long u64
Definition: types.h:89
quic_error_strings
static char * quic_error_strings[]
Definition: quic.c:38
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
session_dgram_header_::rmt_port
u16 rmt_port
Definition: session_types.h:443
SVM_FIFO_WANT_DEQ_NOTIF_IF_EMPTY
@ SVM_FIFO_WANT_DEQ_NOTIF_IF_EMPTY
Notify on transition to empty.
Definition: svm_fifo.h:37
on_stream_open
static quicly_stream_open_t on_stream_open
Definition: quic.c:53
quic_send_packets
static int quic_send_packets(quic_ctx_t *ctx)
Definition: quic.c:711
off
u32 off
Definition: interface_output.c:1096
vlib_thread_main_t::n_threads
u32 n_threads
Definition: threads.h:271
application_::sm_properties
segment_manager_props_t sm_properties
Segment manager properties.
Definition: application.h:120
quic_session_cache_::super
ptls_encrypt_ticket_t super
Definition: quic.h:198
format_ip46_address
format_function_t format_ip46_address
Definition: ip46_address.h:50
clib_bihash_kv_16_8_t::key
u64 key[2]
Definition: bihash_16_8.h:42
quic_rx_packet_ctx_::salen
socklen_t salen
Definition: quic.h:239
quic_main_::app_index
u32 app_index
Definition: quic.h:246
crypto_ctx_
Definition: application_interface.h:193
session_get_if_valid
static session_t * session_get_if_valid(u64 si, u32 thread_index)
Definition: session.h:344
session_::opaque
u32 opaque
Opaque, for general use.
Definition: session_types.h:218
quic_main_::default_crypto_engine
u8 default_crypto_engine
Used if you do connect with CRYPTO_ENGINE_NONE (0)
Definition: quic.h:254
QUIC_IV_LEN
#define QUIC_IV_LEN
Definition: quic.h:46
buf
u64 buf
Definition: application.c:493
u32
unsigned int u32
Definition: types.h:88
quic_get_conn_ctx
quic_ctx_t * quic_get_conn_ctx(quicly_conn_t *conn)
Definition: quic.c:427
SESSION_CLEANUP_SESSION
@ SESSION_CLEANUP_SESSION
Definition: session_types.h:116
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
transport_endpoint_
Definition: transport_types.h:193
options
static struct option options[]
Definition: main.c:52
vlib_thread_main_t
Definition: threads.h:243
quic_app_cert_key_pair_delete_callback
static int quic_app_cert_key_pair_delete_callback(app_cert_key_pair_t *ckpair)
Definition: quic.c:95
app_worker_lock_and_send_event
int app_worker_lock_and_send_event(app_worker_t *app, session_t *s, u8 evt_type)
Send event to application.
Definition: application_worker.c:706
quic_format_listener_ctx
static u8 * quic_format_listener_ctx(u8 *s, va_list *args)
Definition: quic.c:2770
quic_reset_connection
static int quic_reset_connection(u64 udp_session_handle, quic_rx_packet_ctx_t *pctx)
Definition: quic.c:2145
quic_common_get_transport_endpoint
static void quic_common_get_transport_endpoint(quic_ctx_t *ctx, transport_endpoint_t *tep, u8 is_lcl)
Definition: quic.c:2382
quic_stream_callbacks
static const quicly_stream_callbacks_t quic_stream_callbacks
Definition: quic.c:964
FIB_PROTOCOL_IP6
@ FIB_PROTOCOL_IP6
Definition: fib_types.h:37
dst
vl_api_ip4_address_t dst
Definition: pnat.api:41
quic_on_receive_reset
static void quic_on_receive_reset(quicly_stream_t *stream, int err)
Definition: quic.c:814
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
app_worker_get
app_worker_t * app_worker_get(u32 wrk_index)
Definition: application_worker.c:41
clib_bihash_kv_24_8_t::key
u64 key[3]
Definition: bihash_24_8.h:42
app_worker_
Definition: application.h:32
quic_ctx_::udp_is_ip4
u8 udp_is_ip4
Definition: quic.h:156
QUIC_CONN_STATE_HANDSHAKE
@ QUIC_CONN_STATE_HANDSHAKE
Definition: quic.h:112
vnet_connect_args_t
struct _vnet_connect_args vnet_connect_args_t
quic_ack_rx_data
static void quic_ack_rx_data(session_t *stream_session)
Definition: quic.c:532
quic_fifosize
u64 quic_fifosize
Definition: quic.c:2617
QUIC_CONN_STATE_PASSIVE_CLOSING
@ QUIC_CONN_STATE_PASSIVE_CLOSING
Definition: quic.h:114
quic_main
quic_main_t quic_main
Definition: quic.c:46
TRANSPORT_CFG_F_UNIDIRECTIONAL
@ TRANSPORT_CFG_F_UNIDIRECTIONAL
Definition: transport_types.h:203
quic_make_connection_key
static void quic_make_connection_key(clib_bihash_kv_16_8_t *kv, const quicly_cid_plaintext_t *id)
Definition: quic.c:471
quic_format_stream_ctx
static u8 * quic_format_stream_ctx(u8 *s, va_list *args)
Definition: quic.c:2826
SESSION_INVALID_HANDLE
#define SESSION_INVALID_HANDLE
Definition: session_types.h:23
APP_OPTIONS_FLAGS
@ APP_OPTIONS_FLAGS
Definition: application_interface.h:205
now
f64 now
Definition: nat44_ei_out2in.c:710
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
quic_set_cc
static vlib_cli_command_t quic_set_cc
(constructor) VLIB_CLI_COMMAND (quic_set_cc)
Definition: quic.c:2934
quic.h
quic_input_node
vlib_node_registration_t quic_input_node
(constructor) VLIB_REGISTER_NODE (quic_input_node)
Definition: quic.c:3002
vlib_node_t
Definition: node.h:247
quic_main_::available_crypto_engines
uword * available_crypto_engines
Bitmap for registered engines.
Definition: quic.h:253
vlib_get_main
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:38
quic_main_::tstamp_ticks_per_clock
f64 tstamp_ticks_per_clock
Definition: quic.h:250
u8
unsigned char u8
Definition: types.h:56
quic_ctx_::crypto_engine
u32 crypto_engine
Definition: quic.h:172
quic_connect
static int quic_connect(transport_endpoint_cfg_t *tep)
Definition: quic.c:1366
clib_error_t
Definition: clib_error.h:21
transport.h
a
a
Definition: bitmap.h:525
QUIC_TSTAMP_RESOLUTION
#define QUIC_TSTAMP_RESOLUTION
Definition: quic.h:38
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
crypto_ctx_::crypto_engine
u8 crypto_engine
Definition: application_interface.h:198
quic_connection_closed
static void quic_connection_closed(quic_ctx_t *ctx)
Called when quicly return an error This function interacts tightly with quic_proto_on_close.
Definition: quic.c:613
vec_terminate_c_string
#define vec_terminate_c_string(V)
(If necessary) NULL terminate a vector containing a c-string.
Definition: vec.h:1132
quic_sendable_packet_count
static int quic_sendable_packet_count(session_t *udp_session)
Definition: quic.c:479
QUIC_CONN_STATE_READY
@ QUIC_CONN_STATE_READY
Definition: quic.h:113
quic_get_transport_listener_endpoint
static void quic_get_transport_listener_endpoint(u32 listener_index, transport_endpoint_t *tep, u8 is_lcl)
Definition: quic.c:2394
session.h
quic_init_crypto_context
static int quic_init_crypto_context(crypto_context_t *crctx, quic_ctx_t *ctx)
Definition: quic.c:228
quic_release_crypto_context
static void quic_release_crypto_context(u32 crypto_context_index, u8 thread_index)
Definition: quic.c:219
i
int i
Definition: flowhash_template.h:376
quic_list_crypto_context_command_fn
static clib_error_t * quic_list_crypto_context_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: quic.c:144
svm_fifo_reset_has_deq_ntf
static void svm_fifo_reset_has_deq_ntf(svm_fifo_t *f)
Clear has notification flag.
Definition: svm_fifo.h:809
vlib_node_t::error_heap_index
u32 error_heap_index
Definition: node.h:315
quic_acquire_crypto_context
static int quic_acquire_crypto_context(quic_ctx_t *ctx)
Definition: quic.c:332
clib_warning
#define clib_warning(format, args...)
Definition: error.h:59
quic_udp_session_rx_callback
static int quic_udp_session_rx_callback(session_t *udp_session)
Definition: quic.c:2263
quic_rx_packet_ctx_::ph
session_dgram_hdr_t ph
Definition: quic.h:241
quic_encrypt_ticket_cb
int quic_encrypt_ticket_cb(ptls_encrypt_ticket_t *_self, ptls_t *tls, int is_encrypt, ptls_buffer_t *dst, ptls_iovec_t src)
Definition: quic_crypto.c:447
quic_rx_packet_ctx_::ctx_index
u32 ctx_index
Definition: quic.h:232
quic_set_max_packets_per_key
static vlib_cli_command_t quic_set_max_packets_per_key
(constructor) VLIB_CLI_COMMAND (quic_set_max_packets_per_key)
Definition: quic.c:2928
QUIC_CONN_STATE_ACTIVE_CLOSING
@ QUIC_CONN_STATE_ACTIVE_CLOSING
Definition: quic.h:117
transport_endpt_crypto_cfg_
Definition: transport_types.h:273
quic_ctx_is_stream
static int quic_ctx_is_stream(quic_ctx_t *ctx)
Definition: quic.c:442
VLIB_PLUGIN_REGISTER
VLIB_PLUGIN_REGISTER()
app_cert_key_pair_get_if_valid
app_cert_key_pair_t * app_cert_key_pair_get_if_valid(u32 index)
Definition: application.c:2016
session_::flags
u32 flags
Session flags.
Definition: session_types.h:197
rv
int __clib_unused rv
Definition: application.c:491
QUIC_SESSION_INVALID
#define QUIC_SESSION_INVALID
Definition: quic.h:40
session_dgram_header_::lcl_ip
ip46_address_t lcl_ip
Definition: session_types.h:442
quic_process_one_rx_packet
static int quic_process_one_rx_packet(u64 udp_session_handle, svm_fifo_t *f, u32 fifo_offset, quic_rx_packet_ctx_t *pctx)
Definition: quic.c:2184
quic_add_segment_callback
static int quic_add_segment_callback(u32 client_index, u64 seg_handle)
Definition: quic.c:1939
QUIC_PACKET_TYPE_DROP
@ QUIC_PACKET_TYPE_DROP
Definition: quic.h:127
certificate_::cert
u8 * cert
Definition: application_interface.h:29
vlib_time_now
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:327
quic_main_::per_thread_crypto_key_indices
u32 * per_thread_crypto_key_indices
Definition: quic.h:266
vlib_main
int vlib_main(vlib_main_t *volatile vm, unformat_input_t *input)
Definition: main.c:1914
quic_fifo_egress_shift
void quic_fifo_egress_shift(quicly_stream_t *stream, size_t delta)
Definition: quic.c:907
vnet_app_attach_args_t
struct _vnet_app_attach_args_t vnet_app_attach_args_t
app_worker_::app_index
u32 app_index
Index of owning app.
Definition: application.h:43
quic_ctx_::quic_connection_ctx_id
u32 quic_connection_ctx_id
Definition: quic.h:163
vlib_node_runtime_t
Definition: node.h:454
quicly_vpp_now_cb
static quicly_now_t quicly_vpp_now_cb
Definition: quic.c:55
session_cli_return_if_not_enabled
#define session_cli_return_if_not_enabled()
Definition: session.h:728
quic_ctx_get
static quic_ctx_t * quic_ctx_get(u32 ctx_index, u32 thread_index)
Definition: quic.c:413
vlib_cli_command_t
Definition: cli.h:92
session_transport_reset_notify
void session_transport_reset_notify(transport_connection_t *tc)
Notify application that connection has been reset.
Definition: session.c:1187
PREDICT_TRUE
#define PREDICT_TRUE(x)
Definition: clib.h:125
vlib_get_thread_main
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:56
crypto_ctx_::ckpair_index
u32 ckpair_index
certificate & key
Definition: application_interface.h:197
quic_main_::udp_fifo_size
u32 udp_fifo_size
Definition: quic.h:261
svm_fifo_max_dequeue_cons
static u32 svm_fifo_max_dequeue_cons(svm_fifo_t *f)
Fifo max bytes to dequeue optimized for consumer.
Definition: svm_fifo.h:487
quic_rx_packet_ctx_
Definition: quic.h:228
svm_fifo_add_want_deq_ntf
static void svm_fifo_add_want_deq_ntf(svm_fifo_t *f, u8 ntf_type)
Set specific want notification flag.
Definition: svm_fifo.h:760
app_worker_accept_notify
int app_worker_accept_notify(app_worker_t *app_wrk, session_t *s)
Definition: application_worker.c:351
quic_update_time
static void quic_update_time(f64 now, u8 thread_index)
Definition: quic.c:1099
app_listener_get_session
session_t * app_listener_get_session(app_listener_t *al)
Definition: application.c:306
session_alloc
session_t * session_alloc(u32 thread_index)
Definition: session.c:201
session_cleanup_ntf_t
session_cleanup_ntf_t
Definition: session_types.h:113
session_send_io_evt_to_thread
int session_send_io_evt_to_thread(svm_fifo_t *f, session_evt_type_t evt_type)
Definition: session.c:84
session_::session_state
volatile u8 session_state
State in session layer state machine.
Definition: session_types.h:185
session_dgram_header_::is_ip4
u8 is_ip4
Definition: session_types.h:445
quic_update_timer
static void quic_update_timer(quic_ctx_t *ctx)
Definition: quic.c:1120
quic_proto_on_close
static void quic_proto_on_close(u32 ctx_index, u32 thread_index)
Definition: quic.c:1381
session_::connection_index
u32 connection_index
Index of the transport connection associated to the session.
Definition: session_types.h:200
clib_mem_alloc
static void * clib_mem_alloc(uword size)
Definition: mem.h:256
CRYPTO_ENGINE_NONE
@ CRYPTO_ENGINE_NONE
Definition: application_interface.h:176
quic_connection_get
static transport_connection_t * quic_connection_get(u32 ctx_index, u32 thread_index)
Definition: quic.c:1530
quic_get_counter_value
static u64 quic_get_counter_value(u32 event_code)
Definition: quic.c:2651
vnet_app_add_cert_key_interest
int vnet_app_add_cert_key_interest(u32 index, u32 app_index)
Ask for app cb on pair deletion.
Definition: application.c:2049
QUIC_ERROR_FULL_FIFO
#define QUIC_ERROR_FULL_FIFO
Definition: quic.h:64
quic_list_crypto_context_command
static vlib_cli_command_t quic_list_crypto_context_command
(constructor) VLIB_CLI_COMMAND (quic_list_crypto_context_command)
Definition: quic.c:2922
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
listen_session_get_from_handle
static session_t * listen_session_get_from_handle(session_handle_t handle)
Definition: session.h:631
certificate_::cert_key_index
u32 cert_key_index
Definition: application_interface.h:27
quic_del_segment_callback
static int quic_del_segment_callback(u32 client_index, u64 seg_handle)
Definition: quic.c:1946
QUIC_APP_ERROR_CLOSE_NOTIFY
#define QUIC_APP_ERROR_CLOSE_NOTIFY
Definition: quic.h:65
session_dgram_header_::rmt_ip
ip46_address_t rmt_ip
Definition: session_types.h:441
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137
svm_fifo_max_dequeue
static u32 svm_fifo_max_dequeue(svm_fifo_t *f)
Fifo max bytes to dequeue.
Definition: svm_fifo.h:516
quic_main_::connection_hash
clib_bihash_16_8_t connection_hash
quic connection id -> conn handle
Definition: quic.h:249
application.h
packets
units packets
Definition: map.api:366
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
quic_crypto_decrypt_packet
void quic_crypto_decrypt_packet(quic_ctx_t *qctx, quic_rx_packet_ctx_t *pctx)
Definition: quic_crypto.c:179
app_listener_
Definition: application.h:79