FD.io VPP  v19.08.1-401-g8e4ed521a
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 
44 /* Taken from quicly.c */
45 #define QUICLY_QUIC_BIT 0x40
46 
47 #define QUICLY_PACKET_TYPE_INITIAL (QUICLY_LONG_HEADER_BIT | QUICLY_QUIC_BIT | 0)
48 #define QUICLY_PACKET_TYPE_0RTT (QUICLY_LONG_HEADER_BIT | QUICLY_QUIC_BIT | 0x10)
49 #define QUICLY_PACKET_TYPE_HANDSHAKE (QUICLY_LONG_HEADER_BIT | QUICLY_QUIC_BIT | 0x20)
50 #define QUICLY_PACKET_TYPE_RETRY (QUICLY_LONG_HEADER_BIT | QUICLY_QUIC_BIT | 0x30)
51 #define QUICLY_PACKET_TYPE_BITMASK 0xf0
52 
53 /* error codes */
54 #define QUIC_ERROR_FULL_FIFO 0xff10
55 #define QUIC_APP_ERROR_CLOSE_NOTIFY QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(0)
56 #define QUIC_APP_ALLOCATION_ERROR QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(0x1)
57 #define QUIC_APP_ACCEPT_NOTIFY_ERROR QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(0x2)
58 #define QUIC_APP_CONNECT_NOTIFY_ERROR QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(0x3)
59 
60 #if QUIC_DEBUG
61 #define QUIC_DBG(_lvl, _fmt, _args...) \
62  if (_lvl <= QUIC_DEBUG) \
63  clib_warning (_fmt, ##_args)
64 #else
65 #define QUIC_DBG(_lvl, _fmt, _args...)
66 #endif
67 
69 
70 typedef enum
71 {
72 #define quic_error(n,s) QUIC_ERROR_##n,
74 #undef quic_error
76 } quic_error_t;
77 
79 {
88 
89 
90 typedef enum quic_ctx_flags_
91 {
92  QUIC_F_IS_STREAM = (1 << 0),
93  QUIC_F_IS_LISTENER = (1 << 1),
95 
96 /* This structure is used to implement the concept of VPP connection for QUIC.
97  * We create one per connection and one per stream. */
98 typedef struct quic_ctx_
99 {
100  union
101  {
103  struct
104  { /** QUIC ctx case */
105  quicly_conn_t *conn;
111  u8 _qctx_end_marker; /* Leave this at the end */
112  };
113  struct
114  { /** STREAM ctx case */
115  quicly_stream_t *stream;
117  u8 _sctx_end_marker; /* Leave this at the end */
118  };
119  };
125 } quic_ctx_t;
126 
127 /* Make sure our custom fields don't overlap with the fields we use in
128  .connection
129 */
130 STATIC_ASSERT (offsetof (quic_ctx_t, _qctx_end_marker) <=
132  "connection data must be less than TRANSPORT_CONN_ID_LEN bytes");
133 STATIC_ASSERT (offsetof (quic_ctx_t, _sctx_end_marker) <=
135  "connection data must be less than TRANSPORT_CONN_ID_LEN bytes");
136 
138 {
142 
143 /* single-entry session cache */
144 typedef struct quic_session_cache_
145 {
146  ptls_encrypt_ticket_t super;
147  uint8_t id[32];
148  ptls_iovec_t data;
150 
151 typedef struct quic_stream_data_
152 {
155  u32 app_rx_data_len; /* bytes received, to be read by external app */
157 
158 typedef struct quic_worker_ctx_
159 {
160  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
161  int64_t time_now; /**< worker time */
162  tw_timer_wheel_1t_3w_1024sl_ov_t timer_wheel; /**< worker timer wheel */
165 
166 typedef struct quic_main_
167 {
171  clib_bihash_16_8_t connection_hash; /* quic connection id -> conn handle */
173 
174  ptls_cipher_suite_t ***quic_ciphers; /* available ciphers by crypto engine */
177 
178  /*
179  * Config
180  */
181  quicly_context_t quicly_ctx;
182  ptls_handshake_properties_t hs_properties;
183  quicly_cid_plaintext_t next_cid;
184 
187 } quic_main_t;
188 
189 #endif /* __included_quic_h__ */
190 
191 /*
192  * fd.io coding-style-patch-verification: ON
193  *
194  * Local Variables:
195  * eval: (c-set-style "gnu")
196  * End:
197  */
u64 udp_fifo_size
Definition: quic.h:185
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
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:170
quicly_stream_t * stream
STREAM ctx case.
Definition: quic.h:115
quicly_cid_plaintext_t next_cid
Definition: quic.h:183
u8 default_cipher
Definition: quic.h:175
unsigned long u64
Definition: types.h:89
u32 parent_app_wrk_id
Definition: quic.h:122
u32 timer_handle
Definition: quic.h:121
int64_t time_now
worker time
Definition: quic.h:161
clib_bihash_16_8_t connection_hash
Definition: quic.h:171
u32 client_opaque
Definition: quic.h:107
struct quic_ctx_ quic_ctx_t
struct quic_worker_ctx_ quic_worker_ctx_t
f64 tstamp_ticks_per_clock
Definition: quic.h:172
unsigned char u8
Definition: types.h:56
double f64
Definition: types.h:142
quic_crypto_engine_
Definition: quic.h:137
unsigned int u32
Definition: types.h:88
ptls_handshake_properties_t hs_properties
Definition: quic.h:182
u32 parent_app_id
Definition: quic.h:123
u32 app_index
Definition: quic.h:168
Definition: quic.h:98
u8 conn_state
Definition: quic.h:109
u32 app_rx_data_len
Definition: quic.h:155
quic_ctx_conn_state_
Definition: quic.h:78
u32 thread_index
Definition: quic.h:154
ptls_iovec_t data
Definition: quic.h:148
quicly_conn_t * conn
QUIC ctx case.
Definition: quic.h:105
transport_connection_t connection
Definition: quic.h:102
ptls_cipher_suite_t *** quic_ciphers
Definition: quic.h:174
quicly_context_t quicly_ctx
Definition: quic.h:181
ptls_encrypt_ticket_t super
Definition: quic.h:146
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
tw_timer_wheel_1t_3w_1024sl_ov_t timer_wheel
worker timer wheel
Definition: quic.h:162
u32 quic_connection_ctx_id
Definition: quic.h:116
session_handle_t udp_session_handle
Definition: quic.h:120
quic_ctx_flags_
Definition: quic.h:90
u8 flags
Definition: quic.h:124
u32 * opening_ctx_pool
Definition: quic.h:163
struct _vlib_node_registration vlib_node_registration_t
u8 * srv_hostname
Definition: quic.h:108
u64 session_handle_t
quic_error_t
Definition: quic.h:70
struct quic_stream_data_ quic_stream_data_t
vlib_node_registration_t quic_input_node
(constructor) VLIB_REGISTER_NODE (quic_input_node)
Definition: quic.c:2454
enum quic_crypto_engine_ quic_crypto_engine_t
u8 udp_is_ip4
Definition: quic.h:110
quic_session_cache_t session_cache
Definition: quic.h:176
quic_ctx_t ** ctx_pool
Definition: quic.h:169
enum quic_ctx_flags_ quic_ctx_flags_t
u64 udp_fifo_prealloc
Definition: quic.h:186
u32 listener_ctx_id
Definition: quic.h:106