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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef __included_quic_h__
17 #define __included_quic_h__
19 #include <vnet/session/application_interface.h>
21 #include <vppinfra/lock.h>
22 #include <vppinfra/tw_timer_1t_3w_1024sl_ov.h>
23 #include <vppinfra/bihash_16_8.h>
29 * 2 - connection/stream events
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
40 #define QUIC_INT_MAX 0x3FFFFFFFFFFFFFFF
41 #define QUIC_DEFAULT_FIFO_SIZE (64 << 10)
42 #define QUIC_SEND_PACKET_VEC_SIZE 16
44 #define QUIC_SEND_MAX_BATCH_PACKETS 16
45 #define QUIC_RCV_MAX_BATCH_PACKETS 16
47 /* Taken from quicly.c */
48 #define QUICLY_QUIC_BIT 0x40
50 #define QUICLY_PACKET_TYPE_INITIAL (QUICLY_LONG_HEADER_BIT | QUICLY_QUIC_BIT | 0)
51 #define QUICLY_PACKET_TYPE_0RTT (QUICLY_LONG_HEADER_BIT | QUICLY_QUIC_BIT | 0x10)
52 #define QUICLY_PACKET_TYPE_HANDSHAKE (QUICLY_LONG_HEADER_BIT | QUICLY_QUIC_BIT | 0x20)
53 #define QUICLY_PACKET_TYPE_RETRY (QUICLY_LONG_HEADER_BIT | QUICLY_QUIC_BIT | 0x30)
54 #define QUICLY_PACKET_TYPE_BITMASK 0xf0
57 #define QUIC_ERROR_FULL_FIFO 0xff10
58 #define QUIC_APP_ERROR_CLOSE_NOTIFY QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(0)
59 #define QUIC_APP_ALLOCATION_ERROR QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(0x1)
60 #define QUIC_APP_ACCEPT_NOTIFY_ERROR QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(0x2)
61 #define QUIC_APP_CONNECT_NOTIFY_ERROR QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(0x3)
64 #define QUIC_DBG(_lvl, _fmt, _args...) \
65 if (_lvl <= QUIC_DEBUG) \
66 clib_warning (_fmt, ##_args)
68 #define QUIC_DBG(_lvl, _fmt, _args...)
71 #define QUIC_ERR(_fmt, _args...) \
73 clib_warning ("QUIC-ERR: " _fmt, ##_args); \
76 extern vlib_node_registration_t quic_input_node;
80 #define quic_error(n,s) QUIC_ERROR_##n,
81 #include <plugins/quic/quic_error.def>
86 typedef enum quic_ctx_conn_state_
88 QUIC_CONN_STATE_OPENED,
89 QUIC_CONN_STATE_HANDSHAKE,
90 QUIC_CONN_STATE_READY,
91 QUIC_CONN_STATE_PASSIVE_CLOSING,
92 QUIC_CONN_STATE_PASSIVE_CLOSING_APP_CLOSED,
93 QUIC_CONN_STATE_PASSIVE_CLOSING_QUIC_CLOSED,
94 QUIC_CONN_STATE_ACTIVE_CLOSING,
95 } quic_ctx_conn_state_t;
97 typedef enum quic_packet_type_
99 QUIC_PACKET_TYPE_NONE,
100 QUIC_PACKET_TYPE_RECEIVE,
101 QUIC_PACKET_TYPE_MIGRATE,
102 QUIC_PACKET_TYPE_ACCEPT,
103 QUIC_PACKET_TYPE_RESET,
104 QUIC_PACKET_TYPE_DROP,
105 } quic_packet_type_t;
107 typedef enum quic_ctx_flags_
109 QUIC_F_IS_STREAM = (1 << 0),
110 QUIC_F_IS_LISTENER = (1 << 1),
113 /* This structure is used to implement the concept of VPP connection for QUIC.
114 * We create one per connection and one per stream. */
115 typedef struct quic_ctx_
119 transport_connection_t connection;
121 { /** QUIC ctx case */
128 u8 _qctx_end_marker; /* Leave this at the end */
131 { /** STREAM ctx case */
132 quicly_stream_t *stream;
133 u32 quic_connection_ctx_id;
134 u8 _sctx_end_marker; /* Leave this at the end */
137 session_handle_t udp_session_handle;
139 u32 parent_app_wrk_id;
142 quicly_context_t *quicly_ctx;
146 /* Make sure our custom fields don't overlap with the fields we use in
149 STATIC_ASSERT (offsetof (quic_ctx_t, _qctx_end_marker) <=
150 TRANSPORT_CONN_ID_LEN,
151 "connection data must be less than TRANSPORT_CONN_ID_LEN bytes");
152 STATIC_ASSERT (offsetof (quic_ctx_t, _sctx_end_marker) <=
153 TRANSPORT_CONN_ID_LEN,
154 "connection data must be less than TRANSPORT_CONN_ID_LEN bytes");
156 /* single-entry session cache */
157 typedef struct quic_session_cache_
159 ptls_encrypt_ticket_t super;
162 } quic_session_cache_t;
164 typedef struct quic_stream_data_
168 u32 app_rx_data_len; /**< bytes received, to be read by external app */
169 } quic_stream_data_t;
171 typedef struct quic_worker_ctx_
173 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
174 int64_t time_now; /**< worker time */
175 tw_timer_wheel_1t_3w_1024sl_ov_t timer_wheel; /**< worker timer wheel */
178 typedef struct quic_rx_packet_ctx_
180 quicly_decoded_packet_t packet;
181 u8 data[QUIC_MAX_PACKET_SIZE];
187 struct sockaddr_in6 sa6;
191 session_dgram_hdr_t ph;
192 } quic_rx_packet_ctx_t;
194 typedef struct quicly_ctx_data_
196 quicly_context_t quicly_ctx;
198 ptls_context_t ptls_ctx;
201 typedef struct quic_main_
204 quic_ctx_t **ctx_pool;
205 quic_worker_ctx_t *wrk_ctx;
206 clib_bihash_16_8_t connection_hash; /**< quic connection id -> conn handle */
207 f64 tstamp_ticks_per_clock;
209 ptls_cipher_suite_t ***quic_ciphers; /**< available ciphers by crypto engine */
210 uword *available_crypto_engines; /**< Bitmap for registered engines */
211 u8 default_crypto_engine; /**< Used if you do connect with CRYPTO_ENGINE_NONE (0) */
213 ptls_handshake_properties_t hs_properties;
214 quicly_cid_plaintext_t next_cid;
215 quic_session_cache_t session_cache;
218 u32 udp_fifo_prealloc;
221 #endif /* __included_quic_h__ */
224 * fd.io coding-style-patch-verification: ON
227 * eval: (c-set-style "gnu")