Commit Graph

7332 Commits

Author SHA1 Message Date
Vladimir Homutov
8a3c4c6d8c QUIC: distinguish reserved transport parameters in logging.
18.1.  Reserved Transport Parameters

     Transport parameters with an identifier of the form "31 * N + 27" for
     integer values of N are reserved to exercise the requirement that
     unknown transport parameters be ignored.  These transport parameters
     have no semantics, and can carry arbitrary values.
2021-02-10 14:10:14 +03:00
Roman Arutyunyan
5d4e864e0d QUIC: send PING frames on PTO expiration.
Two PING frames are sent per level that generate two UDP datagrams.
2021-02-12 14:51:53 +03:00
Roman Arutyunyan
8084a829d0 QUIC: improved setting the lost timer.
Setting the timer is brought into compliance with quic-recovery-34.  Now it's
set from a single function ngx_quic_set_lost_timer() that takes into account
both loss detection and PTO.  The following issues are fixed with this change:

- when in loss detection mode, discarding a context could turn off the
  timer forever after switching to the PTO mode
- when in loss detection mode, sending a packet resulted in rescheduling the
  timer as if it's always in the PTO mode
2021-02-12 14:40:33 +03:00
Roman Arutyunyan
dbd812efd2 QUIC: disabled non-immediate ACKs for Initial and Handshake.
As per quic-transport-33:

   An endpoint MUST acknowledge all ack-eliciting Initial and Handshake
   packets immediately

If a packet carrying Initial or Handshake ACK was lost, a non-immediate ACK
should not be sent later.  Instead, client is expected to send a new packet
to acknowledge.

Sending non-immediate ACKs for Initial packets can cause the client to
generate an inflated RTT sample.
2021-02-04 20:39:47 +03:00
Roman Arutyunyan
56a11126e8 QUIC: fixed logging ACK frames.
Previously, the wrong end pointer was used, which could lead to errors
"quic failed to parse ack frame gap".
2021-02-09 14:31:36 +03:00
Vladimir Homutov
eab61bfc22 QUIC: the "quic_host_key" directive.
The token generation in QUIC is reworked. Single host key is used to generate
all required keys of needed sizes using HKDF.

The "quic_stateless_reset_token_key" directive is removed.  Instead, the
"quic_host_key" directive is used, which reads key from file, or sets it
to random bytes if not specified.
2021-02-08 16:49:33 +03:00
Roman Arutyunyan
040a23bfc3 QUIC: use server ack_delay_exponent when sending ack.
Previously, client one was used.
2021-02-04 14:35:36 +03:00
Sergey Kandaurov
b51d010029 QUIC: removed redundant "app" flag from ngx_quic_close_frame_t.
The flag was introduced to create type-aware CONNECTION_CLOSE frames,
and now is replaced with frame type information, directly accessible.
Notably, this fixes type logging for received frames in b3d9e57d0f62.
2021-02-03 12:39:41 +03:00
Roman Arutyunyan
365c8b7914 HTTP/3: reverted version check for keepalive flag.
The flag is used in ngx_http_finalize_connection() to switch client connection
to the keepalive mode.  Since eaea7dac3292 this code is not executed for HTTP/3
which allows us to revert the change and get back to the default branch code.
2021-02-02 15:09:48 +03:00
Roman Arutyunyan
a373d2851b HTTP/3: fixed format specifier. 2021-02-01 18:48:18 +03:00
Roman Arutyunyan
6f3c821d1f 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
a7cf99b10d QUIC: fixed stateless reset recognition and send.
Previously, if an unexpected packet was received on an existing QUIC
connection, stateless reset token was neither recognized nor sent.
2021-02-01 14:46:36 +03:00
Roman Arutyunyan
fef3360466 QUIC: refactored packet processing.
- split ngx_quic_process_packet() in two functions with the second one called
  ngx_quic_process_payload() in charge of decrypring and handling the payload
- renamed ngx_quic_payload_handler() to ngx_quic_handle_frames()
- moved error cleanup from ngx_quic_input() to ngx_quic_process_payload()
- moved handling closed connection from ngx_quic_handle_frames() to
  ngx_quic_process_payload()
- minor fixes
2021-01-28 12:35:18 +03:00
Vladimir Homutov
89dda20510 QUIC: stateless retry.
Previously, quic connection object was created when Retry packet was sent.
This is neither necessary nor convenient, and contradicts the idea of retry:
protecting from bad clients and saving server resources.

