Commit Graph

78 Commits

Author SHA1 Message Date
Roman Arutyunyan eea23ac250 HTTP/3: "quic" parameter of "listen" directive.
Now "listen" directve has a new "quic" parameter which enables QUIC protocol
for the address.  Further, to enable HTTP/3, a new directive "http3" is
introduced.  The hq-interop protocol is enabled by "http3_hq" as before.
Now application protocol is chosen by ALPN.

Previously used "http3" parameter of "listen" is deprecated.
2023-02-27 14:00:56 +04:00
Roman Arutyunyan 1565a79f8a HTTP/3: insert count block timeout.
Previously, there was no timeout for a request stream blocked on insert count,
which could result in infinite wait.  Now client_header_timeout is set when
stream is first blocked.
2023-01-05 19:03:22 +04:00
Roman Arutyunyan 42e1233601 HTTP/3: trigger 400 (Bad Request) on stream error while blocked.
Previously, stream was closed with NGX_HTTP_CLOSE.  However, in a similar case
when recv() returns eof or error, status 400 is triggered.
2023-01-05 18:15:46 +04:00
Sergey Kandaurov 5f8fa53775 HTTP/3: fixed $connection_time.
Previously, start_time wasn't set for a new stream.
The fix is to derive it from the parent connection.
Also it's used to simplify tracking keepalive_time.
2023-01-10 17:59:16 +04:00
Roman Arutyunyan 62700a2ed2 HTTP/3: implement keepalive for hq.
Previously, keepalive timer was deleted in ngx_http_v3_wait_request_handler()
and set in request cleanup handler.  This worked for HTTP/3 connections, but not
for hq connections.  Now keepalive timer is deleted in
ngx_http_v3_init_request_stream() and set in connection cleanup handler,
which works both for HTTP/3 and hq.
2022-10-25 12:52:09 +04:00
Roman Arutyunyan aa58c6457a QUIC: application init() callback.
It's called after handshake completion or prior to the first early data stream
creation.  The callback should initialize application-level data before
creating streams.

HTTP/3 callback implementation sets keepalive timer and sends SETTINGS.

Also, this allows to limit max handshake time in ngx_http_v3_init_stream().
2022-11-30 12:51:15 +04:00
Roman Arutyunyan 2fb971a6b9 HTTP/3: renamed functions.
ngx_http_v3_init() is renamed ngx_http_v3_init_stream().
ngx_http_v3_reset_connection() is renamed to ngx_http_v3_reset_stream().
2022-08-22 14:09:03 +04:00
Roman Arutyunyan 595a642018 QUIC: idle mode for main connection.
Now main QUIC connection for HTTP/3 always has c->idle flag set.  This allows
the connection to receive worker shutdown notification.  It is passed to
application level via a new conf->shutdown() callback.

