FD.io VPP  v19.08-27-gf4dcae4
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_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 {
78 
79 
80 typedef enum quic_ctx_flags_
81 {
82  QUIC_F_IS_STREAM = (1 << 0),
83  QUIC_F_IS_LISTENER = (1 << 1),
85 
86 /* This structure is used to implement the concept of VPP connection for QUIC.
87  * We create one per connection and one per stream. */
88 typedef struct quic_ctx_
89 {
90  union
91  {
93  struct
94  { /** QUIC ctx case */
95  quicly_conn_t *conn;
101  u8 _qctx_end_marker; /* Leave this at the end */
102  };
103  struct
104  { /** STREAM ctx case */
105  quicly_stream_t *stream;
107  u8 _sctx_end_marker; /* Leave this at the end */
108  };
109  };
115 } quic_ctx_t;
116 
117 /* Make sure our custom fields don't overlap with the fields we use in
118  .connection
119 */
120 STATIC_ASSERT (offsetof (quic_ctx_t, _qctx_end_marker) <=
122  "connection data must be less than TRANSPORT_CONN_ID_LEN bytes");
123 STATIC_ASSERT (offsetof (quic_ctx_t, _sctx_end_marker) <=
125  "connection data must be less than TRANSPORT_CONN_ID_LEN bytes");
126 
128 {
132 
133 /* single-entry session cache */
134 typedef struct quic_session_cache_
135 {
136  ptls_encrypt_ticket_t super;
137  uint8_t id[32];
138  ptls_iovec_t data;
140 
141 typedef struct quic_stream_data_
142 {
145  u32 app_rx_data_len; /* bytes received, to be read by external app */
147 
148 typedef struct quic_worker_ctx_
149 {
150  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
151  int64_t time_now; /**< worker time */
152  tw_timer_wheel_1t_3w_1024sl_ov_t timer_wheel; /**< worker timer wheel */
155 
156 typedef struct quic_main_
157 {
161  clib_bihash_16_8_t connection_hash; /* quicly connection id -> conn handle */
163 
164  ptls_cipher_suite_t ***quic_ciphers; /* available ciphers by crypto engine */
167 
168  /*
169  * Config
170  */
171  quicly_context_t quicly_ctx;
172  ptls_handshake_properties_t hs_properties;
173  quicly_cid_plaintext_t next_cid;
174 } quic_main_t;
175 
176 #endif /* __included_quic_h__ */
177 
178 /*
179  * fd.io coding-style-patch-verification: ON
180  *
181  * Local Variables:
182  * eval: (c-set-style "gnu")
183  * End:
184  */
#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:160
quicly_stream_t * stream
STREAM ctx case.
Definition: quic.h:105
quicly_cid_plaintext_t next_cid
Definition: quic.h:173
u8 default_cipher
Definition: quic.h:165
u32 parent_app_wrk_id
Definition: quic.h:112
u32 timer_handle
Definition: quic.h:111
int64_t time_now
worker time
Definition: quic.h:151
clib_bihash_16_8_t connection_hash
Definition: quic.h:161
u32 client_opaque
Definition: quic.h:97
struct quic_ctx_ quic_ctx_t
struct quic_worker_ctx_ quic_worker_ctx_t
f64 tstamp_ticks_per_clock
Definition: quic.h:162
unsigned char u8
Definition: types.h:56
double f64
Definition: types.h:142
quic_crypto_engine_
Definition: quic.h:127
unsigned int u32
Definition: types.h:88
ptls_handshake_properties_t hs_properties
Definition: quic.h:172
u32 parent_app_id
Definition: quic.h:113
u32 app_index
Definition: quic.h:158
Definition: quic.h:88
u8 conn_state
Definition: quic.h:99
u32 app_rx_data_len
Definition: quic.h:145
quic_ctx_conn_state_
Definition: quic.h:68
u32 thread_index
Definition: quic.h:144
ptls_iovec_t data
Definition: quic.h:138
quicly_conn_t * conn
QUIC ctx case.
Definition: quic.h:95
transport_connection_t connection
Definition: quic.h:92
ptls_cipher_suite_t *** quic_ciphers
Definition: quic.h:164
quicly_context_t quicly_ctx
Definition: quic.h:171
ptls_encrypt_ticket_t super
Definition: quic.h:136
struct quic_main_ quic_main_t
struct _transport_connection transport_connection_t
#define TRANSPORT_CONN_ID_LEN
tw_timer_wheel_1t_3w_1024sl_ov_t timer_wheel
worker timer wheel
Definition: quic.h:152
u32 quic_connection_ctx_id
Definition: quic.h:106
session_handle_t udp_session_handle
Definition: quic.h:110
quic_ctx_flags_
Definition: quic.h:80
u8 flags
Definition: quic.h:114
u32 * opening_ctx_pool
Definition: quic.h:153
u8 * srv_hostname
Definition: quic.h:98
u64 session_handle_t
struct quic_stream_data_ quic_stream_data_t
enum quic_crypto_engine_ quic_crypto_engine_t
u8 udp_is_ip4
Definition: quic.h:100
STATIC_ASSERT(offsetof(quic_ctx_t, _qctx_end_marker)<=TRANSPORT_CONN_ID_LEN,"connection data must be less than TRANSPORT_CONN_ID_LEN bytes")
quic_session_cache_t session_cache
Definition: quic.h:166
quic_ctx_t ** ctx_pool
Definition: quic.h:159
enum quic_ctx_flags_ quic_ctx_flags_t
u32 listener_ctx_id
Definition: quic.h:96