Now, the connection is not created, token is verified cryptographically
instead of holding it in connection.
2021-01-29 15:53:47 +03:00
Roman Arutyunyan
cd62534300 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
Sergey Kandaurov
68aa6fec77 README: reflect renaming of several transport parameter directives.
Reported by Kyriakos Zarifis.
2021-01-27 13:09:45 +03:00
Roman Arutyunyan
52d0bf620a HTTP/3: removed HTTP/3-specific code.
The ngx_http_set_lingering_close() function is not called for HTTP/3.

The change reduces diff to the default branch.
2020-12-21 17:35:13 +00:00
Roman Arutyunyan
7bac596afb 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
88f6b969e6 HTTP/3: added comment. 2021-01-12 21:08:55 +00:00
Roman Arutyunyan
4e312daa7e 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
9e489d208f 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
f3c9e9f961 QUIC: draft-33 salt and retry keys.
Notably, the version negotiation table is updated to reject draft-33/QUICv1
(which requires a new TLS codepoint) unless explicitly asked to built with.
2021-01-11 15:25:48 +03:00
Vladimir Homutov
291eb52899 QUIC: fixed header protection macro name. 2020-12-30 20:47:35 +03:00
Vladimir Homutov
c4f31ccca1 QUIC: ngx_quic_bpf module.
The quic kernel bpf helper inspects packet payload for DCID, extracts key
and routes the packet into socket matching the key.

Due to reuseport feature, each worker owns a personal socket, which is
identified by the same key, used to create DCID.

