summaryrefslogtreecommitdiffhomepage
path: root/src/event (follow)
AgeCommit message (Collapse)AuthorFilesLines
2021-12-07QUIC: converted ngx_quic_keys_set_encryption_secret() to NGX codes.Sergey Kandaurov3-17/+27
While here, removed check for encryption level zero, redundant by its nature.
2021-12-06QUIC: simplified configuration.Vladimir Homutov5-35/+87
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-02QUIC: fixed using of retired connection id (ticket #2289).Vladimir Homutov1-4/+6
RFC 9000 19.16 The sequence number specified in a RETIRE_CONNECTION_ID frame MUST NOT refer to the Destination Connection ID field of the packet in which the frame is contained. Before the patch, the RETIRE_CONNECTION_ID frame was sent before switching to the new client id. If retired client id was currently in use, this lead to violation of the spec.
2021-12-02QUIC: logging of CRYPTO frame payload under NGX_QUIC_DEBUG_FRAMES.Sergey Kandaurov1-0/+14
2021-12-01QUIC: removed excessive check.Vladimir Homutov1-1/+1
The c->udp->dgram may be NULL only if the quic connection was just created: the ngx_event_udp_recvmsg() passes information about datagrams to existing connections by providing information in c->udp. If case of a new connection, c->udp is allocated by the QUIC code during creation of quic connection (it uses c->sockaddr to initialize qsock->path). Thus the check for qsock->path is excessive and can be read wrong, assuming that other options possible, leading to warnings from clang static analyzer.
2021-11-30QUIC: ngx_quic_send_alert() callback moved to its place.Sergey Kandaurov3-29/+28
2021-11-30QUIC: simplified ngx_quic_send_alert() callback.Sergey Kandaurov1-10/+4
Removed sending CLOSE_CONNECTION directly to avoid duplicate frames, since it is sent later again in SSL_do_handshake() error handling. As such, removed redundant settings of error fields set elsewhere. While here, improved debug message.
2021-11-18QUIC: removed unnecessary closing of active/backup sockets.Vladimir Homutov1-6/+0
All open sockets are stored in a queue. There is no need to close some of them separately. If it happens that active and backup point to same socket, double close may happen (leading to possible segfault).
2021-11-29QUIC: fixed migration during NAT rebinding.Vladimir Homutov3-69/+31
The RFC 9000 allows a packet from known CID arrive from unknown path: These requirements regarding connection ID reuse apply only to the sending of packets, as unintentional changes in path without a change in connection ID are possible. For example, after a period of network inactivity, NAT rebinding might cause packets to be sent on a new path when the client resumes sending. Before the patch, such packets were rejected with an error in the ngx_quic_check_migration() function. Removing the check makes the separate function excessive - remaining checks are early migration check and "disable_active_migration" check. The latter is a transport parameter sent to client and it should not be used by server. The server should send "disable_active_migration" "if the endpoint does not support active connection migration" (18.2). The support status depends on nginx configuration: to have migration working with multiple workers, you need bpf helper, available on recent Linux systems. The patch does not set "disable_active_migration" automatically and leaves it for the administrator. By default, active migration is enabled. RFC 900 says that it is ok to migrate if the peer violates "disable_active_migration" flag requirements: If the peer violates this requirement, the endpoint MUST either drop the incoming packets on that path without generating a Stateless Reset OR proceed with path validation and allow the peer to migrate. Generating a Stateless Reset or closing the connection would allow third parties in the network to cause connections to close by spoofing or otherwise manipulating observed traffic. So, nginx adheres to the second option and proceeds to path validation. Note: The ngtcp2 may be used for testing both active migration and NAT rebinding: ngtcp2/client --change-local-addr=200ms --delay-stream=500ms <ip> <port> <url> ngtcp2/client --change-local-addr=200ms --delay-stream=500ms --nat-rebinding \ <ip> <port> <url>
2021-11-29QUIC: refactored multiple QUIC packets handling.Vladimir Homutov3-11/+10
Single UDP datagram may contain multiple QUIC datagrams. In order to facilitate handling of such cases, 'first' flag in the ngx_quic_header_t structure is introduced.
2021-11-18QUIC: fixed handling of RETIRE_CONNECTION_ID frame.Vladimir Homutov3-30/+55
Previously, the retired socket was not closed if it didn't match active or backup. New sockets could not be created (due to count limit), since retired socket was not closed before calling ngx_quic_create_sockets(). When replacing retired socket, new socket is only requested after closing old one, to avoid hitting the limit on the number of active connection ids. Together with added restrictions, this fixes an issue when a current socket could be closed during migration, recreated and erroneously reused leading to null pointer dereference.
2021-11-18QUIC: additional checks for the RETIRE_CONNECTION_ID frame.Vladimir Homutov1-0/+33
2021-11-17QUIC: handle DATA_BLOCKED frame from client.Roman Arutyunyan3-15/+58
Previously the frame was not handled and connection was closed with an error. Now, after receiving this frame, global flow control is updated and new flow control credit is sent to client.
2021-11-17QUIC: update stream flow control credit on STREAM_DATA_BLOCKED.Roman Arutyunyan1-37/+44
Previously, after receiving STREAM_DATA_BLOCKED, current flow control limit was sent to client. Now, if the limit can be updated to the full window size, it is updated and the new value is sent to client, otherwise nothing is sent. The change lets client update flow control credit on demand. Also, it saves traffic by not sending MAX_STREAM_DATA with the same value twice.
2021-11-11QUIC: reject streams which we could not create.Roman Arutyunyan2-4/+74
The reasons why a stream may not be created by server currently include hitting worker_connections limit and memory allocation error. Previously in these cases the entire QUIC connection was closed and all its streams were shut down. Now the new stream is rejected and existing streams continue working. To reject an HTTP/3 request stream, RESET_STREAM and STOP_SENDING with H3_REQUEST_REJECTED error code are sent to client. HTTP/3 uni streams and Stream streams are not rejected.
2021-11-12QUIC: stop processing new client streams at the closing state.Sergey Kandaurov1-2/+2
2021-11-01SSL: $ssl_curve (ticket #2135).Sergey Kandaurov2-0/+38
The variable contains a negotiated curve used for the handshake key exchange process. Known curves are listed by their names, unknown ones are shown in hex. Note that for resumed sessions in TLSv1.2 and older protocols, $ssl_curve contains the curve used during the initial handshake, while in TLSv1.3 it contains the curve used during the session resumption (see the SSL_get_negotiated_group manual page for details). The variable is only meaningful when using OpenSSL 3.0 and above. With older versions the variable is empty.
2021-11-11QUIC: fixed PATH_RESPONSE frame expansion.Vladimir Homutov1-3/+11
The PATH_RESPONSE frame must be expanded to 1200, except the case when anti-amplification limit is in effect, i.e. on unvalidated paths. Previously, the anti-amplification limit was always applied.
2021-11-10QUIC: removed ngx_quic_error_text() declaration.Vladimir Homutov1-2/+0
This is a leftover from cab3b7a070ef.
2021-11-09QUIC: fixed GSO packets count.Vladimir Homutov1-2/+4
Thanks to Andrey Kolyshkin <a.kolyshkin@corp.vk.com>
2021-11-10QUIC: removed dead code.Vladimir Homutov2-39/+0
The function is no longer used since b3d9e57d0f62.
2021-11-08QUIC: converted client_tp_done to bitfield.Vladimir Homutov1-1/+1
2021-10-13QUIC: fixed removal of unused client IDs.Vladimir Homutov1-3/+6
If client ID was never used, its refcount is zero. To keep things simple, the ngx_quic_unref_client_id() function is now aware of such IDs. If client ID was used, the ngx_quic_replace_retired_client_id() function is supposed to find all users and unref the ID, thus ngx_quic_unref_client_id() should not be called after it.
2021-11-03QUIC: connections with wrong ALPN protocols are now rejected.Vladimir Homutov2-13/+13
Previously, it was not enforced in the stream module. Now, since b9e02e9b2f1d it is possible to specify protocols. Since ALPN is always required, the 'require_alpn' setting is now obsolete.
2021-10-07QUIC: refactored packet creation.Vladimir Homutov4-74/+108
The "min" and "max" arguments refer to UDP datagram size. Generating payload requires to account properly for header size, which is variable and depends on payload size and packet number.
2021-10-07QUIC: removed unused argument in ngx_quic_create_short_header().Vladimir Homutov1-3/+3
2021-09-30QUIC: added function to initialize packet.Vladimir Homutov1-64/+56
2021-10-22QUIC: fixed processing of minimum packet size.Vladimir Homutov1-0/+4
If packet needs to be expanded (for example Initial to 1200 bytes), but path limit is less, such packet should not be created/sent.
2021-09-23QUIC: added shutdown support in stream proxy.Vladimir Homutov2-0/+51
2021-11-03Merged with the default branch.Sergey Kandaurov2-6/+241
2021-10-26QUIC: style.Sergey Kandaurov3-5/+1
2021-10-26QUIC: speeding up processing 0-RTT.Sergey Kandaurov1-2/+18
After fe919fd63b0b, processing QUIC streams was postponed until after handshake completion, which means that 0-RTT is effectively off. With ssl_ocsp enabled, it could be further delayed. This differs from how OCSP validation works with SSL_read_early_data(). With this change, processing QUIC streams is unlocked when obtaining 0-RTT secret.
2021-10-26QUIC: refactored OCSP validation in preparation for 0-RTT support.Sergey Kandaurov3-13/+33
2021-10-19QUIC: switched to integer arithmetic in rtt calculations.Vladimir Homutov1-8/+17
RFC 9002 uses constants implying effective implementation, i.e. using bit shift operations instead of floating point.
2021-10-15QUIC: optimized ack range processing.Vladimir Homutov1-3/+7
The sent queue is sorted by packet number. It is possible to avoid traversing full queue while handling ack ranges. It makes sense to start traversing from the queue head (i.e. check oldest packets first).
2021-10-13QUIC: limited the total number of frames.Roman Arutyunyan2-3/+7
Exceeding 10000 allocated frames is considered a flood.
2021-10-13QUIC: traffic-based flood detection.Roman Arutyunyan2-5/+31
With this patch, all traffic over a QUIC connection is compared to traffic over QUIC streams. As long as total traffic is many times larger than stream traffic, we consider this to be a flood.
2021-10-12QUIC: attempt decrypt before checking for stateless reset.Martin Duke1-2/+5
Checking the reset after encryption avoids false positives. More importantly, it avoids the check entirely in the usual case where decryption succeeds. RFC 9000, 10.3.1 Detecting a Stateless Reset Endpoints MAY skip this check if any packet from a datagram is successfully processed.
2021-10-12QUIC: Check if CID has been used in stateless reset checkMartin Duke1-2/+5
Section 10.3.1 of RFC9000 requires this check.
2021-09-21QUIC: send RESET_STREAM in response to STOP_SENDING.Roman Arutyunyan1-5/+13
As per RFC 9000: An endpoint that receives a STOP_SENDING frame MUST send a RESET_STREAM frame if the stream is in the "Ready" or "Send" state. An endpoint SHOULD copy the error code from the STOP_SENDING frame to the RESET_STREAM frame it sends, but it can use any application error code.
2021-09-22QUIC: reset stream only once.Roman Arutyunyan1-1/+6
2021-09-27QUIC: moved a variable initialization near to its use.Sergey Kandaurov1-2/+2
This tends to produce slightly more optimal code with pos == NULL when built with Clang on low optimization levels. Spotted by Ruslan Ermilov.
2021-09-27Configure: check for QUIC 0-RTT support at compile time.Ruslan Ermilov1-1/+1
2021-09-22QUIC: set NGX_TCP_NODELAY_DISABLED for fake stream connections.Sergey Kandaurov1-0/+1
Notably, it is to avoid setting the TCP_NODELAY flag for QUIC streams in ngx_http_upstream_send_response(). It is an invalid operation on inherently SOCK_DGRAM sockets, which leads to QUIC connection close. The change reduces diff to the default branch in stream content phase.
2021-09-21QUIC: simplified stream fd initialization.Roman Arutyunyan1-2/+1
2021-09-09QUIC: separate event handling functions.Roman Arutyunyan3-25/+37
The functions ngx_quic_handle_read_event() and ngx_quic_handle_write_event() are added. Previously this code was a part of ngx_handle_read_event() and ngx_handle_write_event(). The change simplifies ngx_handle_read_event() and ngx_handle_write_event() by moving QUIC-related code to a QUIC source file.
2021-09-09QUIC: removed Firefox workaround for trailing zeroes in datagrams.Sergey Kandaurov1-5/+0
This became unnecessary after discarding invalid packets since a6784cf32c13.
2021-09-09QUIC: macro style.Ruslan Ermilov1-1/+1
2021-09-06QUIC: store QUIC connection fd in stream fake connection.Roman Arutyunyan1-0/+2
Previously it had -1 as fd. This fixes proxying, which relies on downstream connection having a real fd. Also, this reduces diff to the default branch for ngx_close_connection().
2021-09-03QUIC: fixed null pointer dereference in MAX_DATA handler.Mariano Di Martino1-1/+3
If a MAX_DATA frame was received before any stream was created, then the worker process would crash in nginx_quic_handle_max_data_frame() while traversing the stream tree. The issue is solved by adding a check that makes sure the tree is not empty.