comparison src/event/ngx_event_quic.h @ 8224:ae35ccba7aa6 quic

Extracted transport part of the code into separate file. All code dealing with serializing/deserializing is moved int srv/event/ngx_event_quic_transport.c/h file. All macros for dealing with data are internal to source file. The header file exposes frame types and error codes. The exported functions are currently packet header parsers and writers and frames parser/writer. The ngx_quic_header_t structure is updated with 'log' member. This avoids passing extra argument to parsing functions that need to report errors.
author Vladimir Homutov <vl@nginx.com>
date Wed, 18 Mar 2020 12:58:27 +0300
parents 61f9b873e2e7
children e9891e8ee975
comparison
equal deleted inserted replaced
8223:61f9b873e2e7 8224:ae35ccba7aa6
9 9
10 10
11 #include <ngx_event_openssl.h> 11 #include <ngx_event_openssl.h>
12 12
13 13
14 #define quic_version 0xff000018 /* draft-24 (ngtcp2) */ 14 #define quic_version 0xff000018 /* draft-24 (ngtcp2) */
15 //#define quic_version 0xff00001b /* draft-27 (FFN 76) */ 15 //#define quic_version 0xff00001b /* draft-27 (FFN 76) */
16
17 /* 17.2. Long Header Packets */
18
19 #define NGX_QUIC_PKT_LONG 0x80
20
21 #define NGX_QUIC_PKT_INITIAL 0xc0
22 #define NGX_QUIC_PKT_HANDSHAKE 0xe0
23
24
25 #if (NGX_HAVE_NONALIGNED)
26
27 #define ngx_quic_parse_uint16(p) ntohs(*(uint16_t *) (p))
28 #define ngx_quic_parse_uint32(p) ntohl(*(uint32_t *) (p))
29
30 #define ngx_quic_write_uint16 ngx_quic_write_uint16_aligned
31 #define ngx_quic_write_uint32 ngx_quic_write_uint32_aligned
32
33 #else
34
35 #define ngx_quic_parse_uint16(p) ((p)[0] << 8 | (p)[1])
36 #define ngx_quic_parse_uint32(p) \
37 ((uint32_t) (p)[0] << 24 | (p)[1] << 16 | (p)[2] << 8 | (p)[3])
38
39 #define ngx_quic_write_uint16(p, s) \
40 ((p)[0] = (u_char) ((s) >> 8), \
41 (p)[1] = (u_char) (s), \
42 (p) + sizeof(uint16_t))
43
44 #define ngx_quic_write_uint32(p, s) \
45 ((p)[0] = (u_char) ((s) >> 24), \
46 (p)[1] = (u_char) ((s) >> 16), \
47 (p)[2] = (u_char) ((s) >> 8), \
48 (p)[3] = (u_char) (s), \
49 (p) + sizeof(uint32_t))
50
51 #endif
52
53
54 #define ngx_quic_write_uint16_aligned(p, s) \
55 (*(uint16_t *) (p) = htons((uint16_t) (s)), (p) + sizeof(uint16_t))
56
57 #define ngx_quic_write_uint32_aligned(p, s) \
58 (*(uint32_t *) (p) = htonl((uint32_t) (s)), (p) + sizeof(uint32_t))
59
60 #define ngx_quic_varint_len(value) \
61 ((value) <= 63 ? 1 \
62 : ((uint32_t) value) <= 16383 ? 2 \
63 : ((uint64_t) value) <= 1073741823 ? 4 \
64 : 8)
65 16
66 17
67 struct ngx_quic_stream_s { 18 struct ngx_quic_stream_s {
68 uint64_t id; 19 uint64_t id;
69 ngx_uint_t unidirectional:1; 20 ngx_uint_t unidirectional:1;
70 ngx_connection_t *parent; 21 ngx_connection_t *parent;
71 void *data; 22 void *data;
72 }; 23 };
73 24
74 typedef struct ngx_quic_secret_s ngx_quic_secret_t;
75 typedef enum ssl_encryption_level_t ngx_quic_level_t;
76
77 typedef struct {
78 ngx_quic_secret_t *secret;
79 ngx_uint_t type;
80 ngx_uint_t *number;
81 ngx_uint_t flags;
82 uint32_t version;
83 ngx_str_t token;
84 ngx_quic_level_t level;
85
86 /* filled in by parser */
87 ngx_buf_t *raw; /* udp datagram from wire */
88
89 u_char *data; /* quic packet */
90 size_t len;
91
92 /* cleartext fields */
93 ngx_str_t dcid;
94 ngx_str_t scid;
95
96 uint64_t pn;
97
98 ngx_str_t payload; /* decrypted payload */
99
100 } ngx_quic_header_t;
101
102 void ngx_quic_build_int(u_char **pos, uint64_t value);
103 25
104 void ngx_quic_init_ssl_methods(SSL_CTX* ctx); 26 void ngx_quic_init_ssl_methods(SSL_CTX* ctx);
105 27
106 void ngx_quic_run(ngx_connection_t *c, ngx_ssl_t *ssl, ngx_msec_t timeout, 28 void ngx_quic_run(ngx_connection_t *c, ngx_ssl_t *ssl, ngx_msec_t timeout,
107 ngx_connection_handler_pt handler); 29 ngx_connection_handler_pt handler);