FD.io VPP  v20.01-48-g3e0dafb74
Vector Packet Processing
quic.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 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 #ifndef __included_quic_h__
17 #define __included_quic_h__
18 
20 
21 #include <vppinfra/lock.h>
23 #include <vppinfra/bihash_16_8.h>
24 
25 #include <quicly.h>
26 
27 /* QUIC log levels
28  * 1 - errors
29  * 2 - connection/stream events
30  * 3 - packet events
31  * 4 - timer events
32  **/
33 
34 #define QUIC_DEBUG 0
35 #define QUIC_TSTAMP_RESOLUTION 0.001 /* QUIC tick resolution (1ms) */
36 #define QUIC_TIMER_HANDLE_INVALID ((u32) ~0)
37 #define QUIC_SESSION_INVALID ((u32) ~0 - 1)
38 #define QUIC_MAX_PACKET_SIZE 1280
39 
40 #define QUIC_INT_MAX 0x3FFFFFFFFFFFFFFF
41 #define QUIC_DEFAULT_FIFO_SIZE (64 << 10)
42 #define QUIC_SEND_PACKET_VEC_SIZE 16
43 #define QUIC_IV_LEN 17
44 
45 #define QUIC_SEND_MAX_BATCH_PACKETS 16
46 #define QUIC_RCV_MAX_BATCH_PACKETS 16
47 #define QUIC_DEFAULT_CONN_TIMEOUT (30 * 1000) /* 30 seconds */
48 
49 /* Taken from quicly.c */
50 #define QUICLY_QUIC_BIT 0x40
51 
52 #define QUICLY_PACKET_TYPE_INITIAL (QUICLY_LONG_HEADER_BIT | QUICLY_QUIC_BIT | 0)
53 #define QUICLY_PACKET_TYPE_0RTT (QUICLY_LONG_HEADER_BIT | QUICLY_QUIC_BIT | 0x10)
54 #define QUICLY_PACKET_TYPE_HANDSHAKE (QUICLY_LONG_HEADER_BIT | QUICLY_QUIC_BIT | 0x20)
55 #define QUICLY_PACKET_TYPE_RETRY (QUICLY_LONG_HEADER_BIT | QUICLY_QUIC_BIT | 0x30)
56 #define QUICLY_PACKET_TYPE_BITMASK 0xf0
57 
58 /* error codes */
59 #define QUIC_ERROR_FULL_FIFO 0xff10
60 #define QUIC_APP_ERROR_CLOSE_NOTIFY QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(0)
61 #define QUIC_APP_ALLOCATION_ERROR QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(0x1)
62 #define QUIC_APP_ACCEPT_NOTIFY_ERROR QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(0x2)
63 #define QUIC_APP_CONNECT_NOTIFY_ERROR QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(0x3)
64 
65 #if QUIC_DEBUG
66 #define QUIC_DBG(_lvl, _fmt, _args...) \
67  if (_lvl <= QUIC_DEBUG) \
68  clib_warning (_fmt, ##_args)
69 #else
70 #define QUIC_DBG(_lvl, _fmt, _args...)
71 #endif
72 
73 #if CLIB_ASSERT_ENABLE
74 #define QUIC_ASSERT(truth) ASSERT (truth)
75 #else
76 #define QUIC_ASSERT(truth) \
77  do { \
78  if (PREDICT_FALSE (! (truth))) \
79  QUIC_ERR ("ASSERT(%s) failed", # truth); \
80  } while (0)
81 #endif
82 
83 #define QUIC_ERR(_fmt, _args...) \
84  do { \
85  clib_warning ("QUIC-ERR: " _fmt, ##_args); \
86  } while (0)
87 
88 
89 
91 
92 typedef enum
93 {
94 #define quic_error(n,s) QUIC_ERROR_##n,
96 #undef quic_error
98 } quic_error_t;
99 
101 {
110 
111 typedef enum quic_packet_type_
112 {
120 
121 typedef enum quic_ctx_flags_
122 {
123  QUIC_F_IS_STREAM = (1 << 0),
124  QUIC_F_IS_LISTENER = (1 << 1),
126 
127 /* This structure is used to implement the concept of VPP connection for QUIC.
128  * We create one per connection and one per stream. */
129 typedef struct quic_ctx_
130 {
131  union
132  {
134  struct
135  { /** QUIC ctx case */
136  quicly_conn_t *conn;
142  u8 _qctx_end_marker; /* Leave this at the end */
143  };
144  struct
145  { /** STREAM ctx case */
146  quicly_stream_t *stream;
148  u8 _sctx_end_marker; /* Leave this at the end */
149  };
150  };
159 } quic_ctx_t;
160 
161 /* Make sure our custom fields don't overlap with the fields we use in
162  .connection
163 */
164 STATIC_ASSERT (offsetof (quic_ctx_t, _qctx_end_marker) <=
166  "connection data must be less than TRANSPORT_CONN_ID_LEN bytes");
167 STATIC_ASSERT (offsetof (quic_ctx_t, _sctx_end_marker) <=
169  "connection data must be less than TRANSPORT_CONN_ID_LEN bytes");
170 
171 /* single-entry session cache */
172 typedef struct quic_session_cache_
173 {
174  ptls_encrypt_ticket_t super;
175  uint8_t id[32];
176  ptls_iovec_t data;
178 
179 typedef struct quic_stream_data_
180 {
183  u32 app_rx_data_len; /**< bytes received, to be read by external app */
184  u32 app_tx_data_len; /**< bytes sent */
186 
188 {
189  quicly_context_t quicly_ctx;
190  char cid_key[QUIC_IV_LEN];
191  ptls_context_t ptls_ctx;
193 
194 typedef struct quic_worker_ctx_
195 {
196  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
197  int64_t time_now; /**< worker time */
198  tw_timer_wheel_1t_3w_1024sl_ov_t timer_wheel; /**< worker timer wheel */
199  quicly_cid_plaintext_t next_cid;
200  crypto_context_t *crypto_ctx_pool; /**< per thread pool of crypto contexes */
201  clib_bihash_24_8_t crypto_context_hash; /**< per thread [params:crypto_ctx_index] hash */
203 
204 typedef struct quic_rx_packet_ctx_
205 {
206  quicly_decoded_packet_t packet;
210  union
211  {
212  struct sockaddr sa;
213  struct sockaddr_in6 sa6;
214  };
215  socklen_t salen;
219 
220 typedef struct quic_main_
221 {
225  clib_bihash_16_8_t connection_hash; /**< quic connection id -> conn handle */
227 
228  ptls_cipher_suite_t ***quic_ciphers; /**< available ciphers by crypto engine */
229  uword *available_crypto_engines; /**< Bitmap for registered engines */
230  u8 default_crypto_engine; /**< Used if you do connect with CRYPTO_ENGINE_NONE (0) */
231 
232  ptls_handshake_properties_t hs_properties;
234 
238 } quic_main_t;
239 
240 #endif /* __included_quic_h__ */
241 
242 /*
243  * fd.io coding-style-patch-verification: ON
244  *
245  * Local Variables:
246  * eval: (c-set-style "gnu")
247  * End:
248  */
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
uword * available_crypto_engines
Bitmap for registered engines.
Definition: quic.h:229
ptls_context_t ptls_ctx
Definition: quic.h:191
struct quic_session_cache_ quic_session_cache_t
enum quic_ctx_conn_state_ quic_ctx_conn_state_t
quic_worker_ctx_t * wrk_ctx
Definition: quic.h:224
quicly_stream_t * stream
STREAM ctx case.
Definition: quic.h:146
quic_packet_type_
Definition: quic.h:111
u32 parent_app_wrk_id
Definition: quic.h:153
u32 timer_handle
Definition: quic.h:152
int64_t time_now
worker time
Definition: quic.h:197
clib_bihash_16_8_t connection_hash
quic connection id -> conn handle
Definition: quic.h:225
u32 client_opaque
Definition: quic.h:138
struct quic_ctx_ quic_ctx_t
struct quic_worker_ctx_ quic_worker_ctx_t
f64 tstamp_ticks_per_clock
Definition: quic.h:226
unsigned char u8
Definition: types.h:56
double f64
Definition: types.h:142
session_dgram_hdr_t ph
Definition: quic.h:217
u8 default_crypto_engine
Used if you do connect with CRYPTO_ENGINE_NONE (0)
Definition: quic.h:230
unsigned int u32
Definition: types.h:88
ptls_handshake_properties_t hs_properties
Definition: quic.h:232
#define QUIC_MAX_PACKET_SIZE
Definition: quic.h:38
#define QUIC_IV_LEN
Definition: quic.h:43
u32 parent_app_id
Definition: quic.h:154
u32 app_index
Definition: quic.h:222
clib_bihash_24_8_t crypto_context_hash
per thread [params:crypto_ctx_index] hash
Definition: quic.h:201
u8 conn_state
Definition: quic.h:140
struct quic_rx_packet_ctx_ quic_rx_packet_ctx_t
u32 app_rx_data_len
bytes received, to be read by external app
Definition: quic.h:183
struct quic_crypto_context_data_ quic_crypto_context_data_t
quic_ctx_conn_state_
Definition: quic.h:100
u32 thread_index
Definition: quic.h:182
ptls_iovec_t data
Definition: quic.h:176
quicly_conn_t * conn
QUIC ctx case.
Definition: quic.h:136
transport_connection_t connection
Definition: quic.h:133
u32 ckpair_index
Definition: quic.h:155
ptls_cipher_suite_t *** quic_ciphers
available ciphers by crypto engine
Definition: quic.h:228
ptls_encrypt_ticket_t super
Definition: quic.h:174
struct quic_main_ quic_main_t
struct _transport_connection transport_connection_t
STATIC_ASSERT(offsetof(quic_ctx_t, _qctx_end_marker)<=TRANSPORT_CONN_ID_LEN, "connection data must be less than TRANSPORT_CONN_ID_LEN bytes")
#define TRANSPORT_CONN_ID_LEN
crypto_context_t * crypto_ctx_pool
per thread pool of crypto contexes
Definition: quic.h:200
socklen_t salen
Definition: quic.h:215
tw_timer_wheel_1t_3w_1024sl_ov_t timer_wheel
worker timer wheel
Definition: quic.h:198
u32 quic_connection_ctx_id
Definition: quic.h:147
u8 data[128]
Definition: ipsec_types.api:87
u32 udp_fifo_prealloc
Definition: quic.h:236
session_handle_t udp_session_handle
Definition: quic.h:151
quic_ctx_flags_
Definition: quic.h:121
enum quic_packet_type_ quic_packet_type_t
u8 flags
Definition: quic.h:158
struct _vlib_node_registration vlib_node_registration_t
u32 crypto_context_index
Definition: quic.h:157
u8 * srv_hostname
Definition: quic.h:139
quicly_context_t quicly_ctx
Definition: quic.h:189
u64 session_handle_t
quic_error_t
Definition: quic.h:92
struct quic_stream_data_ quic_stream_data_t
quicly_decoded_packet_t packet
Definition: quic.h:206
vlib_node_registration_t quic_input_node
(constructor) VLIB_REGISTER_NODE (quic_input_node)
Definition: quic.c:2815
u64 uword
Definition: types.h:112
u8 udp_is_ip4
Definition: quic.h:141
quic_session_cache_t session_cache
Definition: quic.h:233
quic_ctx_t ** ctx_pool
Definition: quic.h:223
u32 connection_timeout
Definition: quic.h:237
quicly_cid_plaintext_t next_cid
Definition: quic.h:199
u32 app_tx_data_len
bytes sent
Definition: quic.h:184
u32 udp_fifo_size
Definition: quic.h:235
enum quic_ctx_flags_ quic_ctx_flags_t
u32 crypto_engine
Definition: quic.h:156
u32 listener_ctx_id
Definition: quic.h:137