summaryrefslogtreecommitdiffhomepage
path: root/src/event (follow)
AgeCommit message (Collapse)AuthorFilesLines
2023-01-28Style.Maxim Dounin1-2/+2
2023-02-22QUIC: OpenSSL compatibility layer.Roman Arutyunyan6-46/+766
The change allows to compile QUIC with OpenSSL which lacks BoringSSL QUIC API. This implementation does not support 0-RTT.
2023-02-23QUIC: improved ssl_reject_handshake error logging.Sergey Kandaurov1-0/+8
The check follows the ngx_ssl_handshake() change in 59e1c73fe02b.
2023-02-23QUIC: using ngx_ssl_handshake_log().Sergey Kandaurov3-9/+7
2023-02-23QUIC: moved "handshake failed" reason to send_alert.Sergey Kandaurov1-1/+1
A QUIC handshake failure breaks down into several cases: - a handshake error which leads to a send_alert call - an error triggered by the add_handshake_data callback - internal errors (allocation etc) Previously, in the first case, only error code was set in the send_alert callback. Now the "handshake failed" reason phrase is set there as well. In the second case, both code and reason are set by add_handshake_data. In the last case, setting reason phrase is removed: returning NGX_ERROR now leads to closing the connection with just INTERNAL_ERROR. Reported by Jiuzhou Cui.
2023-02-23QUIC: using NGX_QUIC_ERR_CRYPTO macro in ALPN checks.Sergey Kandaurov1-1/+1
Patch by Jiuzhou Cui.
2023-02-13QUIC: fixed indentation.Sergey Kandaurov2-3/+3
2023-01-31QUIC: fixed broken token in NEW_TOKEN (ticket #2446).Roman Arutyunyan4-8/+34
Previously, since 3550b00d9dc8, the token was allocated on stack, to get rid of pool usage. Now the token is allocated by ngx_quic_copy_buffer() in QUIC buffers, also used for STREAM, CRYPTO and ACK frames.
2023-01-31QUIC: ngx_quic_copy_buffer() function.Roman Arutyunyan3-21/+37
The function copies passed data to QUIC buffer chain and returns it. The chain can be used in ngx_quic_frame_t data field.
2023-01-18QUIC: defer setting the active flag for client stream events.Sergey Kandaurov1-18/+21
Specifically, now it is kept unset until streams are initialized. Notably, this unbreaks OCSP with client certificates after 35e27117b593. Previously, the read event could be posted prematurely via ngx_quic_set_event() e.g., as part of handling a STREAM frame.
2023-01-10QUIC: relocated ngx_quic_init_streams() for 0-RTT.Roman Arutyunyan1-13/+9
Previously, streams were initialized in early keys handler. However, client transport parameters may not be available by then. This happens, for example, when using QuicTLS. Now streams are initialized in ngx_quic_crypto_input() after calling SSL_do_handshake() for both 0-RTT and 1-RTT.
2023-01-10QUIC: set stream error flag on reset.Roman Arutyunyan1-2/+12
Now, when RESET_STREAM is sent or received, or when streams are closed, stream connection error flag is set. Previously, only stream state was changed, which resulted in setting the error flag only after calling recv()/send()/send_chain(). However, there are cases when none of these functions is called, but it's still important to know if the stream is being closed. For example, when an HTTP/3 request stream is blocked on insert count, receiving RESET_STREAM should trigger stream closure, which was not the case. The change also fixes ngx_http_upstream_check_broken_connection() and ngx_http_test_reading() with QUIC streams.
2023-01-10QUIC: automatically add and never delete stream events.Roman Arutyunyan3-32/+9
Previously, stream events were added and deleted by ngx_handle_read_event() and ngx_handle_write_event() in a way similar to level-triggered events. However, QUIC stream events are effectively edge-triggered and can stay active all time. Moreover, the events are now active since the moment a stream is created.
2023-01-10HTTP/3: fixed $connection_time.Sergey Kandaurov1-0/+1
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-02Merged with the default branch.Sergey Kandaurov2-2/+2
2022-12-16Style.BullerDu1-1/+1
2022-12-15Merged with the default branch.Sergey Kandaurov2-3/+13
2022-12-01SSL: fixed ngx_ssl_recv() to reset c->read->ready after errors.Maxim Dounin1-0/+5
With this change, behaviour of ngx_ssl_recv() now matches ngx_unix_recv(), which used to always reset c->read->ready to 0 when returning errors. This fixes an infinite loop in unbuffered SSL proxying if writing to the client is blocked and an SSL error happens (ticket #2418). With this change, the fix for a similar issue in the stream module (6868:ee3645078759), which used a different approach of explicitly testing c->read->error instead, is no longer needed and was reverted.
2022-11-24SSL: fixed debug logging of SSL_sendfile() return value.Sergey Kandaurov1-1/+1
2022-11-23Fixed segfault when switching off master process during upgrade.Maxim Dounin1-1/+3
Binary upgrades are not supported without master process, but it is, however, possible, that nginx running with master process is asked to upgrade binary, and the configuration file as available on disk at this time includes "master_process off;". If this happens, listening sockets inherited from the previous binary will have ls[i].previous set. But the old cycle on initial process startup, including startup after binary upgrade, is destroyed by ngx_init_cycle() once configuration parsing is complete. As a result, an attempt to dereference ls[i].previous in ngx_event_process_init() accesses already freed memory. Fix is to avoid looking into ls[i].previous if the old cycle is already freed. With this change it is also no longer needed to clear ls[i].previous in worker processes, so the relevant code was removed.
2022-11-23Disabled cloning of sockets without master process (ticket #2403).Maxim Dounin1-1/+4
Cloning of listening sockets for each worker process does not make sense when working without master process, and causes some of the connections not to be accepted if worker_processes is set to more than one and there are listening sockets configured with the reuseport flag. Fix is to disable cloning when master process is disabled.
2022-11-30QUIC: application init() callback.Roman Arutyunyan2-3/+21
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-10-13SSL: removed cast not needed after 5ffd76a9ccf3.Sergey Kandaurov1-1/+1
2022-10-12SSL: workaround for session timeout handling with TLSv1.3.Maxim Dounin2-0/+48
OpenSSL with TLSv1.3 updates the session creation time on session resumption and keeps the session timeout unmodified, making it possible to maintain the session forever, bypassing client certificate expiration and revocation. To make sure session timeouts are actually used, we now update the session creation time and reduce the session timeout accordingly. BoringSSL with TLSv1.3 ignores configured session timeouts and uses a hardcoded timeout instead, 7 days. So we update session timeout to the configured value as soon as a session is created.
2022-10-12SSL: optimized rotation of session ticket keys.Maxim Dounin2-19/+47
Instead of syncing keys with shared memory on each ticket operation, the code now does this only when the worker is going to change expiration of the current key, or going to switch to a new key: that is, usually at most once per second. To do so without races, the code maintains 3 keys: current, previous, and next. If a worker will switch to the next key earlier, other workers will still be able to decrypt new tickets, since they will be encrypted with the next key.
2022-10-12SSL: automatic rotation of session ticket keys.Maxim Dounin2-30/+160
As long as ssl_session_cache in shared memory is configured, session ticket keys are now automatically generated in shared memory, and rotated periodically. This can be beneficial from forward secrecy point of view, and also avoids increased CPU usage after configuration reloads. This also helps BoringSSL to properly resume sessions in configurations with multiple worker processes and no ssl_session_ticket_key directives, as BoringSSL tries to automatically rotate session ticket keys and does this independently in different worker processes, thus breaking session resumption between worker processes.
2022-10-12SSL: shorter debug messages about session tickets.Maxim Dounin1-3/+3
2022-10-12SSL: renamed session ticket key functions and data index.Maxim Dounin2-16/+13
Previously used names are way too long, renamed to simplify writing code.
2022-10-12SSL: renamed session ticket key type.Maxim Dounin2-21/+21
The ngx_ssl_session_ticket_key_t is way too long, renamed to ngx_ssl_ticket_key_t to simplify writing code.
2022-10-12SSL: style.Maxim Dounin1-0/+2
Runtime OCSP functions separated from configuration ones.
2022-10-12SSL: explicit clearing of expired sessions.Maxim Dounin1-0/+6
This reduces lifetime of session keying material in server's memory, and therefore can be beneficial from forward secrecy point of view.
2022-10-12SSL: single allocation in session cache on 32-bit platforms.Maxim Dounin2-48/+25
Given the present typical SSL session sizes, on 32-bit platforms it is now beneficial to store all data in a single allocation, since rbtree node + session id + ASN1 representation of a session takes 256 bytes of shared memory (36 + 32 + 150 = about 218 bytes plus SNI server name). Storing all data in a single allocation is beneficial for SNI names up to about 40 characters long and makes it possible to store about 4000 sessions in one megabyte (instead of about 3000 sessions now). This also slightly simplifies the code.
2022-10-12SSL: explicit session id length checking.Maxim Dounin1-2/+8
Session ids are not expected to be longer than 32 bytes, but this is theoretically possible with TLSv1.3, where session ids are essentially arbitrary and sent as session tickets. Since on 64-bit platforms we use fixed 32-byte buffer for session ids, added an explicit length check to make sure the buffer is large enough.
2022-10-12SSL: updated comment about session sizes.Maxim Dounin1-6/+6
Previous numbers are somewhat outdated, typical ASN1 representations of sessions are slightly bigger now.
2022-10-12SSL: reduced logging of session cache failures (ticket #621).Maxim Dounin2-2/+8
Session cache allocations might fail as long as the new session is different in size from the one least recently used (and freed when the first allocation fails). In particular, it might not be possible to allocate space for sessions with client certificates, since they are noticeably bigger than normal sessions. To ensure such allocation failures won't clutter logs, logging level changed to "warn", and logging is now limited to at most one warning per second.
2022-10-12SSL: disabled saving tickets to session cache.Maxim Dounin1-0/+17
OpenSSL tries to save TLSv1.3 sessions into session cache even when using tickets for stateless session resumption, "because some applications just want to know about the creation of a session". To avoid trashing session cache with useless data, we do not save such sessions now.
2022-09-08SSL: silenced GCC warnings when building with BoringSSL.Sergey Kandaurov1-1/+1
BoringSSL uses macro stub for SSL_CTX_set_ecdh_auto that expands to 1, which triggers -Wunused-value "statement with no effect" warnings.
2022-09-07Win32: fixed build on Windows with OpenSSL 3.0.x (ticket #2379).Maxim Dounin1-3/+3
SSL_sendfile() expects integer file descriptor as an argument, but nginx uses OS file handles (HANDLE) to work with files on Windows, and passing HANDLE instead of an integer correctly results in build failure. Since SSL_sendfile() is not expected to work on Windows anyway, the code is now disabled on Windows with appropriate compile-time checks.
2022-09-07SSL: fixed incorrect usage of #if instead of #ifdef.Maxim Dounin1-1/+1
In 2014ed60f17f, "#if SSL_CTRL_SET_ECDH_AUTO" test was incorrectly used instead of "#ifdef SSL_CTRL_SET_ECDH_AUTO". There is no practical difference, since SSL_CTRL_SET_ECDH_AUTO evaluates to a non-zero numeric value when defined, but anyway it's better to correctly test if the value is defined.
2022-09-07Events: fixed style and wrong error handling in the iocp module.Maxim Dounin1-4/+3
2022-11-30QUIC: removed cancelable flag from QUIC and HTTP/3 events.Roman Arutyunyan1-4/+0
All these events are created in context of a client connection and are deleted when the connection is closed. Setting ev->cancelable could trigger premature connection closure and a socket leak alert.
2022-10-19QUIC: idle mode for main connection.Roman Arutyunyan2-3/+19
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-09-07QUIC: do not send MAX_STREAMS in shutdown state.Roman Arutyunyan1-8/+9
No more streams are expected from client.
2022-08-22QUIC: defer stream removal until all its data is acked.Roman Arutyunyan3-23/+64
Previously, stream was kept alive until all its data is sent. This resulted in disabling retransmission of final part of stream when QUIC connection was closed right after closing stream connection.
2022-11-29QUIC: reusable mode for main connection.Roman Arutyunyan3-52/+98
The connection is automatically switched to this mode by transport layer when there are no non-cancelable streams. Currently, cancelable streams are HTTP/3 encoder/decoder/control streams.
2022-09-07QUIC: post close event for connection close.Roman Arutyunyan2-23/+26
Previously, close event was used only for close timeout, while read event was used for posting connection close.
2022-08-22QUIC: made ngx_quic_finalize_connecion() more graceful.Roman Arutyunyan1-18/+14
Previously, ngx_quic_finalize_connection() closed the connection with NGX_ERROR code, which resulted in immediate connection closure. Now the code is NGX_OK, which provides a more graceful shutdown with a timeout.
2022-09-07QUIC: treat qc->error == -1 as a missing error.Roman Arutyunyan1-3/+3
Previously, zero was used for this purpose. However, NGX_QUIC_ERR_NO_ERROR is zero too. As a result, NGX_QUIC_ERR_NO_ERROR was changed to NGX_QUIC_ERR_INTERNAL_ERROR when closing a QUIC connection.
2022-11-25QUIC: fixed computation of nonce with packet numbers beyond 2^32.Sergey Kandaurov1-4/+8
Prodded by Yu Zhu.
2022-11-23QUIC: fixed triggering stream read event (ticket #2409).Roman Arutyunyan1-1/+1
If a client packet carrying a stream data frame is not acked due to packet loss, the stream data is retransmitted later by client. It's also possible that the retransmitted range is bigger than before due to more stream data being available by then. If the original data was read out by the application, there would be no read event triggered by the retransmitted frame, even though it contains new data.