summaryrefslogtreecommitdiffhomepage
path: root/src (follow)
AgeCommit message (Collapse)AuthorFilesLines
2020-10-01QUIC: fixed clang-ast asserts.Sergey Kandaurov2-2/+2
2020-10-01QUIC: fixed build with OpenSSL after bed310672f39.Sergey Kandaurov1-1/+1
2020-10-01QUIC: moved ssl configuration pointer to quic configuration.Vladimir Homutov6-31/+30
The ssl configuration is obtained at config time and saved for future use.
2020-09-30QUIC: added stateless reset support.Vladimir Homutov7-13/+237
The new "quic_stateless_reset_token_key" directive is added. It sets the endpoint key used to generate stateless reset tokens and enables feature. If the endpoint receives short-header packet that can't be matched to existing connection, a stateless reset packet is generated with a proper token. If a valid stateless reset token is found in the incoming packet, the connection is closed. Example configuration: http { quic_stateless_reset_token_key "foo"; ... }
2020-09-30QUIC: refined the "c->quic->initialized" flag usage.Vladimir Homutov1-53/+66
The flag is tied to the initial secret creation. The presence of c->quic pointer is sufficient to enable execution of ngx_quic_close_quic(). The ngx_quic_new_connection() function now returns the allocated quic connection object and the c->quic pointer is set by the caller. If an early error occurs before secrets initialization (i.e. in cases of invalid retry token or nginx exiting), it is still possible to generate an error response by trying to initialize secrets directly in the ngx_quic_send_cc() function. Before the change such early errors failed to send proper connection close message and logged an error. An auxilliary ngx_quic_init_secrets() function is introduced to avoid verbose call to ngx_quic_set_initial_secret() requiring local variable.
2020-09-30QUIC: packet processing refactoring.Vladimir Homutov3-475/+239
All packet header parsing is now performed by ngx_quic_parse_packet() function, located in the ngx_quic_transport.c file. The packet processing is centralized in the ngx_quic_process_packet() function which decides if the packet should be accepted, ignored or connection should be closed, depending on the connection state. As a result of refactoring, behavior has changed in some places: - minimal size of Initial packet is now always tested - connection IDs are always tested in existing connections - old keys are discarded on encryption level switch
2020-09-25QUIC: simplified packet header parsing.Vladimir Homutov2-26/+3
Now flags are processed in ngx_quic_input(), and raw->pos points to the first byte after the flags. Redundant checks from ngx_quic_parse_short_header() and ngx_quic_parse_long_header() are removed.
2020-09-25QUIC: keep the entire packet size in pkt->len.Roman Arutyunyan3-6/+7
Previously pkt->len kept the length of the packet remainder starting from pkt->raw->pos.
2020-09-18QUIC: switched to using fixed-length server connection IDs.Vladimir Homutov2-10/+5
2020-09-30QUIC: resend frames by moving them to output queue.Roman Arutyunyan1-20/+20
Previously, when a packet was declared lost, another packet was sent with the same frames. Now lost frames are moved to the output frame queue and push event is posted. This has the advantage of forming packets with more frames than before. Also, the start argument is removed from the ngx_quic_resend_frames() function as excess information.
2020-09-29QUIC: switch stream context to a server selected by SNI.Roman Arutyunyan1-2/+15
Previously the default server configuration context was used until the :authority or host header was parsed. This led to using the configuration parameters like client_header_buffer_size or request_pool_size from the default server rather than from the server selected by SNI. Also, the switch to the right server log is implemented. This issue manifested itself as QUIC stream being logged to the default server log until :authority or host is parsed.
2020-09-23QUIC: unbreak client certificate verification after 0d2b2664b41c.Sergey Kandaurov1-0/+2
Initially, client certificate verification didn't work due to the missing hc->ssl on a QUIC stream, which is started to be set in 7738:7f0981be07c4. Then it was lost in 7999:0d2b2664b41c introducing "quic" listen parameter. This change re-adds hc->ssl back for all QUIC connections, similar to SSL.
2020-09-21QUIC: prevented posted push event while in the draining state.Vladimir Homutov1-12/+12
If the push event was posted before ngx_quic_close_connection(), it could send data in the draining state.
2020-09-16HTTP/3: rearranged length check when parsing header.Roman Arutyunyan1-5/+5
The new code looks simpler and is similar to other checks.
2020-09-16HTTP/3: removed HTTP/3 parser call from discard body filter.Roman Arutyunyan1-10/+1
Request body discard is disabled for QUIC streams anyway.
2020-09-16HTTP/3: reject HTTP/2 frames.Roman Arutyunyan1-0/+17
As per HTTP/3 draft 30, section 7.2.8: Frame types that were used in HTTP/2 where there is no corresponding HTTP/3 frame have also been reserved (Section 11.2.1). These frame types MUST NOT be sent, and their receipt MUST be treated as a connection error of type H3_FRAME_UNEXPECTED.
2020-08-28Stream: set module.Pavel Pautov1-0/+226
Adds 'set' directive to the stream server context.
2020-09-24SSL: abort handshake on SSL_set_SSL_CTX() errors.Sergey Kandaurov1-1/+4
In rare cases, such as memory allocation failure, SSL_set_SSL_CTX() returns NULL, which could mean that a different SSL configuration has not been set. Note that this new behaviour seemingly originated in OpenSSL-1.1.0 release.
2020-09-23HTTP/2: run posted requests after reading body.Maxim Dounin1-0/+4
HTTP/2 code failed to run posted requests after calling the request body handler, and this resulted in connection hang if a subrequest was created in the body handler and no other actions were made.
2020-09-23HTTP/2: fixed segfault on DATA frames after 400 errors.Maxim Dounin1-0/+7
If 400 errors were redirected to an upstream server using the error_page directive, DATA frames from the client might cause segmentation fault due to null pointer dereference. The bug had appeared in 6989:2c4dbcd6f2e4 (1.13.0). Fix is to skip such frames in ngx_http_v2_state_read_data() (similarly to 7561:9f1f9d6e056a). With the fix, behaviour of 400 errors in HTTP/2 is now similar to one in HTTP/1.x, that is, nginx doesn't try to read the request body. Note that proxying 400 errors, as well as other early stage errors, to upstream servers might not be a good idea anyway. These errors imply that reading and processing of the request (and the request headers) wasn't complete, and proxying of such incomplete request might lead to various errors. Reported by Chenglong Zhang.
2020-09-16SSL: disabled shutdown when there are buffered data.Maxim Dounin1-1/+1
This fixes "SSL_shutdown() failed (SSL: ... bad write retry)" errors as observed on the second SSL_shutdown() call after SSL shutdown fixes in 09fb2135a589 (1.19.2), notably when HTTP/2 connections are closed due to read timeouts while there are incomplete writes.
2020-09-16SSL: disabled shutdown after connection errors.Maxim Dounin1-1/+1
This fixes "SSL_shutdown() failed (SSL: ... bad write retry)" errors as observed on the second SSL_shutdown() call after SSL shutdown fixes in 09fb2135a589 (1.19.2), notably when sending fails in ngx_http_test_expect(), similarly to ticket #1194. Note that there are some places where c->error is misused to prevent further output, such as ngx_http_v2_finalize_connection() if there are pending streams, or in filter finalization. These places seem to be extreme enough to don't care about missing shutdown though. For example, filter finalization currently prevents keepalive from being used.
2020-09-16SSL: fixed event handling during shutdown.Maxim Dounin1-0/+7
The c->read->ready and c->write->ready flags need to be cleared to ensure that appropriate read or write events will be reported by kernel. Without this, SSL shutdown might wait till the timeout after blocking on writing or reading even if there is a socket activity.
2020-09-16SSL: workaround for incorrect SSL_write() errors in OpenSSL 1.1.1.Maxim Dounin1-0/+12
OpenSSL 1.1.1 fails to return SSL_ERROR_SYSCALL if an error happens during SSL_write() after close_notify alert from the peer, and returns SSL_ERROR_ZERO_RETURN instead. Broken by this commit, which removes the "i == 0" check around the SSL_RECEIVED_SHUTDOWN one: https://git.openssl.org/?p=openssl.git;a=commitdiff;h=8051ab2 In particular, if a client closed the connection without reading the response but with properly sent close_notify alert, this resulted in unexpected "SSL_write() failed while ..." critical log message instead of correct "SSL_write() failed (32: Broken pipe)" at the info level. Since SSL_ERROR_ZERO_RETURN cannot be legitimately returned after SSL_write(), the fix is to convert all SSL_ERROR_ZERO_RETURN errors after SSL_write() to SSL_ERROR_SYSCALL.
2020-09-09Cache: keep c->body_start when Vary changes (ticket #2029).Sergey Kandaurov2-1/+3
If the variant hash doesn't match one we used as a secondary cache key, we switch back to the original key. In this case, c->body_start was kept updated from an existing cache node overwriting the new response value. After file cache update, it led to discrepancy between a cache node and cache file seen as critical errors "file cache .. has too long header".
2020-08-24HTTP/3: skip unknown frames on request stream.Roman Arutyunyan3-11/+60
As per HTTP/3 draft 29, section 4.1: Frames of unknown types (Section 9), including reserved frames (Section 7.2.8) MAY be sent on a request or push stream before, after, or interleaved with other frames described in this section. Also, trailers frame is now used as an indication of the request body end.
2020-09-16HTTP/3: fixed handling request body eof.Roman Arutyunyan3-24/+35
While for HTTP/1 unexpected eof always means an error, for HTTP/3 an eof right after a DATA frame end means the end of the request body. For this reason, since adding HTTP/3 support, eof no longer produced an error right after recv() but was passed to filters which would make a decision. This decision was made in ngx_http_parse_chunked() and ngx_http_v3_parse_request_body() based on the b->last_buf flag. Now that since 0f7f1a509113 (1.19.2) rb->chunked->length is a lower threshold for the expected number of bytes, it can be set to zero to indicate that more bytes may or may not follow. Now it's possible to move the check for eof from parser functions to ngx_http_request_body_chunked_filter() and clean up the parsing code. Also, in the default branch, in case of eof, the following three things happened, which were replaced with returning NGX_ERROR while implementing HTTP/3: - "client prematurely closed connection" message was logged - c->error flag was set - NGX_HTTP_BAD_REQUEST was returned The change brings back this behavior for HTTP/1 as well as HTTP/3.
2020-09-11QUIC: switched to draft 29 by default.Vladimir Homutov1-2/+2
2020-09-09QUIC: allowed old DCID for initial packets until first ACK.Roman Arutyunyan1-8/+21
If a packet sent in response to an initial client packet was lost, then successive client initial packets were dropped by nginx with the unexpected dcid message logged. This was because the new DCID generated by the server was not available to the client.
2020-09-08QUIC: eliminated idle timeout restart for dropped packets.Roman Arutyunyan1-3/+27
2020-09-08QUIC: removed check for packet size beyond MAX_UDP_PAYLOAD_SIZE.Sergey Kandaurov1-5/+0
The check tested the total size of a packet header and unprotected packet payload, which doesn't include the packet number length and expansion of the packet protection AEAD. If the packet was corrupted, it could cause false triggering of the condition due to unsigned type underflow leading to a connection error. Existing checks for the QUIC header and protected packet payload lengths should be enough.
2020-09-08QUIC: check that the packet length is of at least sample size.Sergey Kandaurov1-0/+4
From quic-tls draft, section 5.4.2: An endpoint MUST discard packets that are not long enough to contain a complete sample. The check includes the Packet Number field assumed to be 4 bytes long.
2020-09-08QUIC: update packet length for short packets too.Sergey Kandaurov2-2/+2
During long packet header parsing, pkt->len is updated with the Length field value that is used to find next coalesced packets in a datagram. For short packets it still contained the whole QUIC packet size. This change uniforms packet length handling to always contain the total length of the packet number and protected packet payload in pkt->len.
2020-09-07QUIC: added logging output stream frame offset.Roman Arutyunyan1-4/+4
2020-09-04QUIC: refactored ngx_quic_retry_input().Vladimir Homutov1-15/+9
The function now returns NGX_DECLINED for packets that need to be ignored and integrates nicely into ngx_quic_input().
2020-09-06QUIC: do not send STOP_SENDING after STREAM fin.Roman Arutyunyan1-1/+1
Previously STOP_SENDING was sent to client upon stream closure if rev->eof and rev->error were not set. This was an indirect indication that no RESET_STREAM or STREAM fin has arrived. But it is indeed possible that rev->eof is not set, but STREAM fin has already been received, just not read out by the application. In this case sending STOP_SENDING does not make sense and can be misleading for some clients.
2020-09-03QUIC: added support for multiple connection IDs.Vladimir Homutov3-14/+301
The peer may issue additional connection IDs up to the limit defined by transport parameter "active_connection_id_limit", using NEW_CONNECTION_ID frames, and retire such IDs using RETIRE_CONNECTION_ID frame.
2020-08-27QUIC: style.Vladimir Homutov1-13/+13
Moved processing of RETIRE_CONNECTION_ID right after the NEW_CONNECTION_ID.
2020-09-02QUIC: pass return code from ngx_quic_decrypt() to the caller.Vladimir Homutov2-24/+39
It is required to distinguish internal errors from corrupted packets and perform actions accordingly: drop the packet or close the connection. While there, made processing of ngx_quic_decrypt() erorrs similar and removed couple of protocol violation errors.
2020-09-02QUIC: discard unrecognized long packes.Vladimir Homutov1-1/+4
While there, updated comment about discarded packets.
2020-08-31HTTP/3: do not set the never-indexed literal bit by default.Roman Arutyunyan1-3/+3
The "Literal Header Field Never Indexed" header field representation is not used in HTTP/2, and it makes little sense to make a distinction in HTTP/3.
2020-09-01QUIC: discard incorrect packets instead of closing the connection.Vladimir Homutov2-35/+29
quic-transport 5.2: Packets that are matched to an existing connection are discarded if the packets are inconsistent with the state of that connection. 5.2.2: Servers MUST drop incoming packets under all other circumstances.
2020-09-01QUIC: do not update largest packet number from a bad packet.Roman Arutyunyan1-2/+6
The removal of QUIC packet protection depends on the largest packet number received. When a garbage packet was received, the decoder still updated the largest packet number from that packet. This could affect removing protection from subsequent QUIC packets.
2020-08-28QUIC: handle PATH_CHALLENGE frame.Roman Arutyunyan2-15/+69
A PATH_RESPONSE frame with the same data is sent in response.
2020-08-25QUIC: enforce flow control on incoming STREAM and CRYPTO frames.Roman Arutyunyan1-13/+41
2020-08-25HTTP/3: drop the unwanted remainder of the request.Roman Arutyunyan2-0/+13
As per HTTP/3 draft 29, section 4.1: When the server does not need to receive the remainder of the request, it MAY abort reading the request stream, send a complete response, and cleanly close the sending part of the stream.
2020-08-25QUIC: send STOP_SENDING on stream closure.Roman Arutyunyan2-0/+49
The frame is sent for a read-enabled stream which has not received a FIN or RESET_STREAM.
2020-08-21QUIC: disabled bidirectional SSL shutdown after 09fb2135a589.Sergey Kandaurov1-0/+1
On QUIC connections, SSL_shutdown() is used to call the send_alert callback to send a CONNECTION_CLOSE frame. The reverse side is handled by other means. At least BoringSSL doesn't differentiate whether this is a QUIC SSL method, so waiting for the peer's close_notify alert should be explicitly disabled.
2020-08-21QUIC: stripped down debug traces that have served its purpose.Sergey Kandaurov3-63/+4
The most observable remainers are incoming packet and stream payload that could still be useful to debug various QUIC and HTTP/3 frames.
2020-08-21QUIC: dead code removed.Vladimir Homutov1-8/+0
This case was already handled in c70446e3d771.