BPF objects are locked in RAM and are subject to RLIMIT_MEMLOCK.
The "ulimit -l" command may be used to setup proper limits, if maps
cannot be created with EPERM or updated with ETOOLONG.
2020-12-25 15:01:15 +03:00
Vladimir Homutov
b20b58ca7d Core: added interface to linux bpf() system call.
It contains wrappers for operations with BPF maps and for loading BPF programs.
2020-12-15 15:23:07 +03:00
Vladimir Homutov
fb655007a1 QUIC: ngx_quic_module. 2020-12-25 14:18:51 +03:00
Vladimir Homutov
4952711097 QUIC: moved all quic sources into src/event/quic. 2020-12-25 14:01:28 +03:00
Sergey Kandaurov
45666324af QUIC: removed unused <openssl/aes.h> inclusion.
The low-level API was used in early QUIC development.
2020-12-22 16:41:56 +03:00
Sergey Kandaurov
e00439e55d QUIC: fixed -Wtype-limits with GCC <= 5 (ticket #2104). 2020-12-22 12:04:16 +03:00
Sergey Kandaurov
df8ef280a5 QUIC: fixed logging PATH_CHALLENGE/RESPONSE and build with GCC < 5. 2020-12-22 12:04:15 +03:00
Sergey Kandaurov
a969893656 QUIC: fixed building ALPN callback without debug and http2. 2020-12-22 12:04:15 +03:00
Sergey Kandaurov
71f9b41c7f QUIC: fixed build with OpenSSL < 1.1.1.
The <openssl/kdf.h> header is available since OpenSSL 1.1.0, and HKDF API
used for separate Extract and Expand steps in TLSv1.3 - since OpenSSL 1.1.1.
2020-12-22 12:03:43 +03:00
Sergey Kandaurov
2bc8ee6535 QUIC: converted to SSL_CIPHER_get_protocol_id().
This API is available in BoringSSL for quite some time:
https://boringssl.googlesource.com/boringssl/+/3743aaf
2020-12-21 15:05:43 +03:00
Sergey Kandaurov
405b9be899 HTTP/3: staticize internal parsing functions. 2020-12-16 12:47:41 +00:00
Sergey Kandaurov
c3714a8089 HTTP/3: staticize ngx_http_v3_methods. 2020-12-16 12:47:38 +00:00
Sergey Kandaurov
1a3bf7d593 Merged with the default branch. 2020-12-15 16:55:43 +00:00
Maxim Dounin
402f4cda0c release-1.19.6 tag 2020-12-15 17:41:39 +03:00
Maxim Dounin
65ddeebf33 nginx-1.19.6-RELEASE 2020-12-15 17:41:39 +03:00
Maxim Dounin
b3341c06cb Updated OpenSSL used for win32 builds. 2020-12-15 16:49:24 +03:00
Maxim Dounin
b138e26395 Fixed double close of non-regular files in flv and mp4.
With introduction of open_file_cache in 1454:f497ed7682a7, opening a file
with ngx_open_cached_file() automatically adds a cleanup handler to close
the file.  As such, calling ngx_close_file() directly for non-regular files
is no longer needed and will result in duplicate close() call.

In 1454:f497ed7682a7 ngx_close_file() call for non-regular files was removed
in the static module, but wasn't in the flv module.  And the resulting
incorrect code was later copied to the mp4 module.  Fix is to remove the
ngx_close_file() call from both modules.

Reported by Chris Newton.
2020-12-11 13:42:07 +03:00
Maxim Dounin
2e94c81b0b Removed extra allocation for r->uri.
The ngx_http_parse_complex_uri() function cannot make URI longer and does
not null-terminate URI, so there is no need to allocate an extra byte.  This
allocation appears to be a leftover from changes in 461:a88a3e4e158f (0.1.5),
where null-termination of r->uri and many other strings was removed.
2020-12-10 20:09:39 +03:00
Maxim Dounin
ce9971b2b5 Fixed parsing of absolute URIs with empty path (ticket #2079).
When the request line contains request-target in the absolute-URI form,
it can contain path-empty instead of a single slash (see RFC 7230, RFC 3986).
Previously, the ngx_http_parse_request_line() function only accepted empty
path when there was no query string.

With this change, non-empty query is also correctly handled.  That is,
request line "GET http://example.com?foo HTTP/1.1" is accepted and results
in $uri "/" and $args "foo".

Note that $request_uri remains "?foo", similarly to how spaces in URIs
are handled.  Providing "/?foo", similarly to how "/" is provided for
"GET http://example.com HTTP/1.1", requires allocation.
2020-12-10 20:09:30 +03:00
Roman Arutyunyan
240f8a918e QUIC: always calculate rtt for largest acknowledged packet.
Previously, when processing client ACK, rtt could be calculated for a packet
different than the largest if it was missing in the sent chain.  Even though
this is an unlikely situation, rtt based on a different packet could be larger
than needed leading to bigger pto timeout and performance degradation.
2020-12-09 21:26:21 +00:00
Roman Arutyunyan
4fd02c5839 QUIC: send and process ack_delay for Initial and Handshake levels.
Previously, this only worked for Application level because before
quic-transport-30, there were the following constraints:

   Because the receiver doesn't use the ACK Delay for Initial and Handshake
   packets, a sender SHOULD send a value of 0.

   When adjusting an RTT sample using peer-reported acknowledgement delays, an
   endpoint ...  MUST ignore the ACK Delay field of the ACK frame for packets
   sent in the Initial and Handshake packet number space.
2020-12-10 14:54:53 +00:00
Roman Arutyunyan
6f9efd423e QUIC: use client max_ack_delay when computing pto timeout.
Previously, server max_ack_delay was used which is wrong.

Also, level check is simplified.
2020-12-09 16:15:24 +00:00
Roman Arutyunyan
e5c10dce5e QUIC: resend handshake packets along with initial.
To speed up handshake, resend both initial and handshake packets if there's
at least one unacknowledged initial packet.
2020-12-08 17:10:22 +00:00
Roman Arutyunyan
fc3f04b111 QUIC: set the temporary flag for input frame buffers.
Missing flag prevented frame data from being copied as the buffer was not
considered a memory buffer.
2020-12-08 14:44:41 +00:00
Ruslan Ermilov
e62a5132ca SSL: fixed SSL shutdown on lingering close.
Ensure c->recv is properly reset to ngx_recv if SSL_shutdown()
blocks on writing.

The bug had appeared in 554c6ae25ffc.
2020-12-08 01:43:36 +03:00
Roman Arutyunyan
c9cbd2f8e7 QUIC: coalesce output packets into a single UDP datagram.
Now initial output packet is not padded anymore if followed by a handshake
packet.  If the datagram is still not big enough to satisfy minimum size
requirements, handshake packet is padded.
2020-12-07 15:09:08 +00:00
Roman Arutyunyan
ec99ccee36 QUIC: introduced QUIC buffers.
Buffers are used to hold frame data.  They have a fixed size and are reused
after being freed.
2020-12-01 19:11:01 +00:00