summaryrefslogtreecommitdiffhomepage
path: root/src/stream/ngx_stream_proxy_module.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
2019-04-24Variables support in proxy_upload_rate and proxy_download_rate.Ruslan Ermilov1-12/+17
2019-03-03SSL: fixed potential leak on memory allocation errors.Maxim Dounin1-0/+1
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.
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-11-21Upstream: revised upstream response time variables.Vladimir Homutov1-5/+9
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-07-17SSL: save sessions for upstream peers using a callback function.Sergey Kandaurov1-5/+22
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-06-04Stream: udp streams.Roman Arutyunyan1-50/+76
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-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.
2017-12-13Retain CAP_NET_RAW capability for transparent proxying.Roman Arutyunyan1-0/+6
The capability is retained automatically in unprivileged worker processes after changing UID if transparent proxying is enabled at least once in nginx configuration. The feature is only available in Linux.
2017-11-20Fixed worker_shutdown_timeout in various cases.Maxim Dounin1-0/+6
The ngx_http_upstream_process_upgraded() did not handle c->close request, and upgraded connections do not use the write filter. As a result, worker_shutdown_timeout did not affect upgraded connections (ticket #1419). Fix is to handle c->close in the ngx_http_request_handler() function, thus covering most of the possible cases in http handling. Additionally, mail proxying did not handle neither c->close nor c->error, and thus worker_shutdown_timeout did not work for mail connections. Fix is to add c->close handling to ngx_mail_proxy_handler(). Also, added explicit handling of c->close to stream proxy, ngx_stream_proxy_process_connection(). This improves worker_shutdown_timeout handling in stream, it will no longer wait for some data being transferred in a connection before closing it, and will also provide appropriate logging at the "info" level.
2017-09-12Stream: fixed logging UDP upstream timeout.Roman Arutyunyan1-1/+5
Previously, when the first UDP response packet was not received from the proxied server within proxy_timeout, no error message was logged before switching to the next upstream. Additionally, when one of succeeding response packets was not received within the timeout, the timeout error had low severity because it was logged as a client connection error as opposed to upstream connection error.
2017-09-11Stream: relaxed next upstream condition (ticket #1317).Roman Arutyunyan1-2/+6
When switching to a next upstream, some buffers could be stuck in the middle of the filter chain. A condition existed that raised an error when this happened. As it turned out, this condition prevented switching to a next upstream if ssl preread was used with the TCP protocol (see the ticket). In fact, the condition does not make sense for TCP, since after successful connection to an upstream switching to another upstream never happens. As for UDP, the issue with stuck buffers is unlikely to happen, but is still possible. Specifically, if a filter delays sending data to upstream. The condition can be relaxed to only check the "buffered" bitmask of the upstream connection. The new condition is simpler and fixes the ticket issue as well. Additionally, the upstream_out chain is now reset for UDP prior to connecting to a new upstream to prevent repeating the client data twice.
2017-05-26Introduced ngx_tcp_nodelay().Ruslan Ermilov1-16/+3
2017-04-18SSL: added support for TLSv1.3 in ssl_protocols directive.Sergey Kandaurov1-0/+1
Support for the TLSv1.3 protocol will be introduced in OpenSSL 1.1.1.
2017-01-11Stream: avoid infinite loop in case of socket read error.Vladimir Homutov1-2/+3
2016-12-26Stream: speed up TCP peer recovery.Roman Arutyunyan1-0/+5
Previously, an unavailable peer was considered recovered after a successful proxy session to this peer. Until then, only a single client connection per fail_timeout was allowed to be proxied to the peer. Since stream sessions can be long, it may take indefinite time for a peer to recover, limiting the ability of the peer to receive new connections. Now, a peer is considered recovered after a successful TCP connection is established to it. Balancers are notified of this event via the notify() callback.
2016-10-31Upstream: do not unnecessarily create per-request upstreams.Ruslan Ermilov1-17/+17
If proxy_pass (and friends) with variables evaluates an upstream specified with literal address, nginx always created a per-request upstream. Now, if there's a matching upstream specified in the configuration (either implicit or explicit), it will be used instead.
2016-10-31Upstream: added the ngx_http_upstream_resolved_t.name field.Ruslan Ermilov1-4/+2
This fixes inconsistency in what is stored in the "host" field. Normally it would contain the "host" part of the parsed URL (e.g., proxy_pass with variables), but for the case of an implicit upstream specified with literal address it contained the text representation of the socket address (that is, host including port for IP). Now the "host" field always contains the "host" part of the URL, while the text representation of the socket address is stored in the newly added "name" field. The ngx_http_upstream_create_round_robin_peer() function was modified accordingly in a way to be compatible with the code that does not know about the new "name" field. The "stream" code was similarly modified except for not adding compatibility in ngx_stream_upstream_create_round_robin_peer(). This change is also a prerequisite for the next change.
2016-10-31Upstream: removed unnecessary condition in proxy_eval() and friends.Ruslan Ermilov1-1/+1
The first condition added in d3454e719bbb should have just replaced the second one.
2016-10-19SSL: compatibility with BoringSSL.Maxim Dounin1-1/+2
BoringSSL changed SSL_set_tlsext_host_name() to be a real function with a (const char *) argument, so it now triggers a warning due to conversion from (u_char *). Added an explicit cast to silence the warning. Prodded by Piotr Sikora, Alessandro Ghedini.
2016-09-22Upstream: introduced u->upstream.Maxim Dounin1-0/+2
It holds upstream{} block configuration, including ones selected via run-time lookup using variables.
2016-09-15Stream: filters.Roman Arutyunyan1-78/+138
2016-09-02Stream: upstream response time variables.Vladimir Homutov1-0/+19
The $upstream_connect_time, $upstream_first_byte_time and $upstream_session_time variables keep corresponding times.
2016-09-02Stream: $upstream_bytes_sent and $upstream_bytes_received.Vladimir Homutov1-2/+12
2016-09-02Stream: the $upstream_addr variable.Vladimir Homutov1-0/+17
Keeps the full address of the upstream server. If several servers were contacted during proxying, their addresses are separated by commas, e.g. "192.168.1.1:80, 192.168.1.2:80".
2016-08-11Stream: the $status variable.Roman Arutyunyan1-37/+38
The stream session status is one of the following: 200 - normal completion 403 - access forbidden 500 - internal server error 502 - bad gateway 503 - limit conn
2016-07-26Stream: fixed build without stream_ssl_module (ticket #1032).Vladimir Homutov1-2/+2
2016-06-14Stream: variables in proxy_pass and proxy_ssl_name.Vladimir Homutov1-53/+323
2016-06-29Stream: got rid of pseudo variables.Vladimir Homutov1-29/+45
Stream limit_conn, upstream_hash and proxy modules now use complex values.
2016-06-15Stream: added preconfiguration step.Vladimir Homutov1-0/+1
2016-06-22Style.Roman Arutyunyan1-1/+0
2016-06-22Stream: use ngx_pcalloc() in ngx_stream_proxy_bind().Roman Arutyunyan1-1/+1
2016-06-20Stream: support for $remote_port in proxy_bind.Roman Arutyunyan1-9/+20
The following two types of bind addresses are supported in addition to $remote_addr and address literals: - $remote_addr:$remote_port - [$remote_addr]:$remote_port In both cases client remote address with port is used in upstream socket bind.
2016-06-20Upstream: support for port in proxy_bind and friends.Roman Arutyunyan1-1/+2
2016-06-20Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.Roman Arutyunyan1-21/+3
2016-06-15SSL: ngx_ssl_ciphers() to set list of ciphers.Tim Taubert1-7/+1
This patch moves various OpenSSL-specific function calls into the OpenSSL module and introduces ngx_ssl_ciphers() to make nginx more crypto-library-agnostic.
2015-12-18Upstream: the "transparent" parameter of proxy_bind and friends.Roman Arutyunyan1-17/+86
This parameter lets binding the proxy connection to a non-local address. Upstream will see the connection as coming from that address. When used with $remote_addr, upstream will accept the connection from real client address. Example: proxy_bind $remote_addr transparent;
2016-04-13Stream: prepared proxy_bind to accept parameters.Roman Arutyunyan1-9/+48
2016-03-18Stream: additional logging for UDP.Vladimir Homutov1-2/+5
2016-01-20Stream: UDP proxy.Roman Arutyunyan1-26/+114
2016-03-15Stream: post first read events from client and upstream.Roman Arutyunyan1-12/+10
The main proxy function ngx_stream_proxy_process() can terminate the stream session. The code, following it, should check its return code to make sure the session still exists. This happens in client and upstream initialization functions. Swapping ngx_stream_proxy_process() call with the code, that follows it, leaves the same problem vice versa. In future ngx_stream_proxy_process() will call ngx_stream_proxy_next_upstream() making it too complicated to know if stream session still exists after this call. Now ngx_stream_proxy_process() is called from posted event handlers in both places with no code following it. The posted event is automatically removed once session is terminated.
2016-02-11Stream: initialize variable right before using it.Roman Arutyunyan1-2/+2
2016-02-11Stream: removed useless typedef.Roman Arutyunyan1-3/+0
2015-10-06Stream: delete proxy connection timer after SSL handshake.Ruslan Ermilov1-0/+4
The timer remained active and could drop active SSL connection.
2015-08-17Win32: MSVC 2015 compatibility.Maxim Dounin1-5/+5
Resolved warnings about declarations that hide previous local declarations. Warnings about WSASocketA() being deprecated resolved by explicit use of WSASocketW() instead of WSASocket(). When compiling without IPv6 support, WinSock deprecated warnings are disabled to allow use of gethostbyname().
2015-08-12Style.Vladimir Homutov1-1/+1
2015-08-10Stream: the "tcp_nodelay" directive.Vladimir Homutov1-2/+22