summaryrefslogtreecommitdiffhomepage
path: root/src/stream (follow)
AgeCommit message (Collapse)AuthorFilesLines
2021-09-22Stream: added half-close support.Vladimir Homutov2-0/+37
The "proxy_half_close" directive enables handling of TCP half close. If enabled, connection to proxied server is kept open until both read ends get EOF. Write end shutdown is properly transmitted via proxy.
2021-08-16SSL: ciphers now set before loading certificates (ticket #2035).Maxim Dounin2-11/+11
To load old/weak server or client certificates it might be needed to adjust the security level, as introduced in OpenSSL 1.1.0. This change ensures that ciphers are set before loading the certificates, so security level changes via the cipher string apply to certificate loading.
2021-05-20Stream: the "fastopen" parameter of the "listen" directive.Ruslan Ermilov3-0/+32
Based on a patch by Anbang Wen.
2021-05-06Upstream: variables support in certificates.Maxim Dounin3-17/+125
2021-05-06Changed complex value slots to use NGX_CONF_UNSET_PTR.Maxim Dounin2-13/+7
With this change, it is now possible to use ngx_conf_merge_ptr_value() to merge complex values. This change follows much earlier changes in ngx_conf_merge_ptr_value() and ngx_conf_set_str_array_slot() in 1452:cd586e963db0 (0.6.10) and 1701:40d004d95d88 (0.6.22), and the change in ngx_conf_set_keyval_slot() (7728:485dba3e2a01, 1.19.4). To preserve compatibility with existing 3rd party modules, both NULL and NGX_CONF_UNSET_PTR are accepted for now.
2021-03-05SSL: fixed build by Sun C with old OpenSSL versions.Maxim Dounin2-4/+4
Sun C complains about "statement not reached" if a "return" is followed by additional statements.
2020-11-27Upstream: excluded down servers from the next_upstream tries.Ruslan Ermilov2-3/+18
Previously, the number of next_upstream tries included servers marked as "down", resulting in "no live upstreams" with the code 502 instead of the code derived from an attempt to connect to the last tried "up" server (ticket #2096).
2020-10-22Stream: proxy_ssl_conf_command directive.Maxim Dounin1-0/+34
Similarly to ssl_conf_command, proxy_ssl_conf_command can be used to set arbitrary OpenSSL configuration parameters as long as nginx is compiled with OpenSSL 1.0.2 or later, when connecting to upstream servers with SSL. Full list of available configuration commands can be found in the SSL_CONF_cmd manual page (https://www.openssl.org/docs/man1.1.1/man3/SSL_CONF_cmd.html).
2020-10-22SSL: ssl_conf_command directive.Maxim Dounin2-0/+34
With the ssl_conf_command directive it is now possible to set arbitrary OpenSSL configuration parameters as long as nginx is compiled with OpenSSL 1.0.2 or later. Full list of available configuration commands can be found in the SSL_CONF_cmd manual page (https://www.openssl.org/docs/man1.1.1/man3/SSL_CONF_cmd.html). In particular, this allows configuring PrioritizeChaCha option (ticket #1445): ssl_conf_command Options PrioritizeChaCha; It can be also used to configure TLSv1.3 ciphers in OpenSSL, which fails to configure them via the SSL_CTX_set_cipher_list() interface (ticket #1529): ssl_conf_command Ciphersuites TLS_CHACHA20_POLY1305_SHA256; Configuration commands are applied after nginx own configuration for SSL, so they can be used to override anything set by nginx. Note though that configuring OpenSSL directly with ssl_conf_command might result in a behaviour nginx does not expect, and should be done with care.
2020-08-28Stream: set module.Pavel Pautov1-0/+226
Adds 'set' directive to the stream server context.
2020-06-08Stream: fixed processing of zero length UDP packets (ticket #1982).Vladimir Homutov2-2/+4
2019-11-18Limit conn: added shared context.Roman Arutyunyan1-46/+43
Previously only an rbtree was associated with a limit_conn. To make it possible to associate more data with a limit_conn, shared context is introduced similar to limit_req. Also, shared pool pointer is kept in a way similar to limit_req.
2019-11-18Limit conn: $limit_conn_status variable.Roman Arutyunyan2-1/+75
The variable takes one of the values: PASSED, REJECTED or REJECTED_DRY_RUN.
2019-11-19Limit conn: limit_conn_dry_run directive.Roman Arutyunyan1-1/+23
A new directive limit_conn_dry_run allows enabling the dry run mode. In this mode connections are not rejected, but reject status is logged as usual.
2019-10-21Parsing server PROXY protocol address and port (ticket #1206).Roman Arutyunyan1-5/+18
New variables $proxy_protocol_server_addr and $proxy_protocol_server_port are added both to HTTP and Stream.
2019-10-21Core: moved PROXY protocol fields out of ngx_connection_t.Roman Arutyunyan2-8/+23
Now a new structure ngx_proxy_protocol_t holds these fields. This allows to add more PROXY protocol fields in the future without modifying the connection structure.
2019-09-16SSL: fixed ssl_verify_client error message.Sergey Kandaurov1-1/+1
2019-05-23Upstream hash: fall back to round-robin if hash key is empty.Niklas Keller1-2/+2
2016-04-11SSL: removed OpenSSL 0.9.7 compatibility.Sergey Kandaurov1-4/+1
2019-04-24Variables support in proxy_upload_rate and proxy_download_rate.Ruslan Ermilov2-12/+20
2019-04-24Added ngx_http_set_complex_value_size_slot().Ruslan Ermilov2-0/+69
If a complex value is expected to be of type size_t, and the compiled value is constant, the constant size_t value is remembered at compile time. The value is accessed through ngx_http_complex_value_size() which either returns the remembered constant or evaluates the expression and parses it as size_t.
2019-03-15Multiple addresses in "listen".Roman Arutyunyan3-79/+41
Previously only one address was used by the listen directive handler even if host name resolved to multiple addresses. Now a separate listening socket is created for each address.
2019-03-03SSL: fixed potential leak on memory allocation errors.Maxim Dounin2-0/+2
If ngx_pool_cleanup_add() fails, we have to clean just created SSL context manually, thus appropriate call added. Additionally, ngx_pool_cleanup_add() moved closer to ngx_ssl_create() in the ngx_http_ssl_module, to make sure there are no leaks due to intermediate code.
2019-03-03SSL: server name callback changed to return SSL_TLSEXT_ERR_OK.Maxim Dounin1-0/+19
OpenSSL 1.1.1 does not save server name to the session if server name callback returns anything but SSL_TLSEXT_ERR_OK, thus breaking the $ssl_server_name variable in resumed sessions. Since $ssl_server_name can be used even if we've selected the default server and there are no other servers, it looks like the only viable solution is to always return SSL_TLSEXT_ERR_OK regardless of the actual result. To fix things in the stream module as well, added a dummy server name callback which always returns SSL_TLSEXT_ERR_OK.
2019-02-25SSL: fixed possible segfault with dynamic certificates.Maxim Dounin1-2/+2
A virtual server may have no SSL context if it does not have certificates defined, so we have to use config of the ngx_http_ssl_module from the SSL context in the certificate callback. To do so, it is now passed as the argument of the callback. The stream module doesn't really need any changes, but was modified as well to match http code.
2019-02-25SSL: adjusted session id context with dynamic certificates.Maxim Dounin1-1/+1
Dynamic certificates re-introduce problem with incorrect session reuse (AKA "virtual host confusion", CVE-2014-3616), since there are no server certificates to generate session id context from. To prevent this, session id context is now generated from ssl_certificate directives as specified in the configuration. This approach prevents incorrect session reuse in most cases, while still allowing sharing sessions across multiple machines with ssl_session_ticket_key set as long as configurations are identical.
2019-02-25SSL: dynamic certificate loading in the stream module.Maxim Dounin2-4/+179
2018-12-27Stream: do not split datagrams when limiting proxy rate.Roman Arutyunyan1-1/+1
Previously, when using proxy_upload_rate and proxy_download_rate, the buffer size for reading from a socket could be reduced as a result of rate limiting. For connection-oriented protocols this behavior is normal since unread data will normally be read at the next iteration. But for datagram-oriented protocols this is not the case, and unread part of the datagram is lost. Now buffer size is not limited for datagrams. Rate limiting still works in this case by delaying the next reading event.
2019-01-14Prevented scheduling events on a shared connection.Roman Arutyunyan1-2/+2
A shared connection does not own its file descriptor, which means that ngx_handle_read_event/ngx_handle_write_event calls should do nothing for it. Currently the c->shared flag is checked in several places in the stream proxy module prior to calling these functions. However it was not done everywhere. Missing checks could lead to calling ngx_handle_read_event/ngx_handle_write_event on shared connections. The problem manifested itself when using proxy_upload_rate and resulted in either duplicate file descriptor error (e.g. with epoll) or incorrect further udp packet processing (e.g. with kqueue). The fix is to set and reset the event active flag in a way that prevents ngx_handle_read_event/ngx_handle_write_event from scheduling socket events.
2018-12-14Geo: fixed handling of AF_UNIX client addresses (ticket #1684).Maxim Dounin1-0/+13
Previously, AF_UNIX client addresses were handled as AF_INET, leading to unexpected results.
2018-11-26Negative size buffers detection.Maxim Dounin1-4/+36
In the past, there were several security issues which resulted in worker process memory disclosure due to buffers with negative size. It looks reasonable to check for such buffers in various places, much like we already check for zero size buffers. While here, removed "#if 1 / #endif" around zero size buffer checks. It looks highly unlikely that we'll disable these checks anytime soon.
2018-11-21Upstream: revised upstream response time variables.Vladimir Homutov3-14/+17
Variables now do not depend on presence of the HTTP status code in response. If the corresponding event occurred, variables contain time between request creation and the event, and "-" otherwise. Previously, intermediate value of the $upstream_response_time variable held unix timestamp.
2018-11-12Stream: proxy_requests directive.Vladimir Homutov1-2/+25
The directive allows to drop binding between a client and existing UDP stream session after receiving a specified number of packets. First packet from the same client address and port will start a new session. Old session continues to exist and will terminate at moment defined by configuration: either after receiving the expected number of responses, or after timeout, as specified by the "proxy_responses" and/or "proxy_timeout" directives. By default, proxy_requests is zero (disabled).
2018-11-12Stream: session completion check code moved to a separate function.Vladimir Homutov1-38/+76
The code refactored to simplify the ngx_stream_proxy_process() function and facilitate adding new session termination conditions.
2018-10-03Upstream: proxy_socket_keepalive and friends.Vladimir Homutov1-0/+16
The directives enable the use of the SO_KEEPALIVE option on upstream connections. By default, the value is left unchanged.
2018-08-29Stream: avoid potential infinite loop at preread phase.Roman Arutyunyan1-15/+21
Previously the preread phase code ignored NGX_AGAIN value returned from c->recv() and relied only on c->read->ready. But this flag is not reliable and should only be checked for optimization purposes. For example, when using SSL, c->read->ready may be set when no input is available. This can lead to calling preread handler infinitely in a loop.
2018-07-18Stream ssl_preread: added SSLv2 Client Hello support.Sergey Kandaurov1-2/+14
In particular, it was not possible to obtain SSLv2 protocol version.
2018-07-17SSL: save sessions for upstream peers using a callback function.Sergey Kandaurov2-6/+23
In TLSv1.3, NewSessionTicket messages arrive after the handshake and can come at any time. Therefore we use a callback to save the session when we know about it. This approach works for < TLSv1.3 as well. The callback function is set once per location on merge phase. Since SSL_get_session() in BoringSSL returns an unresumable session for TLSv1.3, peer save_session() methods have been updated as well to use a session supplied within the callback. To preserve API, the session is cached in c->ssl->session. It is preferably accessed in save_session() methods by ngx_ssl_get_session() and ngx_ssl_get0_session() wrappers.
2018-07-12Events: moved sockets cloning to ngx_event_init_conf().Maxim Dounin1-4/+0
Previously, listenings sockets were not cloned if the worker_processes directive was specified after "listen ... reuseport". This also simplifies upcoming configuration check on the number of worker connections, as it needs to know the number of listening sockets before cloning.
2018-07-11Stream ssl_preread: $ssl_preread_protocol variable.Roman Arutyunyan1-6/+93
The variable keeps the latest SSL protocol version supported by the client. The variable has the same format as $ssl_protocol. The version is read from the client_version field of ClientHello. If the supported_versions extension is present in the ClientHello, then the version is set to TLSv1.3.
2018-06-15Upstream: ngx_http_upstream_random module.Vladimir Homutov1-0/+502
The module implements random load-balancing algorithm with optional second choice. In the latter case, the best of two servers is chosen, accounting number of connections and server weight. Example: upstream u { random [two [least_conn]]; server 127.0.0.1:8080; server 127.0.0.1:8081; server 127.0.0.1:8082; server 127.0.0.1:8083; }
2018-06-14Upstream: improved peer selection concurrency for hash and ip_hash.Ruslan Ermilov1-1/+7
2018-06-04Stream: udp streams.Roman Arutyunyan2-50/+77
Previously, only one client packet could be processed in a udp stream session even though multiple response packets were supported. Now multiple packets coming from the same client address and port are delivered to the same stream session. If it's required to maintain a single stream of data, nginx should be configured in a way that all packets from a client are delivered to the same worker. On Linux and DragonFly BSD the "reuseport" parameter should be specified for this. Other systems do not currently provide appropriate mechanisms. For these systems a single stream of udp packets is only guaranteed in single-worker configurations. The proxy_response directive now specifies how many packets are expected in response to a single client packet.
2018-05-07Silenced -Wcast-function-type warnings (closes #1546).Sergey Kandaurov1-6/+7
Cast to intermediate "void *" to lose compiler knowledge about the original type and pass the warning. This is not a real fix but rather a workaround. Found by gcc8.
2018-04-24SSL: detect "listen ... ssl" without certificates (ticket #178).Maxim Dounin3-13/+37
In mail and stream modules, no certificate provided is a fatal condition, much like with the "ssl" and "starttls" directives. In http, "listen ... ssl" can be used in a non-default server without certificates as long as there is a certificate in the default one, so missing certificate is only fatal for default servers.
2018-03-22Stream: set action before each recv/send while proxying.Roman Arutyunyan1-2/+11
Now it's clear from log error message if the error occurred on client or upstream side.
2018-03-12Style.Roman Arutyunyan1-3/+3
2018-03-12Stream ssl_preread: $ssl_preread_alpn_protocols variable.Roman Arutyunyan1-6/+122
The variable keeps a comma-separated list of protocol names from ALPN TLS extension defined by RFC 7301.
2018-03-07Improved code readablity.Ruslan Ermilov1-2/+6
No functional changes.
2018-03-05Style.Maxim Dounin1-1/+2