quic: Add Tx, Rx and packet drop counters
[vpp.git] / src / plugins / quic / quic.h
index 80f2664..777820e 100644 (file)
 #define QUIC_DBG(_lvl, _fmt, _args...)
 #endif
 
+extern vlib_node_registration_t quic_input_node;
+
+typedef enum
+{
+#define quic_error(n,s) QUIC_ERROR_##n,
+#include <plugins/quic/quic_error.def>
+#undef quic_error
+  QUIC_N_ERROR,
+} quic_error_t;
+
 typedef enum quic_ctx_conn_state_
 {
   QUIC_CONN_STATE_OPENED,
   QUIC_CONN_STATE_HANDSHAKE,
   QUIC_CONN_STATE_READY,
   QUIC_CONN_STATE_PASSIVE_CLOSING,
+  QUIC_CONN_STATE_PASSIVE_CLOSING_APP_CLOSED,
+  QUIC_CONN_STATE_PASSIVE_CLOSING_QUIC_CLOSED,
+  QUIC_CONN_STATE_ACTIVE_CLOSING,
 } quic_ctx_conn_state_t;
 
 
@@ -80,37 +93,30 @@ typedef enum quic_ctx_flags_
   QUIC_F_IS_LISTENER = (1 << 1),
 } quic_ctx_flags_t;
 
-/* *INDENT-OFF* */
-typedef struct quic_ctx_id_
+/* This structure is used to implement the concept of VPP connection for QUIC.
+ * We create one per connection and one per stream. */
+typedef struct quic_ctx_
 {
-  union { /** QUIC ctx case */
-    struct {
+  union
+  {
+    transport_connection_t connection;
+    struct
+    {        /** QUIC ctx case */
       quicly_conn_t *conn;
       u32 listener_ctx_id;
       u32 client_opaque;
       u8 *srv_hostname;
       u8 conn_state;
       u8 udp_is_ip4;
+      u8 _qctx_end_marker;     /* Leave this at the end */
     };
-    struct { /** STREAM ctx case */
+    struct
+    {        /** STREAM ctx case */
       quicly_stream_t *stream;
       u32 quic_connection_ctx_id;
+      u8 _sctx_end_marker;     /* Leave this at the end */
     };
   };
-} quic_ctx_id_t;
-/* *INDENT-ON* */
-
-STATIC_ASSERT (sizeof (quic_ctx_id_t) <= 42, "ctx id must be less than 42");
-
-/* This structure is used to implement the concept of VPP connection for QUIC.
- * We create one per connection and one per stream. */
-typedef struct quic_ctx_
-{
-  union
-  {
-    transport_connection_t connection;
-    quic_ctx_id_t c_quic_ctx_id;
-  };
   session_handle_t udp_session_handle;
   u32 timer_handle;
   u32 parent_app_wrk_id;
@@ -118,6 +124,30 @@ typedef struct quic_ctx_
   u8 flags;
 } quic_ctx_t;
 
+/* Make sure our custom fields don't overlap with the fields we use in
+   .connection
+*/
+STATIC_ASSERT (offsetof (quic_ctx_t, _qctx_end_marker) <=
+              TRANSPORT_CONN_ID_LEN,
+              "connection data must be less than TRANSPORT_CONN_ID_LEN bytes");
+STATIC_ASSERT (offsetof (quic_ctx_t, _sctx_end_marker) <=
+              TRANSPORT_CONN_ID_LEN,
+              "connection data must be less than TRANSPORT_CONN_ID_LEN bytes");
+
+typedef enum quic_crypto_engine_
+{
+  CRYPTO_ENGINE_VPP,
+  CRYPTO_ENGINE_PICOTLS,
+} quic_crypto_engine_t;
+
+/* single-entry session cache */
+typedef struct quic_session_cache_
+{
+  ptls_encrypt_ticket_t super;
+  uint8_t id[32];
+  ptls_iovec_t data;
+} quic_session_cache_t;
+
 typedef struct quic_stream_data_
 {
   u32 ctx_id;
@@ -138,9 +168,13 @@ typedef struct quic_main_
   u32 app_index;
   quic_ctx_t **ctx_pool;
   quic_worker_ctx_t *wrk_ctx;
-  clib_bihash_16_8_t connection_hash;  /* quicly connection id -> conn handle */
+  clib_bihash_16_8_t connection_hash;  /* quic connection id -> conn handle */
   f64 tstamp_ticks_per_clock;
 
+  ptls_cipher_suite_t ***quic_ciphers; /* available ciphers by crypto engine */
+  u8 default_cipher;
+  quic_session_cache_t session_cache;
+
   /*
    * Config
    */