annotate src/event/ngx_event_quic_transport.c @ 8651:dbad2d6d1898 quic

QUIC: removed ngx_quic_hexdump() macro. Instead, appropriate format specifier for hexadecimal is used in ngx_log_debug(). The STREAM frame "data" debug is moved into ngx_quic_log_frame(), similar to all other frame fields debug.
author Vladimir Homutov <vl@nginx.com>
date Fri, 27 Nov 2020 18:43:36 +0300
parents 05b1ee464350
children 2dfc5ef29973
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
2 /*
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
3 * Copyright (C) Nginx, Inc.
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
4 */
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
5
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
6
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
7 #include <ngx_config.h>
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
8 #include <ngx_core.h>
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
9 #include <ngx_event.h>
8486
d0ac4449a07f QUIC: fixed bulding perl module by reducing header pollution.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8478
diff changeset
10 #include <ngx_event_quic_transport.h>
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
11
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
12
8628
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
13 #define NGX_QUIC_LONG_DCID_LEN_OFFSET 5
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
14 #define NGX_QUIC_LONG_DCID_OFFSET 6
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
15 #define NGX_QUIC_SHORT_DCID_OFFSET 1
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
16
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
17
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
18 #if (NGX_HAVE_NONALIGNED)
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
19
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
20 #define ngx_quic_parse_uint16(p) ntohs(*(uint16_t *) (p))
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
21 #define ngx_quic_parse_uint32(p) ntohl(*(uint32_t *) (p))
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
22
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
23 #define ngx_quic_write_uint16 ngx_quic_write_uint16_aligned
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
24 #define ngx_quic_write_uint32 ngx_quic_write_uint32_aligned
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
25
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
26 #else
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
27
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
28 #define ngx_quic_parse_uint16(p) ((p)[0] << 8 | (p)[1])
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
29 #define ngx_quic_parse_uint32(p) \
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
30 ((uint32_t) (p)[0] << 24 | (p)[1] << 16 | (p)[2] << 8 | (p)[3])
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
31
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
32 #define ngx_quic_write_uint16(p, s) \
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
33 ((p)[0] = (u_char) ((s) >> 8), \
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
34 (p)[1] = (u_char) (s), \
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
35 (p) + sizeof(uint16_t))
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
36
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
37 #define ngx_quic_write_uint32(p, s) \
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
38 ((p)[0] = (u_char) ((s) >> 24), \
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
39 (p)[1] = (u_char) ((s) >> 16), \
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
40 (p)[2] = (u_char) ((s) >> 8), \
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
41 (p)[3] = (u_char) (s), \
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
42 (p) + sizeof(uint32_t))
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
43
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
44 #endif
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
45
8315
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
46 #define ngx_quic_write_uint24(p, s) \
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
47 ((p)[0] = (u_char) ((s) >> 16), \
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
48 (p)[1] = (u_char) ((s) >> 8), \
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
49 (p)[2] = (u_char) (s), \
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
50 (p) + 3)
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
51
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
52 #define ngx_quic_write_uint16_aligned(p, s) \
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
53 (*(uint16_t *) (p) = htons((uint16_t) (s)), (p) + sizeof(uint16_t))
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
54
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
55 #define ngx_quic_write_uint32_aligned(p, s) \
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
56 (*(uint32_t *) (p) = htonl((uint32_t) (s)), (p) + sizeof(uint32_t))
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
57
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
58 #define ngx_quic_varint_len(value) \
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
59 ((value) <= 63 ? 1 \
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
60 : ((uint32_t) value) <= 16383 ? 2 \
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
61 : ((uint64_t) value) <= 1073741823 ? 4 \
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
62 : 8)
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
63
8625
4416b7ab0a27 QUIC: multiple versions support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8624
diff changeset
64 #define NGX_QUIC_VERSION(c) (0xff000000 + (c))
4416b7ab0a27 QUIC: multiple versions support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8624
diff changeset
65
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
66
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
67 static u_char *ngx_quic_parse_int(u_char *pos, u_char *end, uint64_t *out);
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
68 static void ngx_quic_build_int(u_char **pos, uint64_t value);
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
69
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
70 static u_char *ngx_quic_read_uint8(u_char *pos, u_char *end, uint8_t *value);
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
71 static u_char *ngx_quic_read_uint32(u_char *pos, u_char *end, uint32_t *value);
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
72 static u_char *ngx_quic_read_bytes(u_char *pos, u_char *end, size_t len,
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
73 u_char **out);
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
74 static u_char *ngx_quic_copy_bytes(u_char *pos, u_char *end, size_t len,
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
75 u_char *dst);
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
76
8560
d0d3fc0697a0 QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents: 8559
diff changeset
77 static ngx_int_t ngx_quic_parse_short_header(ngx_quic_header_t *pkt,
d0d3fc0697a0 QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents: 8559
diff changeset
78 size_t dcid_len);
8640
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
79 static ngx_int_t ngx_quic_parse_long_header(ngx_quic_header_t *pkt);
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
80 static ngx_int_t ngx_quic_supported_version(uint32_t version);
8641
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
81 static ngx_int_t ngx_quic_parse_long_header_v1(ngx_quic_header_t *pkt);
8560
d0d3fc0697a0 QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents: 8559
diff changeset
82
8642
05b1ee464350 QUIC: hide header creation internals in ngx_event_quic_transport.c.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8641
diff changeset
83 static size_t ngx_quic_create_long_header(ngx_quic_header_t *pkt, u_char *out,
05b1ee464350 QUIC: hide header creation internals in ngx_event_quic_transport.c.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8641
diff changeset
84 size_t pkt_len, u_char **pnp);
05b1ee464350 QUIC: hide header creation internals in ngx_event_quic_transport.c.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8641
diff changeset
85 static size_t ngx_quic_create_short_header(ngx_quic_header_t *pkt, u_char *out,
05b1ee464350 QUIC: hide header creation internals in ngx_event_quic_transport.c.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8641
diff changeset
86 size_t pkt_len, u_char **pnp);
05b1ee464350 QUIC: hide header creation internals in ngx_event_quic_transport.c.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8641
diff changeset
87
8370
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
88 static ngx_int_t ngx_quic_frame_allowed(ngx_quic_header_t *pkt,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
89 ngx_uint_t frame_type);
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
90 static size_t ngx_quic_create_ack(u_char *p, ngx_quic_ack_frame_t *ack);
8528
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
91 static size_t ngx_quic_create_stop_sending(u_char *p,
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
92 ngx_quic_stop_sending_frame_t *ss);
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
93 static size_t ngx_quic_create_crypto(u_char *p,
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
94 ngx_quic_crypto_frame_t *crypto);
8273
cb75f194f1f0 Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents: 8269
diff changeset
95 static size_t ngx_quic_create_hs_done(u_char *p);
8384
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
96 static size_t ngx_quic_create_new_token(u_char *p,
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
97 ngx_quic_new_token_frame_t *token);
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
98 static size_t ngx_quic_create_stream(u_char *p, ngx_quic_stream_frame_t *sf);
8245
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
99 static size_t ngx_quic_create_max_streams(u_char *p,
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
100 ngx_quic_max_streams_frame_t *ms);
8266
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
101 static size_t ngx_quic_create_max_stream_data(u_char *p,
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
102 ngx_quic_max_stream_data_frame_t *ms);
8338
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
103 static size_t ngx_quic_create_max_data(u_char *p,
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
104 ngx_quic_max_data_frame_t *md);
8531
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
105 static size_t ngx_quic_create_path_response(u_char *p,
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
106 ngx_quic_path_challenge_frame_t *pc);
8628
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
107 static size_t ngx_quic_create_new_connection_id(u_char *p,
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
108 ngx_quic_new_conn_id_frame_t *rcid);
8538
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
109 static size_t ngx_quic_create_retire_connection_id(u_char *p,
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
110 ngx_quic_retire_cid_frame_t *rcid);
8235
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
111 static size_t ngx_quic_create_close(u_char *p, ngx_quic_close_frame_t *cl);
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
112
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
113 static ngx_int_t ngx_quic_parse_transport_param(u_char *p, u_char *end,
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
114 uint16_t id, ngx_quic_tp_t *dst);
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
115
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
116
8522
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
117 uint32_t ngx_quic_versions[] = {
8625
4416b7ab0a27 QUIC: multiple versions support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8624
diff changeset
118 #if (NGX_QUIC_DRAFT_VERSION >= 29)
4416b7ab0a27 QUIC: multiple versions support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8624
diff changeset
119 /* pretend we support all versions in range draft-29..v1 */
4416b7ab0a27 QUIC: multiple versions support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8624
diff changeset
120 NGX_QUIC_VERSION(29),
4416b7ab0a27 QUIC: multiple versions support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8624
diff changeset
121 NGX_QUIC_VERSION(30),
4416b7ab0a27 QUIC: multiple versions support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8624
diff changeset
122 NGX_QUIC_VERSION(31),
4416b7ab0a27 QUIC: multiple versions support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8624
diff changeset
123 NGX_QUIC_VERSION(32),
4416b7ab0a27 QUIC: multiple versions support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8624
diff changeset
124 /* QUICv1 */
4416b7ab0a27 QUIC: multiple versions support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8624
diff changeset
125 0x00000001
4416b7ab0a27 QUIC: multiple versions support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8624
diff changeset
126 #else
4416b7ab0a27 QUIC: multiple versions support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8624
diff changeset
127 NGX_QUIC_VERSION(NGX_QUIC_DRAFT_VERSION)
4416b7ab0a27 QUIC: multiple versions support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8624
diff changeset
128 #endif
8522
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
129 };
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
130
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
131 #define NGX_QUIC_NVERSIONS \
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
132 (sizeof(ngx_quic_versions) / sizeof(ngx_quic_versions[0]))
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
133
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
134
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
135 /* literal errors indexed by corresponding value */
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
136 static char *ngx_quic_errors[] = {
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
137 "NO_ERROR",
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
138 "INTERNAL_ERROR",
8440
f9592e804834 QUIC error SERVER_BUSY renamed to CONNECTION_REFUSED in draft-29.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8426
diff changeset
139 "CONNECTION_REFUSED",
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
140 "FLOW_CONTROL_ERROR",
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
141 "STREAM_LIMIT_ERROR",
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
142 "STREAM_STATE_ERROR",
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
143 "FINAL_SIZE_ERROR",
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
144 "FRAME_ENCODING_ERROR",
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
145 "TRANSPORT_PARAMETER_ERROR",
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
146 "CONNECTION_ID_LIMIT_ERROR",
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
147 "PROTOCOL_VIOLATION",
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
148 "INVALID_TOKEN",
8426
6ea2f1daedb5 Introduced connection error APPLICATION_ERROR from draft-28.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8425
diff changeset
149 "APPLICATION_ERROR",
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
150 "CRYPTO_BUFFER_EXCEEDED",
8444
769d8bdeffb0 Define KEY_UPDATE_ERROR from quic-tls-24.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8440
diff changeset
151 "KEY_UPDATE_ERROR",
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
152 };
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
153
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
154
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
155 static ngx_inline u_char *
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
156 ngx_quic_parse_int(u_char *pos, u_char *end, uint64_t *out)
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
157 {
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
158 u_char *p;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
159 uint64_t value;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
160 ngx_uint_t len;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
161
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
162 if (pos >= end) {
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
163 return NULL;
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
164 }
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
165
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
166 p = pos;
8636
ad7ca043edf5 QUIC: microoptimization in varint parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8634
diff changeset
167 len = 1 << (*p >> 6);
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
168
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
169 value = *p++ & 0x3f;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
170
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
171 if ((size_t)(end - p) < (len - 1)) {
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
172 return NULL;
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
173 }
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
174
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
175 while (--len) {
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
176 value = (value << 8) + *p++;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
177 }
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
178
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
179 *out = value;
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
180
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
181 return p;
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
182 }
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
183
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
184
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
185 static ngx_inline u_char *
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
186 ngx_quic_read_uint8(u_char *pos, u_char *end, uint8_t *value)
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
187 {
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
188 if ((size_t)(end - pos) < 1) {
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
189 return NULL;
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
190 }
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
191
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
192 *value = *pos;
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
193
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
194 return pos + 1;
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
195 }
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
196
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
197
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
198 static ngx_inline u_char *
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
199 ngx_quic_read_uint32(u_char *pos, u_char *end, uint32_t *value)
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
200 {
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
201 if ((size_t)(end - pos) < sizeof(uint32_t)) {
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
202 return NULL;
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
203 }
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
204
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
205 *value = ngx_quic_parse_uint32(pos);
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
206
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
207 return pos + sizeof(uint32_t);
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
208 }
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
209
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
210
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
211 static ngx_inline u_char *
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
212 ngx_quic_read_bytes(u_char *pos, u_char *end, size_t len, u_char **out)
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
213 {
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
214 if ((size_t)(end - pos) < len) {
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
215 return NULL;
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
216 }
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
217
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
218 *out = pos;
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
219
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
220 return pos + len;
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
221 }
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
222
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
223
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
224 static u_char *
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
225 ngx_quic_copy_bytes(u_char *pos, u_char *end, size_t len, u_char *dst)
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
226 {
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
227 if ((size_t)(end - pos) < len) {
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
228 return NULL;
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
229 }
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
230
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
231 ngx_memcpy(dst, pos, len);
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
232
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
233 return pos + len;
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
234 }
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
235
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
236
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
237 static void
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
238 ngx_quic_build_int(u_char **pos, uint64_t value)
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
239 {
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
240 u_char *p;
8351
dd84c9cef75b Improved ngx_quic_build_int() code and readability.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8344
diff changeset
241 ngx_uint_t bits, len;
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
242
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
243 p = *pos;
8351
dd84c9cef75b Improved ngx_quic_build_int() code and readability.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8344
diff changeset
244 bits = 0;
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
245
8351
dd84c9cef75b Improved ngx_quic_build_int() code and readability.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8344
diff changeset
246 while (value >> ((8 << bits) - 2)) {
dd84c9cef75b Improved ngx_quic_build_int() code and readability.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8344
diff changeset
247 bits++;
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
248 }
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
249
8351
dd84c9cef75b Improved ngx_quic_build_int() code and readability.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8344
diff changeset
250 len = (1 << bits);
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
251
8351
dd84c9cef75b Improved ngx_quic_build_int() code and readability.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8344
diff changeset
252 while (len--) {
dd84c9cef75b Improved ngx_quic_build_int() code and readability.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8344
diff changeset
253 *p++ = value >> (len * 8);
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
254 }
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
255
8351
dd84c9cef75b Improved ngx_quic_build_int() code and readability.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8344
diff changeset
256 **pos |= bits << 6;
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
257 *pos = p;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
258 }
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
259
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
260
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
261 u_char *
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
262 ngx_quic_error_text(uint64_t error_code)
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
263 {
8447
97adb87f149b Get rid of hardcoded numbers used for quic handshake errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8444
diff changeset
264 if (error_code >= NGX_QUIC_ERR_CRYPTO_ERROR) {
97adb87f149b Get rid of hardcoded numbers used for quic handshake errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8444
diff changeset
265 return (u_char *) "handshake error";
97adb87f149b Get rid of hardcoded numbers used for quic handshake errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8444
diff changeset
266 }
8342
76e8ec502c69 Fixed error descriptions.
Vladimir Homutov <vl@nginx.com>
parents: 8338
diff changeset
267
76e8ec502c69 Fixed error descriptions.
Vladimir Homutov <vl@nginx.com>
parents: 8338
diff changeset
268 if (error_code >= NGX_QUIC_ERR_LAST) {
76e8ec502c69 Fixed error descriptions.
Vladimir Homutov <vl@nginx.com>
parents: 8338
diff changeset
269 return (u_char *) "unknown error";
76e8ec502c69 Fixed error descriptions.
Vladimir Homutov <vl@nginx.com>
parents: 8338
diff changeset
270 }
76e8ec502c69 Fixed error descriptions.
Vladimir Homutov <vl@nginx.com>
parents: 8338
diff changeset
271
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
272 return (u_char *) ngx_quic_errors[error_code];
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
273 }
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
274
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
275
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
276 ngx_int_t
8560
d0d3fc0697a0 QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents: 8559
diff changeset
277 ngx_quic_parse_packet(ngx_quic_header_t *pkt)
d0d3fc0697a0 QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents: 8559
diff changeset
278 {
d0d3fc0697a0 QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents: 8559
diff changeset
279 if (!ngx_quic_long_pkt(pkt->flags)) {
d0d3fc0697a0 QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents: 8559
diff changeset
280 pkt->level = ssl_encryption_application;
d0d3fc0697a0 QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents: 8559
diff changeset
281
8569
a6784cf32c13 QUIC: fixed handling of incorrect packets.
Vladimir Homutov <vl@nginx.com>
parents: 8562
diff changeset
282 if (ngx_quic_parse_short_header(pkt, NGX_QUIC_SERVER_CID_LEN) != NGX_OK)
a6784cf32c13 QUIC: fixed handling of incorrect packets.
Vladimir Homutov <vl@nginx.com>
parents: 8562
diff changeset
283 {
a6784cf32c13 QUIC: fixed handling of incorrect packets.
Vladimir Homutov <vl@nginx.com>
parents: 8562
diff changeset
284 return NGX_DECLINED;
a6784cf32c13 QUIC: fixed handling of incorrect packets.
Vladimir Homutov <vl@nginx.com>
parents: 8562
diff changeset
285 }
a6784cf32c13 QUIC: fixed handling of incorrect packets.
Vladimir Homutov <vl@nginx.com>
parents: 8562
diff changeset
286
a6784cf32c13 QUIC: fixed handling of incorrect packets.
Vladimir Homutov <vl@nginx.com>
parents: 8562
diff changeset
287 return NGX_OK;
8560
d0d3fc0697a0 QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents: 8559
diff changeset
288 }
d0d3fc0697a0 QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents: 8559
diff changeset
289
d0d3fc0697a0 QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents: 8559
diff changeset
290 if (ngx_quic_parse_long_header(pkt) != NGX_OK) {
d0d3fc0697a0 QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents: 8559
diff changeset
291 return NGX_DECLINED;
d0d3fc0697a0 QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents: 8559
diff changeset
292 }
d0d3fc0697a0 QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents: 8559
diff changeset
293
8624
340cd26158fb QUIC: preparatory changes for multiple QUIC versions support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8613
diff changeset
294 if (!ngx_quic_supported_version(pkt->version)) {
8560
d0d3fc0697a0 QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents: 8559
diff changeset
295 return NGX_ABORT;
d0d3fc0697a0 QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents: 8559
diff changeset
296 }
d0d3fc0697a0 QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents: 8559
diff changeset
297
8641
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
298 if (ngx_quic_parse_long_header_v1(pkt) != NGX_OK) {
8569
a6784cf32c13 QUIC: fixed handling of incorrect packets.
Vladimir Homutov <vl@nginx.com>
parents: 8562
diff changeset
299 return NGX_DECLINED;
a6784cf32c13 QUIC: fixed handling of incorrect packets.
Vladimir Homutov <vl@nginx.com>
parents: 8562
diff changeset
300 }
a6784cf32c13 QUIC: fixed handling of incorrect packets.
Vladimir Homutov <vl@nginx.com>
parents: 8562
diff changeset
301
a6784cf32c13 QUIC: fixed handling of incorrect packets.
Vladimir Homutov <vl@nginx.com>
parents: 8562
diff changeset
302 return NGX_OK;
8560
d0d3fc0697a0 QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents: 8559
diff changeset
303 }
d0d3fc0697a0 QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents: 8559
diff changeset
304
d0d3fc0697a0 QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents: 8559
diff changeset
305
8640
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
306 static ngx_int_t
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
307 ngx_quic_parse_short_header(ngx_quic_header_t *pkt, size_t dcid_len)
8628
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
308 {
8640
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
309 u_char *p, *end;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
310
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
311 p = pkt->raw->pos;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
312 end = pkt->data + pkt->len;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
313
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
314 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pkt->log, 0,
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
315 "quic packet rx short flags:%xd", pkt->flags);
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
316
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
317 if (!(pkt->flags & NGX_QUIC_PKT_FIXED_BIT)) {
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
318 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, "quic fixed bit is not set");
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
319 return NGX_ERROR;
8628
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
320 }
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
321
8640
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
322 pkt->dcid.len = dcid_len;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
323
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
324 p = ngx_quic_read_bytes(p, end, dcid_len, &pkt->dcid.data);
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
325 if (p == NULL) {
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
326 ngx_log_error(NGX_LOG_INFO, pkt->log, 0,
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
327 "quic packet is too small to read dcid");
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
328 return NGX_ERROR;
8628
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
329 }
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
330
8640
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
331 pkt->raw->pos = p;
8628
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
332
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
333 return NGX_OK;
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
334 }
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
335
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
336
8560
d0d3fc0697a0 QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents: 8559
diff changeset
337 static ngx_int_t
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
338 ngx_quic_parse_long_header(ngx_quic_header_t *pkt)
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
339 {
8522
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
340 u_char *p, *end;
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
341 uint8_t idlen;
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
342
8559
a89a58c642ef QUIC: simplified packet header parsing.
Vladimir Homutov <vl@nginx.com>
parents: 8558
diff changeset
343 p = pkt->raw->pos;
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
344 end = pkt->data + pkt->len;
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
345
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
346 p = ngx_quic_read_uint32(p, end, &pkt->version);
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
347 if (p == NULL) {
8275
19660929e8ff Logging cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8273
diff changeset
348 ngx_log_error(NGX_LOG_INFO, pkt->log, 0,
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
349 "quic packet is too small to read version");
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
350 return NGX_ERROR;
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
351 }
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
352
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
353 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pkt->log, 0,
8609
f32740ddd484 QUIC: got rid of "pkt" abbreviation in logs.
Vladimir Homutov <vl@nginx.com>
parents: 8608
diff changeset
354 "quic packet rx long flags:%xd version:%xD",
8359
2f900ae486bc Debug cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8358
diff changeset
355 pkt->flags, pkt->version);
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
356
8386
81f85c479d7e Discard packets without fixed bit or reserved bits set.
Vladimir Homutov <vl@nginx.com>
parents: 8385
diff changeset
357 if (!(pkt->flags & NGX_QUIC_PKT_FIXED_BIT)) {
81f85c479d7e Discard packets without fixed bit or reserved bits set.
Vladimir Homutov <vl@nginx.com>
parents: 8385
diff changeset
358 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, "quic fixed bit is not set");
8533
62b58f0a4711 QUIC: discard incorrect packets instead of closing the connection.
Vladimir Homutov <vl@nginx.com>
parents: 8531
diff changeset
359 return NGX_ERROR;
8386
81f85c479d7e Discard packets without fixed bit or reserved bits set.
Vladimir Homutov <vl@nginx.com>
parents: 8385
diff changeset
360 }
81f85c479d7e Discard packets without fixed bit or reserved bits set.
Vladimir Homutov <vl@nginx.com>
parents: 8385
diff changeset
361
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
362 p = ngx_quic_read_uint8(p, end, &idlen);
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
363 if (p == NULL) {
8275
19660929e8ff Logging cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8273
diff changeset
364 ngx_log_error(NGX_LOG_INFO, pkt->log, 0,
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
365 "quic packet is too small to read dcid len");
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
366 return NGX_ERROR;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
367 }
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
368
8387
eebdda507ec3 Added tests for connection id lengths in initial packet.
Vladimir Homutov <vl@nginx.com>
parents: 8386
diff changeset
369 if (idlen > NGX_QUIC_CID_LEN_MAX) {
eebdda507ec3 Added tests for connection id lengths in initial packet.
Vladimir Homutov <vl@nginx.com>
parents: 8386
diff changeset
370 ngx_log_error(NGX_LOG_INFO, pkt->log, 0,
eebdda507ec3 Added tests for connection id lengths in initial packet.
Vladimir Homutov <vl@nginx.com>
parents: 8386
diff changeset
371 "quic packet dcid is too long");
eebdda507ec3 Added tests for connection id lengths in initial packet.
Vladimir Homutov <vl@nginx.com>
parents: 8386
diff changeset
372 return NGX_ERROR;
eebdda507ec3 Added tests for connection id lengths in initial packet.
Vladimir Homutov <vl@nginx.com>
parents: 8386
diff changeset
373 }
eebdda507ec3 Added tests for connection id lengths in initial packet.
Vladimir Homutov <vl@nginx.com>
parents: 8386
diff changeset
374
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
375 pkt->dcid.len = idlen;
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
376
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
377 p = ngx_quic_read_bytes(p, end, idlen, &pkt->dcid.data);
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
378 if (p == NULL) {
8275
19660929e8ff Logging cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8273
diff changeset
379 ngx_log_error(NGX_LOG_INFO, pkt->log, 0,
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
380 "quic packet is too small to read dcid");
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
381 return NGX_ERROR;
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
382 }
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
383
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
384 p = ngx_quic_read_uint8(p, end, &idlen);
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
385 if (p == NULL) {
8275
19660929e8ff Logging cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8273
diff changeset
386 ngx_log_error(NGX_LOG_INFO, pkt->log, 0,
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
387 "quic packet is too small to read scid len");
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
388 return NGX_ERROR;
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
389 }
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
390
8387
eebdda507ec3 Added tests for connection id lengths in initial packet.
Vladimir Homutov <vl@nginx.com>
parents: 8386
diff changeset
391 if (idlen > NGX_QUIC_CID_LEN_MAX) {
eebdda507ec3 Added tests for connection id lengths in initial packet.
Vladimir Homutov <vl@nginx.com>
parents: 8386
diff changeset
392 ngx_log_error(NGX_LOG_INFO, pkt->log, 0,
eebdda507ec3 Added tests for connection id lengths in initial packet.
Vladimir Homutov <vl@nginx.com>
parents: 8386
diff changeset
393 "quic packet scid is too long");
eebdda507ec3 Added tests for connection id lengths in initial packet.
Vladimir Homutov <vl@nginx.com>
parents: 8386
diff changeset
394 return NGX_ERROR;
eebdda507ec3 Added tests for connection id lengths in initial packet.
Vladimir Homutov <vl@nginx.com>
parents: 8386
diff changeset
395 }
eebdda507ec3 Added tests for connection id lengths in initial packet.
Vladimir Homutov <vl@nginx.com>
parents: 8386
diff changeset
396
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
397 pkt->scid.len = idlen;
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
398
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
399 p = ngx_quic_read_bytes(p, end, idlen, &pkt->scid.data);
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
400 if (p == NULL) {
8275
19660929e8ff Logging cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8273
diff changeset
401 ngx_log_error(NGX_LOG_INFO, pkt->log, 0,
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
402 "quic packet is too small to read scid");
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
403 return NGX_ERROR;
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
404 }
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
405
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
406 pkt->raw->pos = p;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
407
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
408 return NGX_OK;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
409 }
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
410
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
411
8640
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
412 static ngx_int_t
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
413 ngx_quic_supported_version(uint32_t version)
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
414 {
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
415 ngx_uint_t i;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
416
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
417 for (i = 0; i < NGX_QUIC_NVERSIONS; i++) {
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
418 if (ngx_quic_versions[i] == version) {
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
419 return 1;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
420 }
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
421 }
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
422
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
423 return 0;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
424 }
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
425
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
426
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
427 static ngx_int_t
8641
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
428 ngx_quic_parse_long_header_v1(ngx_quic_header_t *pkt)
8640
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
429 {
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
430 u_char *p, *end;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
431 uint64_t varint;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
432
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
433 p = pkt->raw->pos;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
434 end = pkt->raw->last;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
435
8641
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
436 pkt->log->action = "parsing quic long header";
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
437
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
438 if (ngx_quic_pkt_in(pkt->flags)) {
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
439
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
440 if (pkt->len < NGX_QUIC_MIN_INITIAL_SIZE) {
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
441 ngx_log_error(NGX_LOG_INFO, pkt->log, 0,
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
442 "quic UDP datagram is too small for initial packet");
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
443 return NGX_DECLINED;
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
444 }
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
445
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
446 p = ngx_quic_parse_int(p, end, &varint);
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
447 if (p == NULL) {
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
448 ngx_log_error(NGX_LOG_INFO, pkt->log, 0,
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
449 "quic failed to parse token length");
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
450 return NGX_ERROR;
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
451 }
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
452
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
453 pkt->token.len = varint;
8640
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
454
8641
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
455 p = ngx_quic_read_bytes(p, end, pkt->token.len, &pkt->token.data);
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
456 if (p == NULL) {
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
457 ngx_log_error(NGX_LOG_INFO, pkt->log, 0,
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
458 "quic packet too small to read token data");
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
459 return NGX_ERROR;
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
460 }
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
461
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
462 pkt->level = ssl_encryption_initial;
8640
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
463
8641
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
464 } else if (ngx_quic_pkt_zrtt(pkt->flags)) {
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
465 pkt->level = ssl_encryption_early_data;
8640
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
466
8641
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
467 } else if (ngx_quic_pkt_hs(pkt->flags)) {
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
468 pkt->level = ssl_encryption_handshake;
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
469
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
470 } else {
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
471 ngx_log_error(NGX_LOG_INFO, pkt->log, 0,
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
472 "quic bad packet type");
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
473 return NGX_DECLINED;
8640
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
474 }
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
475
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
476 p = ngx_quic_parse_int(p, end, &varint);
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
477 if (p == NULL) {
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
478 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, "quic bad packet length");
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
479 return NGX_ERROR;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
480 }
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
481
8641
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
482 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pkt->log, 0,
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
483 "quic packet rx %s len:%uL",
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
484 ngx_quic_level_name(pkt->level), varint);
8640
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
485
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
486 if (varint > (uint64_t) ((pkt->data + pkt->len) - p)) {
8641
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
487 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, "quic truncated %s packet",
fe53def49945 QUIC: refactored long header parsing.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8640
diff changeset
488 ngx_quic_level_name(pkt->level));
8640
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
489 return NGX_ERROR;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
490 }
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
491
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
492 pkt->raw->pos = p;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
493 pkt->len = p + varint - pkt->data;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
494
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
495 return NGX_OK;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
496 }
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
497
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
498
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
499 ngx_int_t
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
500 ngx_quic_get_packet_dcid(ngx_log_t *log, u_char *data, size_t n,
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
501 ngx_str_t *dcid)
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
502 {
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
503 size_t len, offset;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
504
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
505 if (n == 0) {
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
506 goto failed;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
507 }
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
508
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
509 if (ngx_quic_long_pkt(*data)) {
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
510 if (n < NGX_QUIC_LONG_DCID_LEN_OFFSET + 1) {
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
511 goto failed;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
512 }
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
513
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
514 len = data[NGX_QUIC_LONG_DCID_LEN_OFFSET];
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
515 offset = NGX_QUIC_LONG_DCID_OFFSET;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
516
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
517 } else {
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
518 len = NGX_QUIC_SERVER_CID_LEN;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
519 offset = NGX_QUIC_SHORT_DCID_OFFSET;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
520 }
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
521
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
522 if (n < len + offset) {
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
523 goto failed;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
524 }
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
525
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
526 dcid->len = len;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
527 dcid->data = &data[offset];
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
528
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
529 return NGX_OK;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
530
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
531 failed:
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
532
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
533 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, log, 0, "quic malformed packet");
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
534
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
535 return NGX_ERROR;
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
536 }
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
537
46374c3fee3f QUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8636
diff changeset
538
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
539 size_t
8522
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
540 ngx_quic_create_version_negotiation(ngx_quic_header_t *pkt, u_char *out)
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
541 {
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
542 u_char *p, *start;
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
543 ngx_uint_t i;
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
544
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
545 p = start = out;
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
546
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
547 *p++ = pkt->flags;
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
548
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
549 /*
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
550 * The Version field of a Version Negotiation packet
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
551 * MUST be set to 0x00000000
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
552 */
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
553 p = ngx_quic_write_uint32(p, 0);
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
554
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
555 *p++ = pkt->dcid.len;
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
556 p = ngx_cpymem(p, pkt->dcid.data, pkt->dcid.len);
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
557
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
558 *p++ = pkt->scid.len;
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
559 p = ngx_cpymem(p, pkt->scid.data, pkt->scid.len);
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
560
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
561 for (i = 0; i < NGX_QUIC_NVERSIONS; i++) {
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
562 p = ngx_quic_write_uint32(p, ngx_quic_versions[i]);
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
563 }
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
564
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
565 return p - start;
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
566 }
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
567
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
568
fc89d02bdca2 QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents: 8499
diff changeset
569 size_t
8642
05b1ee464350 QUIC: hide header creation internals in ngx_event_quic_transport.c.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8641
diff changeset
570 ngx_quic_create_header(ngx_quic_header_t *pkt, u_char *out, size_t pkt_len,
05b1ee464350 QUIC: hide header creation internals in ngx_event_quic_transport.c.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8641
diff changeset
571 u_char **pnp)
05b1ee464350 QUIC: hide header creation internals in ngx_event_quic_transport.c.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8641
diff changeset
572 {
05b1ee464350 QUIC: hide header creation internals in ngx_event_quic_transport.c.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8641
diff changeset
573 return ngx_quic_short_pkt(pkt->flags)
05b1ee464350 QUIC: hide header creation internals in ngx_event_quic_transport.c.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8641
diff changeset
574 ? ngx_quic_create_short_header(pkt, out, pkt_len, pnp)
05b1ee464350 QUIC: hide header creation internals in ngx_event_quic_transport.c.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8641
diff changeset
575 : ngx_quic_create_long_header(pkt, out, pkt_len, pnp);
05b1ee464350 QUIC: hide header creation internals in ngx_event_quic_transport.c.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8641
diff changeset
576 }
05b1ee464350 QUIC: hide header creation internals in ngx_event_quic_transport.c.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8641
diff changeset
577
05b1ee464350 QUIC: hide header creation internals in ngx_event_quic_transport.c.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8641
diff changeset
578
05b1ee464350 QUIC: hide header creation internals in ngx_event_quic_transport.c.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8641
diff changeset
579 static size_t
8285
f85749b60e58 Removed memory allocations from encryption code.
Vladimir Homutov <vl@nginx.com>
parents: 8277
diff changeset
580 ngx_quic_create_long_header(ngx_quic_header_t *pkt, u_char *out,
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
581 size_t pkt_len, u_char **pnp)
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
582 {
8285
f85749b60e58 Removed memory allocations from encryption code.
Vladimir Homutov <vl@nginx.com>
parents: 8277
diff changeset
583 u_char *p, *start;
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
584
8594
ee06a813756c QUIC: teach how to compute only the length of created QUIC headers.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8593
diff changeset
585 if (out == NULL) {
ee06a813756c QUIC: teach how to compute only the length of created QUIC headers.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8593
diff changeset
586 return 5 + 2 + pkt->dcid.len + pkt->scid.len
ee06a813756c QUIC: teach how to compute only the length of created QUIC headers.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8593
diff changeset
587 + ngx_quic_varint_len(pkt_len + pkt->num_len) + pkt->num_len
ee06a813756c QUIC: teach how to compute only the length of created QUIC headers.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8593
diff changeset
588 + (pkt->level == ssl_encryption_initial ? 1 : 0);
ee06a813756c QUIC: teach how to compute only the length of created QUIC headers.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8593
diff changeset
589 }
ee06a813756c QUIC: teach how to compute only the length of created QUIC headers.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8593
diff changeset
590
8285
f85749b60e58 Removed memory allocations from encryption code.
Vladimir Homutov <vl@nginx.com>
parents: 8277
diff changeset
591 p = start = out;
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
592
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
593 *p++ = pkt->flags;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
594
8624
340cd26158fb QUIC: preparatory changes for multiple QUIC versions support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8613
diff changeset
595 p = ngx_quic_write_uint32(p, pkt->version);
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
596
8344
e0abe17a2878 Removed source/destination swap from the function creating header.
Vladimir Homutov <vl@nginx.com>
parents: 8342
diff changeset
597 *p++ = pkt->dcid.len;
e0abe17a2878 Removed source/destination swap from the function creating header.
Vladimir Homutov <vl@nginx.com>
parents: 8342
diff changeset
598 p = ngx_cpymem(p, pkt->dcid.data, pkt->dcid.len);
e0abe17a2878 Removed source/destination swap from the function creating header.
Vladimir Homutov <vl@nginx.com>
parents: 8342
diff changeset
599
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
600 *p++ = pkt->scid.len;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
601 p = ngx_cpymem(p, pkt->scid.data, pkt->scid.len);
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
602
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
603 if (pkt->level == ssl_encryption_initial) {
8593
d8a0bb1e85bf QUIC: simplified ngx_quic_create_long_header().
Sergey Kandaurov <pluknet@nginx.com>
parents: 8589
diff changeset
604 ngx_quic_build_int(&p, 0);
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
605 }
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
606
8315
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
607 ngx_quic_build_int(&p, pkt_len + pkt->num_len);
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
608
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
609 *pnp = p;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
610
8315
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
611 switch (pkt->num_len) {
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
612 case 1:
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
613 *p++ = pkt->trunc;
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
614 break;
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
615 case 2:
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
616 p = ngx_quic_write_uint16(p, pkt->trunc);
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
617 break;
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
618 case 3:
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
619 p = ngx_quic_write_uint24(p, pkt->trunc);
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
620 break;
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
621 case 4:
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
622 p = ngx_quic_write_uint32(p, pkt->trunc);
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
623 break;
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
624 }
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
625
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
626 return p - start;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
627 }
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
628
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
629
8642
05b1ee464350 QUIC: hide header creation internals in ngx_event_quic_transport.c.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8641
diff changeset
630 static size_t
8285
f85749b60e58 Removed memory allocations from encryption code.
Vladimir Homutov <vl@nginx.com>
parents: 8277
diff changeset
631 ngx_quic_create_short_header(ngx_quic_header_t *pkt, u_char *out,
f85749b60e58 Removed memory allocations from encryption code.
Vladimir Homutov <vl@nginx.com>
parents: 8277
diff changeset
632 size_t pkt_len, u_char **pnp)
f85749b60e58 Removed memory allocations from encryption code.
Vladimir Homutov <vl@nginx.com>
parents: 8277
diff changeset
633 {
f85749b60e58 Removed memory allocations from encryption code.
Vladimir Homutov <vl@nginx.com>
parents: 8277
diff changeset
634 u_char *p, *start;
f85749b60e58 Removed memory allocations from encryption code.
Vladimir Homutov <vl@nginx.com>
parents: 8277
diff changeset
635
8594
ee06a813756c QUIC: teach how to compute only the length of created QUIC headers.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8593
diff changeset
636 if (out == NULL) {
ee06a813756c QUIC: teach how to compute only the length of created QUIC headers.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8593
diff changeset
637 return 1 + pkt->dcid.len + pkt->num_len;
ee06a813756c QUIC: teach how to compute only the length of created QUIC headers.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8593
diff changeset
638 }
ee06a813756c QUIC: teach how to compute only the length of created QUIC headers.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8593
diff changeset
639
8285
f85749b60e58 Removed memory allocations from encryption code.
Vladimir Homutov <vl@nginx.com>
parents: 8277
diff changeset
640 p = start = out;
f85749b60e58 Removed memory allocations from encryption code.
Vladimir Homutov <vl@nginx.com>
parents: 8277
diff changeset
641
8315
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
642 *p++ = pkt->flags;
8285
f85749b60e58 Removed memory allocations from encryption code.
Vladimir Homutov <vl@nginx.com>
parents: 8277
diff changeset
643
8344
e0abe17a2878 Removed source/destination swap from the function creating header.
Vladimir Homutov <vl@nginx.com>
parents: 8342
diff changeset
644 p = ngx_cpymem(p, pkt->dcid.data, pkt->dcid.len);
8285
f85749b60e58 Removed memory allocations from encryption code.
Vladimir Homutov <vl@nginx.com>
parents: 8277
diff changeset
645
f85749b60e58 Removed memory allocations from encryption code.
Vladimir Homutov <vl@nginx.com>
parents: 8277
diff changeset
646 *pnp = p;
f85749b60e58 Removed memory allocations from encryption code.
Vladimir Homutov <vl@nginx.com>
parents: 8277
diff changeset
647
8315
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
648 switch (pkt->num_len) {
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
649 case 1:
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
650 *p++ = pkt->trunc;
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
651 break;
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
652 case 2:
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
653 p = ngx_quic_write_uint16(p, pkt->trunc);
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
654 break;
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
655 case 3:
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
656 p = ngx_quic_write_uint24(p, pkt->trunc);
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
657 break;
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
658 case 4:
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
659 p = ngx_quic_write_uint32(p, pkt->trunc);
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
660 break;
fdda518d10ba Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents: 8308
diff changeset
661 }
8285
f85749b60e58 Removed memory allocations from encryption code.
Vladimir Homutov <vl@nginx.com>
parents: 8277
diff changeset
662
f85749b60e58 Removed memory allocations from encryption code.
Vladimir Homutov <vl@nginx.com>
parents: 8277
diff changeset
663 return p - start;
f85749b60e58 Removed memory allocations from encryption code.
Vladimir Homutov <vl@nginx.com>
parents: 8277
diff changeset
664 }
f85749b60e58 Removed memory allocations from encryption code.
Vladimir Homutov <vl@nginx.com>
parents: 8277
diff changeset
665
f85749b60e58 Removed memory allocations from encryption code.
Vladimir Homutov <vl@nginx.com>
parents: 8277
diff changeset
666
8383
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
667 size_t
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
668 ngx_quic_create_retry_itag(ngx_quic_header_t *pkt, u_char *out,
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
669 u_char **start)
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
670 {
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
671 u_char *p;
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
672
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
673 p = out;
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
674
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
675 *p++ = pkt->odcid.len;
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
676 p = ngx_cpymem(p, pkt->odcid.data, pkt->odcid.len);
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
677
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
678 *start = p;
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
679
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
680 *p++ = 0xff;
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
681
8624
340cd26158fb QUIC: preparatory changes for multiple QUIC versions support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8613
diff changeset
682 p = ngx_quic_write_uint32(p, pkt->version);
8383
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
683
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
684 *p++ = pkt->dcid.len;
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
685 p = ngx_cpymem(p, pkt->dcid.data, pkt->dcid.len);
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
686
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
687 *p++ = pkt->scid.len;
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
688 p = ngx_cpymem(p, pkt->scid.data, pkt->scid.len);
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
689
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
690 p = ngx_cpymem(p, pkt->token.data, pkt->token.len);
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
691
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
692 return p - out;
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
693 }
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
694
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
695
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
696 #define ngx_quic_stream_bit_off(val) (((val) & 0x04) ? 1 : 0)
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
697 #define ngx_quic_stream_bit_len(val) (((val) & 0x02) ? 1 : 0)
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
698 #define ngx_quic_stream_bit_fin(val) (((val) & 0x01) ? 1 : 0)
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
699
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
700 ssize_t
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
701 ngx_quic_parse_frame(ngx_quic_header_t *pkt, u_char *start, u_char *end,
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
702 ngx_quic_frame_t *f)
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
703 {
8326
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
704 u_char *p;
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
705 uint64_t varint;
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
706 ngx_uint_t i;
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
707
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
708 p = start;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
709
8242
83a78cca8bce Fixed build.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8241
diff changeset
710 p = ngx_quic_parse_int(p, end, &varint);
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
711 if (p == NULL) {
8385
fb7422074258 Added generation of CC frames with error on connection termination.
Vladimir Homutov <vl@nginx.com>
parents: 8384
diff changeset
712 pkt->error = NGX_QUIC_ERR_FRAME_ENCODING_ERROR;
8275
19660929e8ff Logging cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8273
diff changeset
713 ngx_log_error(NGX_LOG_INFO, pkt->log, 0,
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
714 "quic failed to obtain quic frame type");
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
715 return NGX_ERROR;
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
716 }
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
717
8242
83a78cca8bce Fixed build.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8241
diff changeset
718 f->type = varint;
83a78cca8bce Fixed build.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8241
diff changeset
719
8370
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
720 if (ngx_quic_frame_allowed(pkt, f->type) != NGX_OK) {
8385
fb7422074258 Added generation of CC frames with error on connection termination.
Vladimir Homutov <vl@nginx.com>
parents: 8384
diff changeset
721 pkt->error = NGX_QUIC_ERR_PROTOCOL_VIOLATION;
fb7422074258 Added generation of CC frames with error on connection termination.
Vladimir Homutov <vl@nginx.com>
parents: 8384
diff changeset
722 return NGX_ERROR;
8370
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
723 }
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
724
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
725 switch (f->type) {
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
726
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
727 case NGX_QUIC_FT_CRYPTO:
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
728
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
729 p = ngx_quic_parse_int(p, end, &f->u.crypto.offset);
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
730 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
731 goto error;
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
732 }
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
733
8333
167d32476737 Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents: 8326
diff changeset
734 p = ngx_quic_parse_int(p, end, &f->u.crypto.length);
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
735 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
736 goto error;
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
737 }
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
738
8333
167d32476737 Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents: 8326
diff changeset
739 p = ngx_quic_read_bytes(p, end, f->u.crypto.length, &f->u.crypto.data);
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
740 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
741 goto error;
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
742 }
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
743
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
744 break;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
745
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
746 case NGX_QUIC_FT_PADDING:
8251
c217a907ce42 Added checks for permitted frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8250
diff changeset
747
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
748 while (p < end && *p == NGX_QUIC_FT_PADDING) {
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
749 p++;
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
750 }
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
751
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
752 break;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
753
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
754 case NGX_QUIC_FT_ACK:
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
755 case NGX_QUIC_FT_ACK_ECN:
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
756
8357
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
757 if (!((p = ngx_quic_parse_int(p, end, &f->u.ack.largest))
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
758 && (p = ngx_quic_parse_int(p, end, &f->u.ack.delay))
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
759 && (p = ngx_quic_parse_int(p, end, &f->u.ack.range_count))
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
760 && (p = ngx_quic_parse_int(p, end, &f->u.ack.first_range))))
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
761 {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
762 goto error;
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
763 }
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
764
8326
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
765 f->u.ack.ranges_start = p;
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
766
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
767 /* process all ranges to get bounds, values are ignored */
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
768 for (i = 0; i < f->u.ack.range_count; i++) {
8357
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
769
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
770 p = ngx_quic_parse_int(p, end, &varint);
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
771 if (p) {
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
772 p = ngx_quic_parse_int(p, end, &varint);
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
773 }
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
774
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
775 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
776 goto error;
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
777 }
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
778 }
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
779
8326
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
780 f->u.ack.ranges_end = p;
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
781
8326
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
782 if (f->type == NGX_QUIC_FT_ACK_ECN) {
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
783
8357
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
784 if (!((p = ngx_quic_parse_int(p, end, &f->u.ack.ect0))
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
785 && (p = ngx_quic_parse_int(p, end, &f->u.ack.ect1))
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
786 && (p = ngx_quic_parse_int(p, end, &f->u.ack.ce))))
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
787 {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
788 goto error;
8326
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
789 }
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
790
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
791 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, pkt->log, 0,
8605
eed49b83e18f QUIC: revised value separators in debug and error messages.
Vladimir Homutov <vl@nginx.com>
parents: 8604
diff changeset
792 "quic ACK ECN counters ect0:%uL ect1:%uL ce:%uL",
8326
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
793 f->u.ack.ect0, f->u.ack.ect1, f->u.ack.ce);
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
794 }
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
795
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
796 break;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
797
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
798 case NGX_QUIC_FT_PING:
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
799 break;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
800
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
801 case NGX_QUIC_FT_NEW_CONNECTION_ID:
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
802
8357
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
803 p = ngx_quic_parse_int(p, end, &f->u.ncid.seqnum);
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
804 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
805 goto error;
8357
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
806 }
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
807
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
808 p = ngx_quic_parse_int(p, end, &f->u.ncid.retire);
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
809 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
810 goto error;
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
811 }
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
812
8538
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
813 if (f->u.ncid.retire > f->u.ncid.seqnum) {
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
814 goto error;
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
815 }
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
816
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
817 p = ngx_quic_read_uint8(p, end, &f->u.ncid.len);
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
818 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
819 goto error;
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
820 }
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
821
8538
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
822 if (f->u.ncid.len < 1 || f->u.ncid.len > NGX_QUIC_CID_LEN_MAX) {
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
823 goto error;
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
824 }
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
825
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
826 p = ngx_quic_copy_bytes(p, end, f->u.ncid.len, f->u.ncid.cid);
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
827 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
828 goto error;
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
829 }
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
830
8562
b31c02454539 QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents: 8560
diff changeset
831 p = ngx_quic_copy_bytes(p, end, NGX_QUIC_SR_TOKEN_LEN, f->u.ncid.srt);
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
832 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
833 goto error;
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
834 }
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
835
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
836 break;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
837
8537
88676e7f4449 QUIC: style.
Vladimir Homutov <vl@nginx.com>
parents: 8533
diff changeset
838 case NGX_QUIC_FT_RETIRE_CONNECTION_ID:
88676e7f4449 QUIC: style.
Vladimir Homutov <vl@nginx.com>
parents: 8533
diff changeset
839
88676e7f4449 QUIC: style.
Vladimir Homutov <vl@nginx.com>
parents: 8533
diff changeset
840 p = ngx_quic_parse_int(p, end, &f->u.retire_cid.sequence_number);
88676e7f4449 QUIC: style.
Vladimir Homutov <vl@nginx.com>
parents: 8533
diff changeset
841 if (p == NULL) {
88676e7f4449 QUIC: style.
Vladimir Homutov <vl@nginx.com>
parents: 8533
diff changeset
842 goto error;
88676e7f4449 QUIC: style.
Vladimir Homutov <vl@nginx.com>
parents: 8533
diff changeset
843 }
88676e7f4449 QUIC: style.
Vladimir Homutov <vl@nginx.com>
parents: 8533
diff changeset
844
88676e7f4449 QUIC: style.
Vladimir Homutov <vl@nginx.com>
parents: 8533
diff changeset
845 break;
88676e7f4449 QUIC: style.
Vladimir Homutov <vl@nginx.com>
parents: 8533
diff changeset
846
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
847 case NGX_QUIC_FT_CONNECTION_CLOSE:
8458
e0f92f68e018 QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents: 8447
diff changeset
848 case NGX_QUIC_FT_CONNECTION_CLOSE_APP:
8251
c217a907ce42 Added checks for permitted frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8250
diff changeset
849
8250
8f9cb6d66662 Fixed parsing of CONNECTION CLOSE2 frames.
Vladimir Homutov <vl@nginx.com>
parents: 8249
diff changeset
850 p = ngx_quic_parse_int(p, end, &f->u.close.error_code);
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
851 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
852 goto error;
8250
8f9cb6d66662 Fixed parsing of CONNECTION CLOSE2 frames.
Vladimir Homutov <vl@nginx.com>
parents: 8249
diff changeset
853 }
8f9cb6d66662 Fixed parsing of CONNECTION CLOSE2 frames.
Vladimir Homutov <vl@nginx.com>
parents: 8249
diff changeset
854
8f9cb6d66662 Fixed parsing of CONNECTION CLOSE2 frames.
Vladimir Homutov <vl@nginx.com>
parents: 8249
diff changeset
855 if (f->type == NGX_QUIC_FT_CONNECTION_CLOSE) {
8f9cb6d66662 Fixed parsing of CONNECTION CLOSE2 frames.
Vladimir Homutov <vl@nginx.com>
parents: 8249
diff changeset
856 p = ngx_quic_parse_int(p, end, &f->u.close.frame_type);
8256
0a18893299fe Fixed parsing NGX_QUIC_FT_CONNECTION_CLOSE.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8255
diff changeset
857 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
858 goto error;
8256
0a18893299fe Fixed parsing NGX_QUIC_FT_CONNECTION_CLOSE.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8255
diff changeset
859 }
8250
8f9cb6d66662 Fixed parsing of CONNECTION CLOSE2 frames.
Vladimir Homutov <vl@nginx.com>
parents: 8249
diff changeset
860 }
8f9cb6d66662 Fixed parsing of CONNECTION CLOSE2 frames.
Vladimir Homutov <vl@nginx.com>
parents: 8249
diff changeset
861
8254
856d5a2de258 Fixed build with macOS's long long abomination.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8251
diff changeset
862 p = ngx_quic_parse_int(p, end, &varint);
8250
8f9cb6d66662 Fixed parsing of CONNECTION CLOSE2 frames.
Vladimir Homutov <vl@nginx.com>
parents: 8249
diff changeset
863 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
864 goto error;
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
865 }
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
866
8254
856d5a2de258 Fixed build with macOS's long long abomination.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8251
diff changeset
867 f->u.close.reason.len = varint;
856d5a2de258 Fixed build with macOS's long long abomination.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8251
diff changeset
868
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
869 p = ngx_quic_read_bytes(p, end, f->u.close.reason.len,
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
870 &f->u.close.reason.data);
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
871 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
872 goto error;
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
873 }
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
874
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
875 break;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
876
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
877 case NGX_QUIC_FT_STREAM0:
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
878 case NGX_QUIC_FT_STREAM1:
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
879 case NGX_QUIC_FT_STREAM2:
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
880 case NGX_QUIC_FT_STREAM3:
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
881 case NGX_QUIC_FT_STREAM4:
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
882 case NGX_QUIC_FT_STREAM5:
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
883 case NGX_QUIC_FT_STREAM6:
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
884 case NGX_QUIC_FT_STREAM7:
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
885
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
886 f->u.stream.type = f->type;
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
887
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
888 f->u.stream.off = ngx_quic_stream_bit_off(f->type);
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
889 f->u.stream.len = ngx_quic_stream_bit_len(f->type);
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
890 f->u.stream.fin = ngx_quic_stream_bit_fin(f->type);
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
891
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
892 p = ngx_quic_parse_int(p, end, &f->u.stream.stream_id);
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
893 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
894 goto error;
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
895 }
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
896
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
897 if (f->type & 0x04) {
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
898 p = ngx_quic_parse_int(p, end, &f->u.stream.offset);
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
899 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
900 goto error;
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
901 }
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
902
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
903 } else {
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
904 f->u.stream.offset = 0;
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
905 }
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
906
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
907 if (f->type & 0x02) {
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
908 p = ngx_quic_parse_int(p, end, &f->u.stream.length);
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
909 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
910 goto error;
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
911 }
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
912
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
913 } else {
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
914 f->u.stream.length = end - p; /* up to packet end */
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
915 }
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
916
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
917 p = ngx_quic_read_bytes(p, end, f->u.stream.length,
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
918 &f->u.stream.data);
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
919 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
920 goto error;
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
921 }
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
922
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
923 break;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
924
8237
ff540f13d95d MAX_DATA frame parser/handler.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8236
diff changeset
925 case NGX_QUIC_FT_MAX_DATA:
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
926
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
927 p = ngx_quic_parse_int(p, end, &f->u.max_data.max_data);
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
928 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
929 goto error;
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
930 }
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
931
8237
ff540f13d95d MAX_DATA frame parser/handler.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8236
diff changeset
932 break;
ff540f13d95d MAX_DATA frame parser/handler.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8236
diff changeset
933
8231
78540e2160d0 Added parsing of RESET_STREAM and STOP_SENDING frames
Vladimir Homutov <vl@nginx.com>
parents: 8224
diff changeset
934 case NGX_QUIC_FT_RESET_STREAM:
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
935
8357
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
936 if (!((p = ngx_quic_parse_int(p, end, &f->u.reset_stream.id))
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
937 && (p = ngx_quic_parse_int(p, end, &f->u.reset_stream.error_code))
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
938 && (p = ngx_quic_parse_int(p, end,
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
939 &f->u.reset_stream.final_size))))
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
940 {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
941 goto error;
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
942 }
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
943
8231
78540e2160d0 Added parsing of RESET_STREAM and STOP_SENDING frames
Vladimir Homutov <vl@nginx.com>
parents: 8224
diff changeset
944 break;
78540e2160d0 Added parsing of RESET_STREAM and STOP_SENDING frames
Vladimir Homutov <vl@nginx.com>
parents: 8224
diff changeset
945
78540e2160d0 Added parsing of RESET_STREAM and STOP_SENDING frames
Vladimir Homutov <vl@nginx.com>
parents: 8224
diff changeset
946 case NGX_QUIC_FT_STOP_SENDING:
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
947
8357
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
948 p = ngx_quic_parse_int(p, end, &f->u.stop_sending.id);
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
949 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
950 goto error;
8357
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
951 }
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
952
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
953 p = ngx_quic_parse_int(p, end, &f->u.stop_sending.error_code);
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
954 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
955 goto error;
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
956 }
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
957
8231
78540e2160d0 Added parsing of RESET_STREAM and STOP_SENDING frames
Vladimir Homutov <vl@nginx.com>
parents: 8224
diff changeset
958 break;
78540e2160d0 Added parsing of RESET_STREAM and STOP_SENDING frames
Vladimir Homutov <vl@nginx.com>
parents: 8224
diff changeset
959
8236
d3b26c3bea22 Added parsing of STREAMS BLOCKED frames.
Vladimir Homutov <vl@nginx.com>
parents: 8235
diff changeset
960 case NGX_QUIC_FT_STREAMS_BLOCKED:
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
961 case NGX_QUIC_FT_STREAMS_BLOCKED2:
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
962
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
963 p = ngx_quic_parse_int(p, end, &f->u.streams_blocked.limit);
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
964 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
965 goto error;
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
966 }
8236
d3b26c3bea22 Added parsing of STREAMS BLOCKED frames.
Vladimir Homutov <vl@nginx.com>
parents: 8235
diff changeset
967
8240
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
968 f->u.streams_blocked.bidi =
1f002206a59b Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents: 8237
diff changeset
969 (f->type == NGX_QUIC_FT_STREAMS_BLOCKED) ? 1 : 0;
8236
d3b26c3bea22 Added parsing of STREAMS BLOCKED frames.
Vladimir Homutov <vl@nginx.com>
parents: 8235
diff changeset
970 break;
d3b26c3bea22 Added parsing of STREAMS BLOCKED frames.
Vladimir Homutov <vl@nginx.com>
parents: 8235
diff changeset
971
8251
c217a907ce42 Added checks for permitted frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8250
diff changeset
972 case NGX_QUIC_FT_MAX_STREAMS:
c217a907ce42 Added checks for permitted frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8250
diff changeset
973 case NGX_QUIC_FT_MAX_STREAMS2:
8257
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
974
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
975 p = ngx_quic_parse_int(p, end, &f->u.max_streams.limit);
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
976 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
977 goto error;
8257
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
978 }
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
979
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
980 f->u.max_streams.bidi = (f->type == NGX_QUIC_FT_MAX_STREAMS) ? 1 : 0;
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
981
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
982 break;
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
983
8251
c217a907ce42 Added checks for permitted frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8250
diff changeset
984 case NGX_QUIC_FT_MAX_STREAM_DATA:
8257
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
985
8357
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
986 p = ngx_quic_parse_int(p, end, &f->u.max_stream_data.id);
8257
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
987 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
988 goto error;
8357
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
989 }
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
990
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
991 p = ngx_quic_parse_int(p, end, &f->u.max_stream_data.limit);
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
992 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
993 goto error;
8257
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
994 }
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
995
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
996 break;
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
997
8251
c217a907ce42 Added checks for permitted frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8250
diff changeset
998 case NGX_QUIC_FT_DATA_BLOCKED:
8257
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
999
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
1000 p = ngx_quic_parse_int(p, end, &f->u.data_blocked.limit);
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
1001 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
1002 goto error;
8257
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
1003 }
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
1004
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
1005 break;
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
1006
8251
c217a907ce42 Added checks for permitted frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8250
diff changeset
1007 case NGX_QUIC_FT_STREAM_DATA_BLOCKED:
8257
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
1008
8357
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
1009 p = ngx_quic_parse_int(p, end, &f->u.stream_data_blocked.id);
8257
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
1010 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
1011 goto error;
8357
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
1012 }
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
1013
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
1014 p = ngx_quic_parse_int(p, end, &f->u.stream_data_blocked.limit);
05b8dd5d9f7e Retired the ngx_quic_parse_int_multi() function.
Vladimir Homutov <vl@nginx.com>
parents: 8356
diff changeset
1015 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
1016 goto error;
8257
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
1017 }
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
1018
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
1019 break;
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
1020
8251
c217a907ce42 Added checks for permitted frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8250
diff changeset
1021 case NGX_QUIC_FT_PATH_CHALLENGE:
8257
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
1022
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
1023 p = ngx_quic_copy_bytes(p, end, 8, f->u.path_challenge.data);
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
1024 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
1025 goto error;
8257
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
1026 }
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
1027
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
1028 break;
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
1029
8251
c217a907ce42 Added checks for permitted frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8250
diff changeset
1030 case NGX_QUIC_FT_PATH_RESPONSE:
c217a907ce42 Added checks for permitted frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8250
diff changeset
1031
8257
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
1032 p = ngx_quic_copy_bytes(p, end, 8, f->u.path_response.data);
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
1033 if (p == NULL) {
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
1034 goto error;
8257
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
1035 }
085fd6e68367 Implemented parsing of remaining frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8256
diff changeset
1036
8251
c217a907ce42 Added checks for permitted frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8250
diff changeset
1037 break;
c217a907ce42 Added checks for permitted frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8250
diff changeset
1038
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1039 default:
8275
19660929e8ff Logging cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8273
diff changeset
1040 ngx_log_error(NGX_LOG_INFO, pkt->log, 0,
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
1041 "quic unknown frame type 0x%xi", f->type);
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1042 return NGX_ERROR;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1043 }
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1044
8604
b3d9e57d0f62 QUIC: single function for frame debug logging.
Vladimir Homutov <vl@nginx.com>
parents: 8596
diff changeset
1045 f->level = pkt->level;
b3d9e57d0f62 QUIC: single function for frame debug logging.
Vladimir Homutov <vl@nginx.com>
parents: 8596
diff changeset
1046
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1047 return p - start;
8251
c217a907ce42 Added checks for permitted frame types.
Vladimir Homutov <vl@nginx.com>
parents: 8250
diff changeset
1048
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
1049 error:
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
1050
8385
fb7422074258 Added generation of CC frames with error on connection termination.
Vladimir Homutov <vl@nginx.com>
parents: 8384
diff changeset
1051 pkt->error = NGX_QUIC_ERR_FRAME_ENCODING_ERROR;
fb7422074258 Added generation of CC frames with error on connection termination.
Vladimir Homutov <vl@nginx.com>
parents: 8384
diff changeset
1052
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
1053 ngx_log_error(NGX_LOG_INFO, pkt->log, 0,
8605
eed49b83e18f QUIC: revised value separators in debug and error messages.
Vladimir Homutov <vl@nginx.com>
parents: 8604
diff changeset
1054 "quic failed to parse frame type:0x%xi", f->type);
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
1055
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
1056 return NGX_ERROR;
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1057 }
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1058
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1059
8370
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1060 static ngx_int_t
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1061 ngx_quic_frame_allowed(ngx_quic_header_t *pkt, ngx_uint_t frame_type)
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1062 {
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1063 uint8_t ptype;
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1064
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1065 /* frame permissions per packet: 4 bits: IH01: 12.4, Table 3 */
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1066 static uint8_t ngx_quic_frame_masks[] = {
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1067 /* PADDING */ 0xF,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1068 /* PING */ 0xF,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1069 /* ACK */ 0xD,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1070 /* ACK_ECN */ 0xD,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1071 /* RESET_STREAM */ 0x3,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1072 /* STOP_SENDING */ 0x3,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1073 /* CRYPTO */ 0xD,
8424
c70446e3d771 Treat receipt of NEW_TOKEN as connection error PROTOCOL_VIOLATION.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8422
diff changeset
1074 /* NEW_TOKEN */ 0x0, /* only sent by server */
8370
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1075 /* STREAM0 */ 0x3,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1076 /* STREAM1 */ 0x3,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1077 /* STREAM2 */ 0x3,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1078 /* STREAM3 */ 0x3,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1079 /* STREAM4 */ 0x3,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1080 /* STREAM5 */ 0x3,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1081 /* STREAM6 */ 0x3,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1082 /* STREAM7 */ 0x3,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1083 /* MAX_DATA */ 0x3,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1084 /* MAX_STREAM_DATA */ 0x3,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1085 /* MAX_STREAMS */ 0x3,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1086 /* MAX_STREAMS2 */ 0x3,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1087 /* DATA_BLOCKED */ 0x3,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1088 /* STREAM_DATA_BLOCKED */ 0x3,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1089 /* STREAMS_BLOCKED */ 0x3,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1090 /* STREAMS_BLOCKED2 */ 0x3,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1091 /* NEW_CONNECTION_ID */ 0x3,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1092 /* RETIRE_CONNECTION_ID */ 0x3,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1093 /* PATH_CHALLENGE */ 0x3,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1094 /* PATH_RESPONSE */ 0x3,
8425
3e38dad3a163 Receipt of CONNECTION_CLOSE in 0-RTT is permitted in draft-28.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8424
diff changeset
1095 #if (NGX_QUIC_DRAFT_VERSION >= 28)
3e38dad3a163 Receipt of CONNECTION_CLOSE in 0-RTT is permitted in draft-28.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8424
diff changeset
1096 /* CONNECTION_CLOSE */ 0xF,
3e38dad3a163 Receipt of CONNECTION_CLOSE in 0-RTT is permitted in draft-28.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8424
diff changeset
1097 /* CONNECTION_CLOSE2 */ 0x3,
3e38dad3a163 Receipt of CONNECTION_CLOSE in 0-RTT is permitted in draft-28.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8424
diff changeset
1098 #else
8370
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1099 /* CONNECTION_CLOSE */ 0xD,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1100 /* CONNECTION_CLOSE2 */ 0x1,
8425
3e38dad3a163 Receipt of CONNECTION_CLOSE in 0-RTT is permitted in draft-28.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8424
diff changeset
1101 #endif
8370
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1102 /* HANDSHAKE_DONE */ 0x0, /* only sent by server */
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1103 };
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1104
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1105 if (ngx_quic_long_pkt(pkt->flags)) {
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1106
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1107 if (ngx_quic_pkt_in(pkt->flags)) {
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1108 ptype = 8; /* initial */
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1109
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1110 } else if (ngx_quic_pkt_hs(pkt->flags)) {
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1111 ptype = 4; /* handshake */
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1112
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1113 } else {
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1114 ptype = 2; /* zero-rtt */
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1115 }
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1116
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1117 } else {
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1118 ptype = 1; /* application data */
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1119 }
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1120
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1121 if (ptype & ngx_quic_frame_masks[frame_type]) {
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1122 return NGX_OK;
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1123 }
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1124
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1125 ngx_log_error(NGX_LOG_INFO, pkt->log, 0,
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1126 "quic frame type 0x%xi is not "
8478
d2f716e668e8 Fixed format specifiers.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8470
diff changeset
1127 "allowed in packet with flags 0x%xd",
8370
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1128 frame_type, pkt->flags);
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1129
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1130 return NGX_DECLINED;
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1131 }
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1132
262396242352 Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents: 8361
diff changeset
1133
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1134 ssize_t
8604
b3d9e57d0f62 QUIC: single function for frame debug logging.
Vladimir Homutov <vl@nginx.com>
parents: 8596
diff changeset
1135 ngx_quic_parse_ack_range(ngx_log_t *log, u_char *start, u_char *end,
8326
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
1136 uint64_t *gap, uint64_t *range)
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
1137 {
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
1138 u_char *p;
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
1139
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
1140 p = start;
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
1141
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
1142 p = ngx_quic_parse_int(p, end, gap);
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
1143 if (p == NULL) {
8604
b3d9e57d0f62 QUIC: single function for frame debug logging.
Vladimir Homutov <vl@nginx.com>
parents: 8596
diff changeset
1144 ngx_log_error(NGX_LOG_INFO, log, 0,
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
1145 "quic failed to parse ack frame gap");
8326
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
1146 return NGX_ERROR;
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
1147 }
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
1148
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
1149 p = ngx_quic_parse_int(p, end, range);
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
1150 if (p == NULL) {
8604
b3d9e57d0f62 QUIC: single function for frame debug logging.
Vladimir Homutov <vl@nginx.com>
parents: 8596
diff changeset
1151 ngx_log_error(NGX_LOG_INFO, log, 0,
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
1152 "quic failed to parse ack frame range");
8326
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
1153 return NGX_ERROR;
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
1154 }
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
1155
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
1156 return p - start;
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
1157 }
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
1158
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
1159
8613
867c189f875d QUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan <arut@nginx.com>
parents: 8609
diff changeset
1160 size_t
867c189f875d QUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan <arut@nginx.com>
parents: 8609
diff changeset
1161 ngx_quic_create_ack_range(u_char *p, uint64_t gap, uint64_t range)
867c189f875d QUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan <arut@nginx.com>
parents: 8609
diff changeset
1162 {
867c189f875d QUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan <arut@nginx.com>
parents: 8609
diff changeset
1163 size_t len;
867c189f875d QUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan <arut@nginx.com>
parents: 8609
diff changeset
1164 u_char *start;
867c189f875d QUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan <arut@nginx.com>
parents: 8609
diff changeset
1165
867c189f875d QUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan <arut@nginx.com>
parents: 8609
diff changeset
1166 if (p == NULL) {
867c189f875d QUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan <arut@nginx.com>
parents: 8609
diff changeset
1167 len = ngx_quic_varint_len(gap);
867c189f875d QUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan <arut@nginx.com>
parents: 8609
diff changeset
1168 len += ngx_quic_varint_len(range);
867c189f875d QUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan <arut@nginx.com>
parents: 8609
diff changeset
1169 return len;
867c189f875d QUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan <arut@nginx.com>
parents: 8609
diff changeset
1170 }
867c189f875d QUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan <arut@nginx.com>
parents: 8609
diff changeset
1171
867c189f875d QUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan <arut@nginx.com>
parents: 8609
diff changeset
1172 start = p;
867c189f875d QUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan <arut@nginx.com>
parents: 8609
diff changeset
1173
867c189f875d QUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan <arut@nginx.com>
parents: 8609
diff changeset
1174 ngx_quic_build_int(&p, gap);
867c189f875d QUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan <arut@nginx.com>
parents: 8609
diff changeset
1175 ngx_quic_build_int(&p, range);
867c189f875d QUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan <arut@nginx.com>
parents: 8609
diff changeset
1176
867c189f875d QUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan <arut@nginx.com>
parents: 8609
diff changeset
1177 return p - start;
867c189f875d QUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan <arut@nginx.com>
parents: 8609
diff changeset
1178 }
867c189f875d QUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan <arut@nginx.com>
parents: 8609
diff changeset
1179
867c189f875d QUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan <arut@nginx.com>
parents: 8609
diff changeset
1180
8326
1cdd53532309 ACK ranges processing.
Vladimir Homutov <vl@nginx.com>
parents: 8323
diff changeset
1181 ssize_t
8308
e10b4c61420f Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents: 8307
diff changeset
1182 ngx_quic_create_frame(u_char *p, ngx_quic_frame_t *f)
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1183 {
8308
e10b4c61420f Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents: 8307
diff changeset
1184 /*
e10b4c61420f Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents: 8307
diff changeset
1185 * QUIC-recovery, section 2:
e10b4c61420f Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents: 8307
diff changeset
1186 *
e10b4c61420f Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents: 8307
diff changeset
1187 * Ack-eliciting Frames: All frames other than ACK, PADDING, and
e10b4c61420f Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents: 8307
diff changeset
1188 * CONNECTION_CLOSE are considered ack-eliciting.
e10b4c61420f Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents: 8307
diff changeset
1189 */
e10b4c61420f Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents: 8307
diff changeset
1190 f->need_ack = 1;
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1191
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1192 switch (f->type) {
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1193 case NGX_QUIC_FT_ACK:
8308
e10b4c61420f Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents: 8307
diff changeset
1194 f->need_ack = 0;
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1195 return ngx_quic_create_ack(p, &f->u.ack);
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1196
8528
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1197 case NGX_QUIC_FT_STOP_SENDING:
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1198 return ngx_quic_create_stop_sending(p, &f->u.stop_sending);
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1199
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1200 case NGX_QUIC_FT_CRYPTO:
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1201 return ngx_quic_create_crypto(p, &f->u.crypto);
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1202
8273
cb75f194f1f0 Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents: 8269
diff changeset
1203 case NGX_QUIC_FT_HANDSHAKE_DONE:
cb75f194f1f0 Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents: 8269
diff changeset
1204 return ngx_quic_create_hs_done(p);
cb75f194f1f0 Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents: 8269
diff changeset
1205
8384
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1206 case NGX_QUIC_FT_NEW_TOKEN:
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1207 return ngx_quic_create_new_token(p, &f->u.token);
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1208
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1209 case NGX_QUIC_FT_STREAM0:
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1210 case NGX_QUIC_FT_STREAM1:
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1211 case NGX_QUIC_FT_STREAM2:
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1212 case NGX_QUIC_FT_STREAM3:
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1213 case NGX_QUIC_FT_STREAM4:
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1214 case NGX_QUIC_FT_STREAM5:
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1215 case NGX_QUIC_FT_STREAM6:
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1216 case NGX_QUIC_FT_STREAM7:
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1217 return ngx_quic_create_stream(p, &f->u.stream);
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1218
8235
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
1219 case NGX_QUIC_FT_CONNECTION_CLOSE:
8458
e0f92f68e018 QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents: 8447
diff changeset
1220 case NGX_QUIC_FT_CONNECTION_CLOSE_APP:
8308
e10b4c61420f Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents: 8307
diff changeset
1221 f->need_ack = 0;
8235
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
1222 return ngx_quic_create_close(p, &f->u.close);
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
1223
8245
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1224 case NGX_QUIC_FT_MAX_STREAMS:
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1225 return ngx_quic_create_max_streams(p, &f->u.max_streams);
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1226
8266
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1227 case NGX_QUIC_FT_MAX_STREAM_DATA:
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1228 return ngx_quic_create_max_stream_data(p, &f->u.max_stream_data);
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1229
8338
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
1230 case NGX_QUIC_FT_MAX_DATA:
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
1231 return ngx_quic_create_max_data(p, &f->u.max_data);
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
1232
8531
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
1233 case NGX_QUIC_FT_PATH_RESPONSE:
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
1234 return ngx_quic_create_path_response(p, &f->u.path_response);
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
1235
8628
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1236 case NGX_QUIC_FT_NEW_CONNECTION_ID:
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1237 return ngx_quic_create_new_connection_id(p, &f->u.ncid);
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1238
8538
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
1239 case NGX_QUIC_FT_RETIRE_CONNECTION_ID:
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
1240 return ngx_quic_create_retire_connection_id(p, &f->u.retire_cid);
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
1241
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1242 default:
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1243 /* BUG: unsupported frame type generated */
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1244 return NGX_ERROR;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1245 }
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1246 }
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1247
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1248
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1249 static size_t
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1250 ngx_quic_create_ack(u_char *p, ngx_quic_ack_frame_t *ack)
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1251 {
8613
867c189f875d QUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan <arut@nginx.com>
parents: 8609
diff changeset
1252 size_t len;
867c189f875d QUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan <arut@nginx.com>
parents: 8609
diff changeset
1253 u_char *start;
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1254
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1255 if (p == NULL) {
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1256 len = ngx_quic_varint_len(NGX_QUIC_FT_ACK);
8308
e10b4c61420f Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents: 8307
diff changeset
1257 len += ngx_quic_varint_len(ack->largest);
8470
0d1ad81dd65c QUIC: delay field of an ACK frame is now calculated.
Vladimir Homutov <vl@nginx.com>
parents: 8458
diff changeset
1258 len += ngx_quic_varint_len(ack->delay);
8596
38c7dd720774 QUIC: added ACK frame range support.
Vladimir Homutov <vl@nginx.com>
parents: 8594
diff changeset
1259 len += ngx_quic_varint_len(ack->range_count);
8308
e10b4c61420f Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents: 8307
diff changeset
1260 len += ngx_quic_varint_len(ack->first_range);
8613
867c189f875d QUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan <arut@nginx.com>
parents: 8609
diff changeset
1261 len += ack->ranges_end - ack->ranges_start;
8596
38c7dd720774 QUIC: added ACK frame range support.
Vladimir Homutov <vl@nginx.com>
parents: 8594
diff changeset
1262
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1263 return len;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1264 }
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1265
8244
d60205f37f5a Fixed ACKs to packet numbers greater than 63.
Roman Arutyunyan <arut@nginx.com>
parents: 8243
diff changeset
1266 start = p;
d60205f37f5a Fixed ACKs to packet numbers greater than 63.
Roman Arutyunyan <arut@nginx.com>
parents: 8243
diff changeset
1267
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1268 ngx_quic_build_int(&p, NGX_QUIC_FT_ACK);
8308
e10b4c61420f Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents: 8307
diff changeset
1269 ngx_quic_build_int(&p, ack->largest);
8470
0d1ad81dd65c QUIC: delay field of an ACK frame is now calculated.
Vladimir Homutov <vl@nginx.com>
parents: 8458
diff changeset
1270 ngx_quic_build_int(&p, ack->delay);
8596
38c7dd720774 QUIC: added ACK frame range support.
Vladimir Homutov <vl@nginx.com>
parents: 8594
diff changeset
1271 ngx_quic_build_int(&p, ack->range_count);
8308
e10b4c61420f Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents: 8307
diff changeset
1272 ngx_quic_build_int(&p, ack->first_range);
8613
867c189f875d QUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan <arut@nginx.com>
parents: 8609
diff changeset
1273 p = ngx_cpymem(p, ack->ranges_start, ack->ranges_end - ack->ranges_start);
8596
38c7dd720774 QUIC: added ACK frame range support.
Vladimir Homutov <vl@nginx.com>
parents: 8594
diff changeset
1274
8244
d60205f37f5a Fixed ACKs to packet numbers greater than 63.
Roman Arutyunyan <arut@nginx.com>
parents: 8243
diff changeset
1275 return p - start;
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1276 }
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1277
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1278
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1279 static size_t
8528
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1280 ngx_quic_create_stop_sending(u_char *p, ngx_quic_stop_sending_frame_t *ss)
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1281 {
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1282 size_t len;
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1283 u_char *start;
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1284
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1285 if (p == NULL) {
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1286 len = ngx_quic_varint_len(NGX_QUIC_FT_STOP_SENDING);
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1287 len += ngx_quic_varint_len(ss->id);
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1288 len += ngx_quic_varint_len(ss->error_code);
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1289 return len;
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1290 }
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1291
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1292 start = p;
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1293
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1294 ngx_quic_build_int(&p, NGX_QUIC_FT_STOP_SENDING);
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1295 ngx_quic_build_int(&p, ss->id);
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1296 ngx_quic_build_int(&p, ss->error_code);
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1297
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1298 return p - start;
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1299 }
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1300
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1301
97da6521657c QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents: 8525
diff changeset
1302 static size_t
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1303 ngx_quic_create_crypto(u_char *p, ngx_quic_crypto_frame_t *crypto)
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1304 {
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1305 size_t len;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1306 u_char *start;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1307
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1308 if (p == NULL) {
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1309 len = ngx_quic_varint_len(NGX_QUIC_FT_CRYPTO);
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1310 len += ngx_quic_varint_len(crypto->offset);
8333
167d32476737 Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents: 8326
diff changeset
1311 len += ngx_quic_varint_len(crypto->length);
167d32476737 Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents: 8326
diff changeset
1312 len += crypto->length;
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1313
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1314 return len;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1315 }
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1316
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1317 start = p;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1318
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1319 ngx_quic_build_int(&p, NGX_QUIC_FT_CRYPTO);
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1320 ngx_quic_build_int(&p, crypto->offset);
8333
167d32476737 Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents: 8326
diff changeset
1321 ngx_quic_build_int(&p, crypto->length);
167d32476737 Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents: 8326
diff changeset
1322 p = ngx_cpymem(p, crypto->data, crypto->length);
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1323
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1324 return p - start;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1325 }
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1326
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1327
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1328 static size_t
8273
cb75f194f1f0 Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents: 8269
diff changeset
1329 ngx_quic_create_hs_done(u_char *p)
cb75f194f1f0 Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents: 8269
diff changeset
1330 {
cb75f194f1f0 Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents: 8269
diff changeset
1331 u_char *start;
cb75f194f1f0 Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents: 8269
diff changeset
1332
cb75f194f1f0 Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents: 8269
diff changeset
1333 if (p == NULL) {
cb75f194f1f0 Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents: 8269
diff changeset
1334 return ngx_quic_varint_len(NGX_QUIC_FT_HANDSHAKE_DONE);
cb75f194f1f0 Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents: 8269
diff changeset
1335 }
cb75f194f1f0 Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents: 8269
diff changeset
1336
cb75f194f1f0 Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents: 8269
diff changeset
1337 start = p;
cb75f194f1f0 Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents: 8269
diff changeset
1338
cb75f194f1f0 Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents: 8269
diff changeset
1339 ngx_quic_build_int(&p, NGX_QUIC_FT_HANDSHAKE_DONE);
cb75f194f1f0 Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents: 8269
diff changeset
1340
cb75f194f1f0 Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents: 8269
diff changeset
1341 return p - start;
cb75f194f1f0 Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents: 8269
diff changeset
1342 }
cb75f194f1f0 Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents: 8269
diff changeset
1343
cb75f194f1f0 Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents: 8269
diff changeset
1344
cb75f194f1f0 Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents: 8269
diff changeset
1345 static size_t
8384
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1346 ngx_quic_create_new_token(u_char *p, ngx_quic_new_token_frame_t *token)
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1347 {
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1348 size_t len;
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1349 u_char *start;
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1350
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1351 if (p == NULL) {
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1352 len = ngx_quic_varint_len(NGX_QUIC_FT_NEW_TOKEN);
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1353 len += ngx_quic_varint_len(token->length);
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1354 len += token->length;
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1355
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1356 return len;
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1357 }
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1358
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1359 start = p;
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1360
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1361 ngx_quic_build_int(&p, NGX_QUIC_FT_NEW_TOKEN);
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1362 ngx_quic_build_int(&p, token->length);
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1363 p = ngx_cpymem(p, token->data, token->length);
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1364
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1365 return p - start;
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1366 }
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1367
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1368
52d0c4832570 Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8383
diff changeset
1369 static size_t
8224
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1370 ngx_quic_create_stream(u_char *p, ngx_quic_stream_frame_t *sf)
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1371 {
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1372 size_t len;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1373 u_char *start;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1374
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1375 if (p == NULL) {
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1376 len = ngx_quic_varint_len(sf->type);
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1377
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1378 if (sf->off) {
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1379 len += ngx_quic_varint_len(sf->offset);
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1380 }
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1381
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1382 len += ngx_quic_varint_len(sf->stream_id);
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1383
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1384 /* length is always present in generated frames */
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1385 len += ngx_quic_varint_len(sf->length);
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1386
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1387 len += sf->length;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1388
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1389 return len;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1390 }
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1391
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1392 start = p;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1393
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1394 ngx_quic_build_int(&p, sf->type);
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1395 ngx_quic_build_int(&p, sf->stream_id);
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1396
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1397 if (sf->off) {
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1398 ngx_quic_build_int(&p, sf->offset);
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1399 }
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1400
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1401 /* length is always present in generated frames */
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1402 ngx_quic_build_int(&p, sf->length);
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1403
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1404 p = ngx_cpymem(p, sf->data, sf->length);
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1405
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1406 return p - start;
ae35ccba7aa6 Extracted transport part of the code into separate file.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1407 }
8235
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
1408
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
1409
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
1410 static size_t
8245
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1411 ngx_quic_create_max_streams(u_char *p, ngx_quic_max_streams_frame_t *ms)
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1412 {
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1413 size_t len;
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1414 u_char *start;
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1415 ngx_uint_t type;
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1416
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1417 type = ms->bidi ? NGX_QUIC_FT_MAX_STREAMS : NGX_QUIC_FT_MAX_STREAMS2;
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1418
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1419 if (p == NULL) {
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1420 len = ngx_quic_varint_len(type);
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1421 len += ngx_quic_varint_len(ms->limit);
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1422 return len;
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1423 }
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1424
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1425 start = p;
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1426
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1427 ngx_quic_build_int(&p, type);
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1428 ngx_quic_build_int(&p, ms->limit);
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1429
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1430 return p - start;
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1431 }
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1432
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1433
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1434 static ngx_int_t
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1435 ngx_quic_parse_transport_param(u_char *p, u_char *end, uint16_t id,
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1436 ngx_quic_tp_t *dst)
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1437 {
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1438 uint64_t varint;
8417
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1439 ngx_str_t str;
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1440
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1441 varint = 0;
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1442 ngx_str_null(&str);
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1443
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1444 switch (id) {
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1445
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1446 case NGX_QUIC_TP_DISABLE_ACTIVE_MIGRATION:
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1447 /* zero-length option */
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1448 if (end - p != 0) {
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1449 return NGX_ERROR;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1450 }
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1451 dst->disable_active_migration = 1;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1452 return NGX_OK;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1453
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1454 case NGX_QUIC_TP_MAX_IDLE_TIMEOUT:
8415
125cbfa77013 Renamed max_packet_size to max_udp_payload_size, from draft-28.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8414
diff changeset
1455 case NGX_QUIC_TP_MAX_UDP_PAYLOAD_SIZE:
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1456 case NGX_QUIC_TP_INITIAL_MAX_DATA:
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1457 case NGX_QUIC_TP_INITIAL_MAX_STREAM_DATA_BIDI_LOCAL:
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1458 case NGX_QUIC_TP_INITIAL_MAX_STREAM_DATA_BIDI_REMOTE:
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1459 case NGX_QUIC_TP_INITIAL_MAX_STREAM_DATA_UNI:
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1460 case NGX_QUIC_TP_INITIAL_MAX_STREAMS_BIDI:
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1461 case NGX_QUIC_TP_INITIAL_MAX_STREAMS_UNI:
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1462 case NGX_QUIC_TP_ACK_DELAY_EXPONENT:
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1463 case NGX_QUIC_TP_MAX_ACK_DELAY:
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1464 case NGX_QUIC_TP_ACTIVE_CONNECTION_ID_LIMIT:
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1465
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1466 p = ngx_quic_parse_int(p, end, &varint);
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1467 if (p == NULL) {
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1468 return NGX_ERROR;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1469 }
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1470 break;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1471
8417
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1472 case NGX_QUIC_TP_INITIAL_SCID:
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1473
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1474 str.len = end - p;
8582
b95aa1cb8f98 QUIC: fixed dead store assignment.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8569
diff changeset
1475 str.data = p;
8417
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1476 break;
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1477
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1478 default:
8262
66f59c67adf4 Skip unknown transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8261
diff changeset
1479 return NGX_DECLINED;
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1480 }
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1481
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1482 switch (id) {
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1483
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1484 case NGX_QUIC_TP_MAX_IDLE_TIMEOUT:
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1485 dst->max_idle_timeout = varint;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1486 break;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1487
8415
125cbfa77013 Renamed max_packet_size to max_udp_payload_size, from draft-28.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8414
diff changeset
1488 case NGX_QUIC_TP_MAX_UDP_PAYLOAD_SIZE:
125cbfa77013 Renamed max_packet_size to max_udp_payload_size, from draft-28.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8414
diff changeset
1489 dst->max_udp_payload_size = varint;
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1490 break;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1491
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1492 case NGX_QUIC_TP_INITIAL_MAX_DATA:
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1493 dst->initial_max_data = varint;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1494 break;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1495
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1496 case NGX_QUIC_TP_INITIAL_MAX_STREAM_DATA_BIDI_LOCAL:
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1497 dst->initial_max_stream_data_bidi_local = varint;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1498 break;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1499
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1500 case NGX_QUIC_TP_INITIAL_MAX_STREAM_DATA_BIDI_REMOTE:
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1501 dst->initial_max_stream_data_bidi_remote = varint;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1502 break;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1503
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1504 case NGX_QUIC_TP_INITIAL_MAX_STREAM_DATA_UNI:
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1505 dst->initial_max_stream_data_uni = varint;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1506 break;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1507
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1508 case NGX_QUIC_TP_INITIAL_MAX_STREAMS_BIDI:
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1509 dst->initial_max_streams_bidi = varint;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1510 break;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1511
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1512 case NGX_QUIC_TP_INITIAL_MAX_STREAMS_UNI:
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1513 dst->initial_max_streams_uni = varint;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1514 break;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1515
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1516 case NGX_QUIC_TP_ACK_DELAY_EXPONENT:
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1517 dst->ack_delay_exponent = varint;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1518 break;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1519
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1520 case NGX_QUIC_TP_MAX_ACK_DELAY:
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1521 dst->max_ack_delay = varint;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1522 break;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1523
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1524 case NGX_QUIC_TP_ACTIVE_CONNECTION_ID_LIMIT:
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1525 dst->active_connection_id_limit = varint;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1526 break;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1527
8417
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1528 case NGX_QUIC_TP_INITIAL_SCID:
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1529 dst->initial_scid = str;
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1530 break;
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1531
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1532 default:
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1533 return NGX_ERROR;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1534 }
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1535
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1536 return NGX_OK;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1537 }
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1538
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1539
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1540 ngx_int_t
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1541 ngx_quic_parse_transport_params(u_char *p, u_char *end, ngx_quic_tp_t *tp,
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1542 ngx_log_t *log)
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1543 {
8356
42198f77ac85 Removed support of drafts older than currently latest 27.
Vladimir Homutov <vl@nginx.com>
parents: 8351
diff changeset
1544 uint64_t id, len;
8262
66f59c67adf4 Skip unknown transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8261
diff changeset
1545 ngx_int_t rc;
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1546
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1547 while (p < end) {
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1548 p = ngx_quic_parse_int(p, end, &id);
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1549 if (p == NULL) {
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1550 ngx_log_error(NGX_LOG_INFO, log, 0,
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
1551 "quic failed to parse transport param id");
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1552 return NGX_ERROR;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1553 }
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1554
8414
49a98760afd2 Rejected forbidden transport parameters with TRANSPORT_PARAMETER_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8391
diff changeset
1555 switch (id) {
8417
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1556 case NGX_QUIC_TP_ORIGINAL_DCID:
8414
49a98760afd2 Rejected forbidden transport parameters with TRANSPORT_PARAMETER_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8391
diff changeset
1557 case NGX_QUIC_TP_PREFERRED_ADDRESS:
8417
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1558 case NGX_QUIC_TP_RETRY_SCID:
8562
b31c02454539 QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents: 8560
diff changeset
1559 case NGX_QUIC_TP_SR_TOKEN:
8414
49a98760afd2 Rejected forbidden transport parameters with TRANSPORT_PARAMETER_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8391
diff changeset
1560 ngx_log_error(NGX_LOG_INFO, log, 0,
49a98760afd2 Rejected forbidden transport parameters with TRANSPORT_PARAMETER_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8391
diff changeset
1561 "quic client sent forbidden transport param"
8605
eed49b83e18f QUIC: revised value separators in debug and error messages.
Vladimir Homutov <vl@nginx.com>
parents: 8604
diff changeset
1562 " id:0x%xL", id);
8414
49a98760afd2 Rejected forbidden transport parameters with TRANSPORT_PARAMETER_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8391
diff changeset
1563 return NGX_ERROR;
49a98760afd2 Rejected forbidden transport parameters with TRANSPORT_PARAMETER_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8391
diff changeset
1564 }
49a98760afd2 Rejected forbidden transport parameters with TRANSPORT_PARAMETER_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8391
diff changeset
1565
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1566 p = ngx_quic_parse_int(p, end, &len);
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1567 if (p == NULL) {
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1568 ngx_log_error(NGX_LOG_INFO, log, 0,
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
1569 "quic failed to parse"
8605
eed49b83e18f QUIC: revised value separators in debug and error messages.
Vladimir Homutov <vl@nginx.com>
parents: 8604
diff changeset
1570 " transport param id:0x%xL length", id);
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1571 return NGX_ERROR;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1572 }
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1573
8262
66f59c67adf4 Skip unknown transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8261
diff changeset
1574 rc = ngx_quic_parse_transport_param(p, p + len, id, tp);
66f59c67adf4 Skip unknown transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8261
diff changeset
1575
66f59c67adf4 Skip unknown transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8261
diff changeset
1576 if (rc == NGX_ERROR) {
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1577 ngx_log_error(NGX_LOG_INFO, log, 0,
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
1578 "quic failed to parse"
8605
eed49b83e18f QUIC: revised value separators in debug and error messages.
Vladimir Homutov <vl@nginx.com>
parents: 8604
diff changeset
1579 " transport param id:0x%xL data", id);
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1580 return NGX_ERROR;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1581 }
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1582
8262
66f59c67adf4 Skip unknown transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8261
diff changeset
1583 if (rc == NGX_DECLINED) {
66f59c67adf4 Skip unknown transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8261
diff changeset
1584 ngx_log_error(NGX_LOG_INFO, log, 0,
8605
eed49b83e18f QUIC: revised value separators in debug and error messages.
Vladimir Homutov <vl@nginx.com>
parents: 8604
diff changeset
1585 "quic unknown transport param id:0x%xL, skipped", id);
8262
66f59c67adf4 Skip unknown transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8261
diff changeset
1586 }
66f59c67adf4 Skip unknown transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8261
diff changeset
1587
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1588 p += len;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1589 }
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1590
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1591 if (p != end) {
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1592 ngx_log_error(NGX_LOG_INFO, log, 0,
8361
336d527ca031 Error messages cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8360
diff changeset
1593 "quic trailing garbage in"
8605
eed49b83e18f QUIC: revised value separators in debug and error messages.
Vladimir Homutov <vl@nginx.com>
parents: 8604
diff changeset
1594 " transport parameters: bytes:%ui",
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1595 end - p);
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1596 return NGX_ERROR;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1597 }
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1598
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1599 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, log, 0,
8359
2f900ae486bc Debug cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8358
diff changeset
1600 "quic transport parameters parsed ok");
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1601
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1602 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0,
8359
2f900ae486bc Debug cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8358
diff changeset
1603 "quic tp disable active migration: %ui",
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1604 tp->disable_active_migration);
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1605
8605
eed49b83e18f QUIC: revised value separators in debug and error messages.
Vladimir Homutov <vl@nginx.com>
parents: 8604
diff changeset
1606 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0, "quic tp idle_timeout:%ui",
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1607 tp->max_idle_timeout);
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1608
8415
125cbfa77013 Renamed max_packet_size to max_udp_payload_size, from draft-28.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8414
diff changeset
1609 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0,
8605
eed49b83e18f QUIC: revised value separators in debug and error messages.
Vladimir Homutov <vl@nginx.com>
parents: 8604
diff changeset
1610 "quic tp max_udp_payload_size:%ui",
8415
125cbfa77013 Renamed max_packet_size to max_udp_payload_size, from draft-28.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8414
diff changeset
1611 tp->max_udp_payload_size);
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1612
8605
eed49b83e18f QUIC: revised value separators in debug and error messages.
Vladimir Homutov <vl@nginx.com>
parents: 8604
diff changeset
1613 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0, "quic tp max_data:%ui",
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1614 tp->initial_max_data);
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1615
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1616 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0,
8605
eed49b83e18f QUIC: revised value separators in debug and error messages.
Vladimir Homutov <vl@nginx.com>
parents: 8604
diff changeset
1617 "quic tp max_stream_data_bidi_local:%ui",
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1618 tp->initial_max_stream_data_bidi_local);
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1619
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1620 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0,
8605
eed49b83e18f QUIC: revised value separators in debug and error messages.
Vladimir Homutov <vl@nginx.com>
parents: 8604
diff changeset
1621 "quic tp max_stream_data_bidi_remote:%ui",
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1622 tp->initial_max_stream_data_bidi_remote);
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1623
8359
2f900ae486bc Debug cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8358
diff changeset
1624 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0,
8605
eed49b83e18f QUIC: revised value separators in debug and error messages.
Vladimir Homutov <vl@nginx.com>
parents: 8604
diff changeset
1625 "quic tp max_stream_data_uni:%ui",
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1626 tp->initial_max_stream_data_uni);
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1627
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1628 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0,
8605
eed49b83e18f QUIC: revised value separators in debug and error messages.
Vladimir Homutov <vl@nginx.com>
parents: 8604
diff changeset
1629 "quic tp initial_max_streams_bidi:%ui",
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1630 tp->initial_max_streams_bidi);
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1631
8359
2f900ae486bc Debug cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8358
diff changeset
1632 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0,
8605
eed49b83e18f QUIC: revised value separators in debug and error messages.
Vladimir Homutov <vl@nginx.com>
parents: 8604
diff changeset
1633 "quic tp initial_max_streams_uni:%ui",
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1634 tp->initial_max_streams_uni);
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1635
8359
2f900ae486bc Debug cleanup.
Vladimir Homutov <vl@nginx.com>
parents: 8358
diff changeset
1636 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0,
8605
eed49b83e18f QUIC: revised value separators in debug and error messages.
Vladimir Homutov <vl@nginx.com>
parents: 8604
diff changeset
1637 "quic tp ack_delay_exponent:%ui",
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1638 tp->ack_delay_exponent);
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1639
8605
eed49b83e18f QUIC: revised value separators in debug and error messages.
Vladimir Homutov <vl@nginx.com>
parents: 8604
diff changeset
1640 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0, "quic tp max_ack_delay:%ui",
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1641 tp->max_ack_delay);
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1642
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1643 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0,
8605
eed49b83e18f QUIC: revised value separators in debug and error messages.
Vladimir Homutov <vl@nginx.com>
parents: 8604
diff changeset
1644 "quic tp active_connection_id_limit:%ui",
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1645 tp->active_connection_id_limit);
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1646
8417
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1647 #if (NGX_QUIC_DRAFT_VERSION >= 28)
8651
dbad2d6d1898 QUIC: removed ngx_quic_hexdump() macro.
Vladimir Homutov <vl@nginx.com>
parents: 8642
diff changeset
1648 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0,
dbad2d6d1898 QUIC: removed ngx_quic_hexdump() macro.
Vladimir Homutov <vl@nginx.com>
parents: 8642
diff changeset
1649 "quic tp initial source_connection_id len:%uz %xV",
dbad2d6d1898 QUIC: removed ngx_quic_hexdump() macro.
Vladimir Homutov <vl@nginx.com>
parents: 8642
diff changeset
1650 tp->initial_scid.len, &tp->initial_scid);
8417
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1651 #endif
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1652
8260
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1653 return NGX_OK;
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1654 }
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1655
f388c0ad3477 Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8257
diff changeset
1656
8266
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1657 static size_t
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1658 ngx_quic_create_max_stream_data(u_char *p, ngx_quic_max_stream_data_frame_t *ms)
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1659 {
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1660 size_t len;
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1661 u_char *start;
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1662
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1663 if (p == NULL) {
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1664 len = ngx_quic_varint_len(NGX_QUIC_FT_MAX_STREAM_DATA);
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1665 len += ngx_quic_varint_len(ms->id);
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1666 len += ngx_quic_varint_len(ms->limit);
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1667 return len;
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1668 }
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1669
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1670 start = p;
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1671
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1672 ngx_quic_build_int(&p, NGX_QUIC_FT_MAX_STREAM_DATA);
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1673 ngx_quic_build_int(&p, ms->id);
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1674 ngx_quic_build_int(&p, ms->limit);
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1675
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1676 return p - start;
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1677 }
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1678
f92e583fc256 Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents: 8264
diff changeset
1679
8338
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
1680 static size_t
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
1681 ngx_quic_create_max_data(u_char *p, ngx_quic_max_data_frame_t *md)
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
1682 {
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
1683 size_t len;
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
1684 u_char *start;
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
1685
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
1686 if (p == NULL) {
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
1687 len = ngx_quic_varint_len(NGX_QUIC_FT_MAX_DATA);
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
1688 len += ngx_quic_varint_len(md->max_data);
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
1689 return len;
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
1690 }
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
1691
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
1692 start = p;
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
1693
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
1694 ngx_quic_build_int(&p, NGX_QUIC_FT_MAX_DATA);
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
1695 ngx_quic_build_int(&p, md->max_data);
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
1696
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
1697 return p - start;
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
1698 }
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
1699
0f9e9786b90d Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents: 8333
diff changeset
1700
8531
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
1701 static size_t
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
1702 ngx_quic_create_path_response(u_char *p, ngx_quic_path_challenge_frame_t *pc)
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
1703 {
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
1704 size_t len;
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
1705 u_char *start;
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
1706
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
1707 if (p == NULL) {
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
1708 len = ngx_quic_varint_len(NGX_QUIC_FT_PATH_RESPONSE);
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
1709 len += sizeof(pc->data);
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
1710 return len;
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
1711 }
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
1712
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
1713 start = p;
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
1714
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
1715 ngx_quic_build_int(&p, NGX_QUIC_FT_PATH_RESPONSE);
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
1716 p = ngx_cpymem(p, &pc->data, sizeof(pc->data));
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
1717
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
1718 return p - start;
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
1719 }
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
1720
4ff2a0b747d1 QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents: 8528
diff changeset
1721
8538
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
1722 static size_t
8628
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1723 ngx_quic_create_new_connection_id(u_char *p, ngx_quic_new_conn_id_frame_t *ncid)
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1724 {
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1725 size_t len;
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1726 u_char *start;
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1727
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1728 if (p == NULL) {
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1729 len = ngx_quic_varint_len(NGX_QUIC_FT_NEW_CONNECTION_ID);
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1730 len += ngx_quic_varint_len(ncid->seqnum);
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1731 len += ngx_quic_varint_len(ncid->retire);
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1732 len++;
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1733 len += ncid->len;
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1734 len += NGX_QUIC_SR_TOKEN_LEN;
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1735 return len;
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1736 }
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1737
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1738 start = p;
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1739
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1740 ngx_quic_build_int(&p, NGX_QUIC_FT_NEW_CONNECTION_ID);
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1741 ngx_quic_build_int(&p, ncid->seqnum);
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1742 ngx_quic_build_int(&p, ncid->retire);
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1743 *p++ = ncid->len;
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1744 p = ngx_cpymem(p, ncid->cid, ncid->len);
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1745 p = ngx_cpymem(p, ncid->srt, NGX_QUIC_SR_TOKEN_LEN);
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1746
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1747 return p - start;
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1748 }
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1749
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1750
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1751 static size_t
8538
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
1752 ngx_quic_create_retire_connection_id(u_char *p,
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
1753 ngx_quic_retire_cid_frame_t *rcid)
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
1754 {
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
1755 size_t len;
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
1756 u_char *start;
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
1757
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
1758 if (p == NULL) {
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
1759 len = ngx_quic_varint_len(NGX_QUIC_FT_RETIRE_CONNECTION_ID);
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
1760 len += ngx_quic_varint_len(rcid->sequence_number);
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
1761 return len;
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
1762 }
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
1763
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
1764 start = p;
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
1765
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
1766 ngx_quic_build_int(&p, NGX_QUIC_FT_RETIRE_CONNECTION_ID);
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
1767 ngx_quic_build_int(&p, rcid->sequence_number);
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
1768
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
1769 return p - start;
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
1770 }
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
1771
3afaaaa930ab QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents: 8537
diff changeset
1772
8247
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1773 ssize_t
8422
90b02ff6b003 Compatibility with BoringSSL master branch.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8421
diff changeset
1774 ngx_quic_create_transport_params(u_char *pos, u_char *end, ngx_quic_tp_t *tp,
90b02ff6b003 Compatibility with BoringSSL master branch.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8421
diff changeset
1775 size_t *clen)
8247
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1776 {
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1777 u_char *p;
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1778 size_t len;
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1779
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1780 #define ngx_quic_tp_len(id, value) \
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1781 ngx_quic_varint_len(id) \
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1782 + ngx_quic_varint_len(value) \
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1783 + ngx_quic_varint_len(ngx_quic_varint_len(value))
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1784
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1785 #define ngx_quic_tp_vint(id, value) \
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1786 do { \
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1787 ngx_quic_build_int(&p, id); \
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1788 ngx_quic_build_int(&p, ngx_quic_varint_len(value)); \
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1789 ngx_quic_build_int(&p, value); \
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1790 } while (0)
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1791
8416
78e362f0b081 Introduced macros for building length-value transport parameters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8415
diff changeset
1792 #define ngx_quic_tp_strlen(id, value) \
78e362f0b081 Introduced macros for building length-value transport parameters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8415
diff changeset
1793 ngx_quic_varint_len(id) \
78e362f0b081 Introduced macros for building length-value transport parameters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8415
diff changeset
1794 + ngx_quic_varint_len(value.len) \
78e362f0b081 Introduced macros for building length-value transport parameters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8415
diff changeset
1795 + value.len
78e362f0b081 Introduced macros for building length-value transport parameters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8415
diff changeset
1796
78e362f0b081 Introduced macros for building length-value transport parameters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8415
diff changeset
1797 #define ngx_quic_tp_str(id, value) \
78e362f0b081 Introduced macros for building length-value transport parameters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8415
diff changeset
1798 do { \
78e362f0b081 Introduced macros for building length-value transport parameters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8415
diff changeset
1799 ngx_quic_build_int(&p, id); \
78e362f0b081 Introduced macros for building length-value transport parameters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8415
diff changeset
1800 ngx_quic_build_int(&p, value.len); \
78e362f0b081 Introduced macros for building length-value transport parameters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8415
diff changeset
1801 p = ngx_cpymem(p, value.data, value.len); \
78e362f0b081 Introduced macros for building length-value transport parameters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8415
diff changeset
1802 } while (0)
78e362f0b081 Introduced macros for building length-value transport parameters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8415
diff changeset
1803
8247
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1804 p = pos;
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1805
8422
90b02ff6b003 Compatibility with BoringSSL master branch.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8421
diff changeset
1806 len = ngx_quic_tp_len(NGX_QUIC_TP_INITIAL_MAX_DATA, tp->initial_max_data);
8247
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1807
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1808 len += ngx_quic_tp_len(NGX_QUIC_TP_INITIAL_MAX_STREAMS_UNI,
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1809 tp->initial_max_streams_uni);
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1810
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1811 len += ngx_quic_tp_len(NGX_QUIC_TP_INITIAL_MAX_STREAMS_BIDI,
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1812 tp->initial_max_streams_bidi);
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1813
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1814 len += ngx_quic_tp_len(NGX_QUIC_TP_INITIAL_MAX_STREAM_DATA_BIDI_LOCAL,
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1815 tp->initial_max_stream_data_bidi_local);
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1816
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1817 len += ngx_quic_tp_len(NGX_QUIC_TP_INITIAL_MAX_STREAM_DATA_BIDI_REMOTE,
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1818 tp->initial_max_stream_data_bidi_remote);
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1819
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1820 len += ngx_quic_tp_len(NGX_QUIC_TP_INITIAL_MAX_STREAM_DATA_UNI,
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1821 tp->initial_max_stream_data_uni);
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1822
8277
50db7ce374b7 Advertise our max_idle_timeout in transport parameters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8275
diff changeset
1823 len += ngx_quic_tp_len(NGX_QUIC_TP_MAX_IDLE_TIMEOUT,
50db7ce374b7 Advertise our max_idle_timeout in transport parameters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8275
diff changeset
1824 tp->max_idle_timeout);
50db7ce374b7 Advertise our max_idle_timeout in transport parameters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8275
diff changeset
1825
8422
90b02ff6b003 Compatibility with BoringSSL master branch.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8421
diff changeset
1826 if (clen) {
90b02ff6b003 Compatibility with BoringSSL master branch.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8421
diff changeset
1827 *clen = len;
90b02ff6b003 Compatibility with BoringSSL master branch.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8421
diff changeset
1828 }
90b02ff6b003 Compatibility with BoringSSL master branch.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8421
diff changeset
1829
8628
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1830 if (tp->disable_active_migration) {
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1831 len += ngx_quic_varint_len(NGX_QUIC_TP_DISABLE_ACTIVE_MIGRATION);
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1832 len += ngx_quic_varint_len(0);
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1833 }
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1834
8422
90b02ff6b003 Compatibility with BoringSSL master branch.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8421
diff changeset
1835 len += ngx_quic_tp_len(NGX_QUIC_TP_ACTIVE_CONNECTION_ID_LIMIT,
90b02ff6b003 Compatibility with BoringSSL master branch.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8421
diff changeset
1836 tp->active_connection_id_limit);
90b02ff6b003 Compatibility with BoringSSL master branch.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8421
diff changeset
1837
8417
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1838 #if (NGX_QUIC_DRAFT_VERSION >= 28)
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1839 len += ngx_quic_tp_strlen(NGX_QUIC_TP_ORIGINAL_DCID, tp->original_dcid);
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1840 len += ngx_quic_tp_strlen(NGX_QUIC_TP_INITIAL_SCID, tp->initial_scid);
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1841
8421
c206233d9c29 Fixed transport parameters on a new connection with a valid token.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8417
diff changeset
1842 if (tp->retry_scid.len) {
8417
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1843 len += ngx_quic_tp_strlen(NGX_QUIC_TP_RETRY_SCID, tp->retry_scid);
8421
c206233d9c29 Fixed transport parameters on a new connection with a valid token.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8417
diff changeset
1844 }
8417
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1845 #else
8421
c206233d9c29 Fixed transport parameters on a new connection with a valid token.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8417
diff changeset
1846 if (tp->original_dcid.len) {
8417
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1847 len += ngx_quic_tp_strlen(NGX_QUIC_TP_ORIGINAL_DCID, tp->original_dcid);
8421
c206233d9c29 Fixed transport parameters on a new connection with a valid token.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8417
diff changeset
1848 }
8417
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1849 #endif
8383
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
1850
8634
831d1960826f QUIC: generate default stateless reset token key.
Roman Arutyunyan <arut@nginx.com>
parents: 8628
diff changeset
1851 len += ngx_quic_varint_len(NGX_QUIC_TP_SR_TOKEN);
831d1960826f QUIC: generate default stateless reset token key.
Roman Arutyunyan <arut@nginx.com>
parents: 8628
diff changeset
1852 len += ngx_quic_varint_len(NGX_QUIC_SR_TOKEN_LEN);
831d1960826f QUIC: generate default stateless reset token key.
Roman Arutyunyan <arut@nginx.com>
parents: 8628
diff changeset
1853 len += NGX_QUIC_SR_TOKEN_LEN;
8562
b31c02454539 QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents: 8560
diff changeset
1854
8247
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1855 if (pos == NULL) {
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1856 return len;
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1857 }
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1858
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1859 ngx_quic_tp_vint(NGX_QUIC_TP_INITIAL_MAX_DATA,
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1860 tp->initial_max_data);
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1861
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1862 ngx_quic_tp_vint(NGX_QUIC_TP_INITIAL_MAX_STREAMS_UNI,
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1863 tp->initial_max_streams_uni);
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1864
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1865 ngx_quic_tp_vint(NGX_QUIC_TP_INITIAL_MAX_STREAMS_BIDI,
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1866 tp->initial_max_streams_bidi);
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1867
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1868 ngx_quic_tp_vint(NGX_QUIC_TP_INITIAL_MAX_STREAM_DATA_BIDI_LOCAL,
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1869 tp->initial_max_stream_data_bidi_local);
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1870
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1871 ngx_quic_tp_vint(NGX_QUIC_TP_INITIAL_MAX_STREAM_DATA_BIDI_REMOTE,
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1872 tp->initial_max_stream_data_bidi_remote);
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1873
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1874 ngx_quic_tp_vint(NGX_QUIC_TP_INITIAL_MAX_STREAM_DATA_UNI,
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1875 tp->initial_max_stream_data_uni);
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1876
8277
50db7ce374b7 Advertise our max_idle_timeout in transport parameters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8275
diff changeset
1877 ngx_quic_tp_vint(NGX_QUIC_TP_MAX_IDLE_TIMEOUT,
50db7ce374b7 Advertise our max_idle_timeout in transport parameters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8275
diff changeset
1878 tp->max_idle_timeout);
50db7ce374b7 Advertise our max_idle_timeout in transport parameters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8275
diff changeset
1879
8628
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1880 if (tp->disable_active_migration) {
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1881 ngx_quic_build_int(&p, NGX_QUIC_TP_DISABLE_ACTIVE_MIGRATION);
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1882 ngx_quic_build_int(&p, 0);
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1883 }
45db1b5c1706 QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents: 8625
diff changeset
1884
8422
90b02ff6b003 Compatibility with BoringSSL master branch.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8421
diff changeset
1885 ngx_quic_tp_vint(NGX_QUIC_TP_ACTIVE_CONNECTION_ID_LIMIT,
90b02ff6b003 Compatibility with BoringSSL master branch.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8421
diff changeset
1886 tp->active_connection_id_limit);
90b02ff6b003 Compatibility with BoringSSL master branch.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8421
diff changeset
1887
8417
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1888 #if (NGX_QUIC_DRAFT_VERSION >= 28)
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1889 ngx_quic_tp_str(NGX_QUIC_TP_ORIGINAL_DCID, tp->original_dcid);
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1890 ngx_quic_tp_str(NGX_QUIC_TP_INITIAL_SCID, tp->initial_scid);
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1891
8421
c206233d9c29 Fixed transport parameters on a new connection with a valid token.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8417
diff changeset
1892 if (tp->retry_scid.len) {
8417
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1893 ngx_quic_tp_str(NGX_QUIC_TP_RETRY_SCID, tp->retry_scid);
8421
c206233d9c29 Fixed transport parameters on a new connection with a valid token.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8417
diff changeset
1894 }
8417
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1895 #else
8421
c206233d9c29 Fixed transport parameters on a new connection with a valid token.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8417
diff changeset
1896 if (tp->original_dcid.len) {
8417
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1897 ngx_quic_tp_str(NGX_QUIC_TP_ORIGINAL_DCID, tp->original_dcid);
8421
c206233d9c29 Fixed transport parameters on a new connection with a valid token.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8417
diff changeset
1898 }
8417
6633f17044eb QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8416
diff changeset
1899 #endif
8383
7ea34e13937f Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8370
diff changeset
1900
8634
831d1960826f QUIC: generate default stateless reset token key.
Roman Arutyunyan <arut@nginx.com>
parents: 8628
diff changeset
1901 ngx_quic_build_int(&p, NGX_QUIC_TP_SR_TOKEN);
831d1960826f QUIC: generate default stateless reset token key.
Roman Arutyunyan <arut@nginx.com>
parents: 8628
diff changeset
1902 ngx_quic_build_int(&p, NGX_QUIC_SR_TOKEN_LEN);
831d1960826f QUIC: generate default stateless reset token key.
Roman Arutyunyan <arut@nginx.com>
parents: 8628
diff changeset
1903 p = ngx_cpymem(p, tp->sr_token, NGX_QUIC_SR_TOKEN_LEN);
8562
b31c02454539 QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents: 8560
diff changeset
1904
8247
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1905 return p - pos;
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1906 }
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1907
e9891e8ee975 Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents: 8245
diff changeset
1908
8245
a14afe21e692 Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents: 8244
diff changeset
1909 static size_t
8235
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
1910 ngx_quic_create_close(u_char *p, ngx_quic_close_frame_t *cl)
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
1911 {
8458
e0f92f68e018 QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents: 8447
diff changeset
1912 size_t len;
e0f92f68e018 QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents: 8447
diff changeset
1913 u_char *start;
e0f92f68e018 QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents: 8447
diff changeset
1914 ngx_uint_t type;
e0f92f68e018 QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents: 8447
diff changeset
1915
e0f92f68e018 QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents: 8447
diff changeset
1916 type = cl->app ? NGX_QUIC_FT_CONNECTION_CLOSE_APP
e0f92f68e018 QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents: 8447
diff changeset
1917 : NGX_QUIC_FT_CONNECTION_CLOSE;
8235
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
1918
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
1919 if (p == NULL) {
8458
e0f92f68e018 QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents: 8447
diff changeset
1920 len = ngx_quic_varint_len(type);
8235
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
1921 len += ngx_quic_varint_len(cl->error_code);
8458
e0f92f68e018 QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents: 8447
diff changeset
1922
e0f92f68e018 QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents: 8447
diff changeset
1923 if (!cl->app) {
e0f92f68e018 QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents: 8447
diff changeset
1924 len += ngx_quic_varint_len(cl->frame_type);
e0f92f68e018 QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents: 8447
diff changeset
1925 }
e0f92f68e018 QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents: 8447
diff changeset
1926
8235
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
1927 len += ngx_quic_varint_len(cl->reason.len);
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
1928 len += cl->reason.len;
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
1929
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
1930 return len;
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
1931 }
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
1932
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
1933 start = p;
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
1934
8458
e0f92f68e018 QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents: 8447
diff changeset
1935 ngx_quic_build_int(&p, type);
8235
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
1936 ngx_quic_build_int(&p, cl->error_code);
8458
e0f92f68e018 QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents: 8447
diff changeset
1937
e0f92f68e018 QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents: 8447
diff changeset
1938 if (!cl->app) {
e0f92f68e018 QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents: 8447
diff changeset
1939 ngx_quic_build_int(&p, cl->frame_type);
e0f92f68e018 QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents: 8447
diff changeset
1940 }
e0f92f68e018 QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents: 8447
diff changeset
1941
8235
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
1942 ngx_quic_build_int(&p, cl->reason.len);
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
1943 p = ngx_cpymem(p, cl->reason.data, cl->reason.len);
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
1944
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
1945 return p - start;
552d6868091b Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents: 8231
diff changeset
1946 }