The HTTP/3 shutdown callback sends GOAWAY to client and gracefully shuts down
the QUIC connection.
2022-10-19 17:45:18 +04:00
Roman Arutyunyan 7cccd64670 HTTP/3: unified hq code with regular HTTP/3 code.
The change removes hq-specific request handler.  Now hq requests are handled
by the HTTP/3 request handler.
2022-10-19 17:45:30 +04:00
Jiuzhou Cui a7bda07bda HTTP/3: fixed build without NGX_PCRE (broken by 0f5fc7a320db). 2022-11-25 15:07:23 +08:00
Sergey Kandaurov 4d1689d053 HTTP/3: fixed server_name regex captures (ticket #2407).
Previously, HTTP/3 stream connection didn't inherit the servername regex
from the main QUIC connection saved when processing SNI and using regular
expressions in server names.  As a result, it didn't execute to set regex
captures when choosing the virtual server while parsing HTTP/3 headers.
2022-11-22 14:10:04 +04:00
Roman Arutyunyan 2d72193dc0 HTTP/3: skip empty request body buffers (ticket #2374).
When client DATA frame header and its content come in different QUIC packets,
it may happen that only the header is processed by the first
ngx_http_v3_request_body_filter() call.  In this case an empty request body
buffer is added to r->request_body->bufs, which is later reused in a
subsequent ngx_http_v3_request_body_filter() call without being removed from
the body chain.  As a result, rb->request_body->bufs ends up with two copies of
the same buffer.

The fix is to avoid adding empty request body buffers to r->request_body->bufs.
2022-08-03 16:59:51 +04:00
Sergey Kandaurov d98314233f HTTP/3: improved processing of multiple Cookie field lines.
As per draft-ietf-quic-http, 4.1.1.2, and similar to HTTP/2 specification,
they ought to be concatenated.  This closely follows ngx_http_v2_module.
2021-12-30 12:59:32 +03:00
Roman Arutyunyan 22eb20ae31 Style. 2021-12-29 15:33:51 +03:00
Sergey Kandaurov 41b87485eb HTTP/3: avoid sending stream cancellation for pushed streams. 2021-12-07 15:49:30 +03:00
Vladimir Homutov c1d88961cb QUIC: simplified configuration.
Directives that set transport parameters are removed from the configuration.
Corresponding values are derived from the quic configuration or initialized
to default.  Whenever possible, quic configuration parameters are taken from
higher-level protocol settings, i.e. HTTP/3.
2021-12-06 15:19:54 +03:00
Roman Arutyunyan 88d2f21fc9 HTTP/3: http3_hq directive and NGX_HTTP_V3_HQ macro.
Listen quic parameter is no longer supported.
2021-12-04 10:52:55 +03:00
Roman Arutyunyan 6dc747f5ff HTTP/3: merged ngx_http_quic_module into ngx_http_v3_module. 2021-12-06 13:02:36 +03:00
Roman Arutyunyan 56bbbf72d0 HTTP/3: send Stream Cancellation instruction.
As per quic-qpack-21:

   When a stream is reset or reading is abandoned, the decoder emits a
   Stream Cancellation instruction.

Previously the instruction was not sent.  Now it's sent when closing QUIC
stream connection if dynamic table capacity is non-zero and eof was not
received from client.  The latter condition means that a trailers section
may still be on its way from client and the stream needs to be cancelled.
2021-10-18 14:48:11 +03:00
Roman Arutyunyan f72a2bb3f6 HTTP/3: allowed QUIC stream connection reuse.
A QUIC stream connection is treated as reusable until first bytes of request
arrive, which is also when the request object is now allocated.  A connection
closed as a result of draining, is reset with the error code
H3_REQUEST_REJECTED.  Such behavior is allowed by quic-http-34:

   Once a request stream has been opened, the request MAY be cancelled
   by either endpoint. Clients cancel requests if the response is no
   longer of interest; servers cancel requests if they are unable to or
   choose not to respond.

   When the server cancels a request without performing any application
   processing, the request is considered "rejected."  The server SHOULD
   abort its response stream with the error code H3_REQUEST_REJECTED.

   The client can treat requests rejected by the server as though they had
   never been sent at all, thereby allowing them to be retried later.
2021-10-18 15:47:06 +03:00
Roman Arutyunyan 261439aed2 HTTP/3: adjusted QUIC connection finalization.
When an HTTP/3 function returns an error in context of a QUIC stream, it's
this function's responsibility now to finalize the entire QUIC connection
with the right code, if required.  Previously, QUIC connection finalization
could be done both outside and inside such functions.  The new rule follows
a similar rule for logging, leads to cleaner code, and allows to provide more
details about the error.

While here, a few error cases are no longer treated as fatal and QUIC connection
is no longer finalized in these cases.  A few other cases now lead to
stream reset instead of connection finalization.
2021-10-18 15:22:33 +03:00
Roman Arutyunyan 6fe2069e12 HTTP/3: traffic-based flood detection.
With this patch, all traffic over HTTP/3 bidi and uni streams is counted in
the h3c->total_bytes field, and payload traffic is counted in the
h3c->payload_bytes field.  As long as total traffic is many times larger than
payload traffic, we consider this to be a flood.

Request header traffic is counted as if all fields are literal.  Response
header traffic is counted as is.
2021-10-07 13:22:42 +03:00
Roman Arutyunyan 334d204baf HTTP/3: fixed request length calculation.
Previously, when request was blocked, r->request_length was not updated.
2021-10-06 14:51:16 +03:00
Roman Arutyunyan 296f54ff65 HTTP/3: fixed ngx_stat_active counter.
Previously the counter was not incremented for HTTP/3 streams, but still
decremented in ngx_http_close_connection().  There are two solutions here, one
is to increment the counter for HTTP/3 streams, and the other one is not to
decrement the counter for HTTP/3 streams.  The latter solution looks
inconsistent with ngx_stat_reading/ngx_stat_writing, which are incremented on a
per-request basis.  The change adds ngx_stat_active increment for HTTP/3
request and push streams.
2021-09-22 14:08:21 +03:00
Sergey Kandaurov 542d5f7996 HTTP/3: added CONNECT and TRACE methods rejection.
It has got lost in e1eb7f4ca9f1, let alone a subsequent update in 63c66b7cc07c.
2021-09-16 13:13:22 +03:00
Roman Arutyunyan 5cb81675d5 HTTP/3: reading body buffering in filters.
This change follows similar changes in HTTP/1 and HTTP/2 in 9cf043a5d9ca.
2021-09-09 15:47:29 +03:00
Roman Arutyunyan 7c9cdcd3f9 HTTP/3: bulk parse functions.
Previously HTTP/3 streams were parsed by one character.  Now all parse functions
receive buffers.  This should optimize parsing time and CPU load.
2021-07-08 21:52:47 +03:00
Sergey Kandaurov caa3e48d23 HTTP/3: fixed dead store assignment.
Found by Clang Static Analyzer.
2021-08-24 13:03:48 +03:00
Sergey Kandaurov 34db4b5a52 HTTP/3: disabled control characters and space in header names.
This is a follow up to 41f4bd4c51f1.
2021-08-10 12:35:12 +03:00
Roman Arutyunyan 671aa053d5 HTTP/3: close connection on keepalive_requests * 2.
After receiving GOAWAY, client is not supposed to create new streams.  However,
until client reads this frame, we allow it to create new streams, which are
gracefully rejected.  To prevent client from abusing this algorithm, a new
limit is introduced.  Upon reaching keepalive_requests * 2, server now closes
the entire QUIC connection claiming excessive load.
2021-07-29 16:01:37 +03:00
Sergey Kandaurov 53e0bd538c HTTP/3: quic-qpack term updates.
Renamed header -> field per quic-qpack naming convention, in particular:
- Header Field -> Field Line
- Header Block -> (Encoded) Field Section
- Without Name Reference -> With Literal Name
- Header Acknowledgement -> Section Acknowledgment
2021-07-01 15:37:53 +03:00
Roman Arutyunyan 193e598f14 HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t. 2021-05-05 12:54:10 +03:00
Roman Arutyunyan 041da3d5a7 HTTP/3: ngx_http_v3_get_session() macro.
It's used instead of accessing c->quic->parent->data directly.  Apart from being
simpler, it allows to change the way session is stored in the future by changing
the macro.
2021-04-30 19:10:11 +03:00
Sergey Kandaurov 73b9640ea3 HTTP/3: keepalive_time support. 2021-04-16 19:42:03 +03:00
Roman Arutyunyan 9548c57590 HTTP/3: fixed $connection_requests.
Previously, the value was always "1".
2021-03-15 16:25:54 +03:00
Roman Arutyunyan 529409c0a0 HTTP/3: keepalive timeout.
This timeout limits the time when no client request streams exist.
2021-03-30 16:48:38 +03:00
Roman Arutyunyan 6b36b11167 QUIC: connection shutdown.
The function ngx_quic_shutdown_connection() waits until all non-cancelable
streams are closed, and then closes the connection.  In HTTP/3 cancelable
streams are all unidirectional streams except push streams.

The function is called from HTTP/3 when client reaches keepalive_requests.
2021-03-15 16:39:33 +03:00
Roman Arutyunyan 67c58e696f HTTP/3: send GOAWAY when last request is accepted.
The last request in connection is determined according to the keepalive_requests
directive.  Requests beyond keepalive_requests are rejected.
2021-03-15 19:26:04 +03:00
Roman Arutyunyan f9f6ded228 HTTP/3: limited client header size.
The limit is the size of all large client header buffers.  Client header size
is the total size of all client header names and values.
2021-02-17 11:58:32 +03:00
Roman Arutyunyan e33795e354 HTTP/3: introduced ngx_http_v3_parse_t structure.
The structure is used to parse an HTTP/3 request.  An object of this type is
added to ngx_http_request_t instead of h3_parse generic pointer.

Also, the new field is located outside of the request ephemeral zone to keep it
safe after request headers are parsed.
2021-02-17 15:56:34 +03:00
Roman Arutyunyan e12f2cbfbc HTTP/3: fixed format specifier. 2021-02-01 18:48:18 +03:00
Roman Arutyunyan b56ed96a16 HTTP/3: refactored request body parser.
The change reduces diff to the default branch for
src/http/ngx_http_request_body.c.

Also, client Content-Length, if present, is now checked against the real body
size sent by client.
2021-01-25 16:16:47 +03:00
Roman Arutyunyan a1810c53c0 HTTP/3: call ngx_handle_read_event() from client header handler.
This function should be called at the end of an event handler to prepare the
event for the next handler call.  Particularly, the "active" flag is set or
cleared depending on data availability.

With this call missing in one code path, read handler was not called again
after handling the initial part of the client request, if the request was too
big to fit into a single STREAM frame.

Now ngx_handle_read_event() is called in this code path.  Also, read timer is
restarted.
2021-01-29 19:42:47 +03:00
Roman Arutyunyan 4fe4a1be5e HTTP/3: client header validation.
A header with the name containing null, CR, LF, colon or uppercase characters,
is now considered an error.  A header with the value containing null, CR or LF,
is also considered an error.

Also, header is considered invalid unless its name only contains lowercase
characters, digits, minus and optionally underscore.  Such header can be
optionally ignored.
2021-01-18 13:43:36 +03:00
Roman Arutyunyan 51d921cf70 HTTP/3: client pseudo-headers restrictions.
- :method, :path and :scheme are expected exactly once and not empty
- :method and :scheme character validation is added
- :authority cannot appear more than once
2021-01-22 15:57:41 +03:00
Roman Arutyunyan 50430c7e1d HTTP/3: refactored request parser.
The change reduces diff to the default branch for
src/http/ngx_http_request.c and src/http/ngx_http_parse.c.
2021-01-22 16:34:06 +03:00
Sergey Kandaurov ebac406f83 HTTP/3: staticize ngx_http_v3_methods. 2020-12-16 12:47:38 +00:00
Roman Arutyunyan dc5ab4196f HTTP/3: introduced ngx_http_v3_filter.
The filter is responsible for creating HTTP/3 response header and body.

The change removes differences to the default branch for
ngx_http_chunked_filter_module and ngx_http_header_filter_module.
2020-11-27 17:46:21 +00:00
Roman Arutyunyan dce8a2f3d2 HTTP/3: eliminated r->method_start.
The field was introduced to ease parsing HTTP/3 requests.

The change reduces diff to the default branch.
2020-11-25 17:57:43 +00:00
Roman Arutyunyan e7985ce0ab QUIC: renamed c->qs to c->quic. 2020-11-10 19:40:00 +00:00