summaryrefslogtreecommitdiffhomepage
path: root/src/stream (follow)
AgeCommit message (Collapse)AuthorFilesLines
2024-08-09Stream ssl_preread: do not reallocate a parsed SNI host.Sergey Kandaurov1-1/+1
We own this memory from the session pool.
2024-06-27Stream: allow servers with no handler.Roman Arutyunyan1-7/+7
Previously handlers were mandatory. However they are not always needed. For example, a server configured with ssl_reject_handshake does not need a handler. Such servers required a fake handler to pass the check. Now handler absence check is moved to runtime. If handler is missing, the connection is closed with 500 code.
2024-05-03Stream pass: disabled passing from or to udp.Roman Arutyunyan1-0/+9
Passing from udp was not possible for the most part due to preread buffer restriction. Passing to udp could occasionally work, but the connection would still be bound to the original listen rbtree, which prevented it from being deleted on connection closure.
2024-04-11Stream pass: limited the number of passes per connection.Roman Arutyunyan1-0/+51
Previously a cycle in pass configuration resulted in stack overflow.
2024-03-18Fixed undefined behaviour with IPv4-mapped IPv6 addresses.Sergey Kandaurov3-4/+4
Previously, it could result when left-shifting signed integer due to implicit integer promotion, such that the most significant bit appeared on the sign bit. In practice, though, this results in the same left value as with an explicit cast, at least on known compilers, such as GCC and Clang. The reason is that in_addr_t, which is equivalent to uint32_t and same as "unsigned int" in ILP32 and LP64 data type models, has the same type width as the intermediate after integer promotion, so there's no side effects such as sign-extension. This explains why adding an explicit cast does not change object files in practice. Found with UndefinedBehaviorSanitizer (shift). Based on a patch by Piotr Sikora.
2024-03-14Geo: fixed uninitialized memory access.Piotr Sikora1-3/+1
While copying ngx_http_variable_value_t structures to geo binary base in ngx_http_geo_copy_values(), and similarly in the stream module, uninitialized parts of these structures are copied as well. These include the "escape" field and possible holes. Calculating crc32 of this data triggers uninitialized memory access. Found with MemorySanitizer. Signed-off-by: Piotr Sikora <piotr@aviatrix.com>
2024-03-22Stream: $server_name.Sergey Kandaurov1-0/+23
2024-01-18Stream: moved fastopen compatibility check.Roman Arutyunyan1-6/+6
The move makes the code look similar to the corresponding code in http module.
2024-03-22Stream: the "setfib" parameter of the "listen" directive.Sergey Kandaurov3-0/+26
The FreeBSD SO_SETFIB support.
2024-03-22Stream: the "accept_filter" parameter of the "listen" directive.Sergey Kandaurov3-0/+28
The FreeBSD accept filters support.
2024-03-22Stream: the "deferred" parameter of the "listen" directive.Sergey Kandaurov3-0/+24
The Linux TCP_DEFER_ACCEPT support.
2024-03-22Stream: reshuffled ngx_stream_listen_opt_t fields.Sergey Kandaurov1-6/+7
In preparation for adding more parameters to the listen directive, and to be in sync with the corresponding structure in the http module. No functional changes.
2024-03-22Overhauled some diagnostic messages akin to 1b05b9bbcebf.Sergey Kandaurov1-2/+2
2024-03-22Stream: using ngx_stream_ssl_srv_conf_t *sscf naming convention.Sergey Kandaurov2-98/+98
Originally, the stream module was developed based on the mail module, following the existing style. Then it was diverged to closely follow the http module development. This change updates style to use sscf naming convention troughout the stream module, which matches the http module code style. No functional changes.
2024-02-21Stream: ngx_stream_pass_module.Roman Arutyunyan1-0/+276
The module allows to pass connections from Stream to other modules such as HTTP or Mail, as well as back to Stream. Previously, this was only possible with proxying. Connections with preread buffer read out from socket cannot be passed. The module allows selective SSL termination based on SNI. stream { server { listen 8000 default_server; ssl_preread on; ... } server { listen 8000; server_name foo.example.com; pass 127.0.0.1:8001; # to HTTP } server { listen 8000; server_name bar.example.com; ... } } http { server { listen 8001 ssl; ... location / { root html; } } }
2023-12-14Stream: virtual servers.Roman Arutyunyan7-354/+1416
Server name is taken either from ngx_stream_ssl_module or ngx_stream_ssl_preread_module. The change adds "default_server" parameter to the "listen" directive, as well as the following directives: "server_names_hash_max_size", "server_names_hash_bucket_size", "server_name" and "ssl_reject_handshake".
2023-12-13Stream: socket peek in preread phase.Roman Arutyunyan1-43/+146
Previously, preread buffer was always read out from socket, which made it impossible to terminate SSL on the connection without introducing additional SSL BIOs. The following patches will rely on this. Now, when possible, recv(MSG_PEEK) is used instead, which keeps data in socket. It's called if SSL is not already terminated and if an egde-triggered event method is used. For epoll, EPOLLRDHUP support is also required.
2023-03-24SSL: enabled TLSv1.3 by default.Maxim Dounin2-4/+6
2022-12-18Fixed port ranges support in the listen directive.Valentin Bartenev1-1/+1
Ports difference must be respected when checking addresses for duplicates, otherwise configurations like this are broken: listen 127.0.0.1:6000-6005 It was broken by 4cc2bfeff46c (nginx 1.23.3).
2022-12-01SSL: fixed ngx_ssl_recv() to reset c->read->ready after errors.Maxim Dounin1-3/+2
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-23Filtering duplicate addresses in listen (ticket #2400).Maxim Dounin1-13/+36
Due to the glibc bug[1], getaddrinfo("localhost") with AI_ADDRCONFIG on a typical host with glibc and without IPv6 returns two 127.0.0.1 addresses, and therefore "listen localhost:80;" used to result in "duplicate ... address and port pair" after 4f9b72a229c1. Fix is to explicitly filter out duplicate addresses returned during resolution of a name. [1] https://sourceware.org/bugzilla/show_bug.cgi?id=14969
2022-11-02Increased maximum read PROXY protocol header size.Roman Arutyunyan1-4/+6
Maximum size for reading the PROXY protocol header is increased to 4096 to accommodate a bigger number of TLVs, which are supported since cca4c8a715de. Maximum size for writing the PROXY protocol header is not changed since only version 1 is currently supported.
2022-10-17SSL: improved validation of ssl_session_cache and ssl_ocsp_cache.Sergey Kandaurov1-1/+1
Now it properly detects invalid shared zone configuration with omitted size. Previously it used to read outside of the buffer boundary. Found with AddressSanitizer.
2022-10-12PROXY protocol v2 TLV variables.Roman Arutyunyan1-0/+39
The variables have prefix $proxy_protocol_tlv_ and are accessible by name and by type. Examples are: $proxy_protocol_tlv_0x01, $proxy_protocol_tlv_alpn.
2022-06-29Upstream: optimized use of SSL contexts (ticket #1234).Maxim Dounin1-6/+58
To ensure optimal use of memory, SSL contexts for proxying are now inherited from previous levels as long as relevant proxy_ssl_* directives are not redefined. Further, when no proxy_ssl_* directives are redefined in a server block, we now preserve plcf->upstream.ssl in the "http" section configuration to inherit it to all servers. Similar changes made in uwsgi, grpc, and stream proxy.
2022-05-23Stream: don't flush empty buffers created for read errors.Aleksei Bavshin1-1/+1
When we generate the last_buf buffer for an UDP upstream recv error, it does not contain any data from the wire. ngx_stream_write_filter attempts to forward it anyways, which is incorrect (e.g., UDP upstream ECONNREFUSED will be translated to an empty packet). This happens because we mark the buffer as both 'flush' and 'last_buf', and ngx_stream_write_filter has special handling for flush with certain types of connections (see d127837c714f, 32b0ba4855a6). The flags are meant to be mutually exclusive, so the fix is to ensure that flush and last_buf are not set at the same time. Reproduction: stream { upstream unreachable { server 127.0.0.1:8880; } server { listen 127.0.0.1:8998 udp; proxy_pass unreachable; } } 1 0.000000000 127.0.0.1 → 127.0.0.1 UDP 47 45588 → 8998 Len=5 2 0.000166300 127.0.0.1 → 127.0.0.1 UDP 47 51149 → 8880 Len=5 3 0.000172600 127.0.0.1 → 127.0.0.1 ICMP 75 Destination unreachable (Port unreachable) 4 0.000202400 127.0.0.1 → 127.0.0.1 UDP 42 8998 → 45588 Len=0 Fixes d127837c714f.
2022-06-07Upstream: handling of certificates specified as an empty string.Sergey Kandaurov1-4/+7
Now, if the directive is given an empty string, such configuration cancels loading of certificates, in particular, if they would be otherwise inherited from the previous level. This restores previous behaviour, before variables support in certificates was introduced (3ab8e1e2f0f7).
2022-02-03HTTP/2: made it possible to flush response headers (ticket #1743).Maxim Dounin1-1/+1
Response headers can be buffered in the SSL buffer. But stream's fake connection buffered flag did not reflect this, so any attempts to flush the buffer without sending additional data were stopped by the write filter. It does not seem to be possible to reflect this in fc->buffered though, as we never known if main connection's c->buffered corresponds to the particular stream or not. As such, fc->buffered might prevent request finalization due to sending data on some other stream. Fix is to implement handling of flush buffers when the c->need_flush_buf flag is set, similarly to the existing last buffer handling. The same flag is now used for UDP sockets in the stream module instead of explicit checking of c->type.
2021-11-01SSL: $ssl_curve (ticket #2135).Sergey Kandaurov1-0/+3
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-10-21Style: added missing "static" specifiers.Maxim Dounin1-3/+4
Mostly found by gcc -Wtraditional, per "non-static declaration of ... follows static declaration [-Wtraditional]" warnings.
2021-10-19Stream: the "ssl_alpn" directive.Vladimir Homutov2-0/+118
The directive sets the server list of supported application protocols and requires one of this protocols to be negotiated if client is using ALPN.
2021-10-14SSL: added $ssl_alpn_protocol variable.Vladimir Homutov1-0/+3
The variable contains protocol selected by ALPN during handshake and is empty otherwise.
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