]> git.kaiwu.me - nginx.git/log
nginx.git
9 years agorelease-1.11.3 tag
Maxim Dounin [Tue, 26 Jul 2016 13:58:58 +0000 (16:58 +0300)]
release-1.11.3 tag

9 years agonginx-1.11.3-RELEASE release-1.11.3
Maxim Dounin [Tue, 26 Jul 2016 13:58:58 +0000 (16:58 +0300)]
nginx-1.11.3-RELEASE

9 years agoFixed regex captures handling without PCRE.
Vladimir Homutov [Wed, 6 Jul 2016 11:33:40 +0000 (14:33 +0300)]
Fixed regex captures handling without PCRE.

If PCRE is disabled, captures were treated as normal variables in
ngx_http_script_compile(), while code calculating flushes array length in
ngx_http_compile_complex_value() did not account captures as variables.
This could lead to write outside of the array boundary when setting
last element to -1.

Found with AddressSanitizer.

9 years agoStream: variables in proxy_pass and proxy_ssl_name.
Vladimir Homutov [Tue, 14 Jun 2016 15:29:46 +0000 (18:29 +0300)]
Stream: variables in proxy_pass and proxy_ssl_name.

9 years agoHTTP/2: flushing of the SSL buffer in transition to the idle state.
Valentin Bartenev [Tue, 19 Jul 2016 17:34:17 +0000 (20:34 +0300)]
HTTP/2: flushing of the SSL buffer in transition to the idle state.

It fixes potential connection leak if some unsent data was left in the SSL
buffer.  Particularly, that could happen when a client canceled the stream
after the HEADERS frame has already been created.  In this case no other
frames might be produced and the HEADERS frame alone didn't flush the buffer.

9 years agoHTTP/2: refactored ngx_http_v2_send_output_queue().
Valentin Bartenev [Tue, 19 Jul 2016 17:34:02 +0000 (20:34 +0300)]
HTTP/2: refactored ngx_http_v2_send_output_queue().

Now it returns NGX_AGAIN if there's still data to be sent.

9 years agoHTTP/2: fixed send timer handling.
Valentin Bartenev [Tue, 19 Jul 2016 17:31:09 +0000 (20:31 +0300)]
HTTP/2: fixed send timer handling.

Checking for return value of c->send_chain() isn't sufficient since there
are data can be left in the SSL buffer.  Now the wew->ready flag is used
instead.

In particular, this fixed a connection leak in cases when all streams were
closed, but there's still some data to be sent in the SSL buffer and the
client forgot about the connection.

9 years agoHTTP/2: avoid sending output queue if there's nothing to send.
Valentin Bartenev [Tue, 19 Jul 2016 17:30:21 +0000 (20:30 +0300)]
HTTP/2: avoid sending output queue if there's nothing to send.

Particularly this fixes alerts on OS X and NetBSD systems when HTTP/2 is
configured over plain TCP sockets.

On these systems calling writev() with no data leads to EINVAL errors
being logged as "writev() failed (22: Invalid argument) while processing
HTTP/2 connection".

9 years agoHTTP/2: always handle streams in error state.
Valentin Bartenev [Tue, 19 Jul 2016 17:22:44 +0000 (20:22 +0300)]
HTTP/2: always handle streams in error state.

Previously, a stream could be closed by timeout if it was canceled
while its send window was exhausted.

9 years agoHTTP/2: prevented output of the HEADERS frame for canceled streams.
Valentin Bartenev [Tue, 19 Jul 2016 17:22:44 +0000 (20:22 +0300)]
HTTP/2: prevented output of the HEADERS frame for canceled streams.

It's useless to generate HEADERS if the stream has been canceled already.

9 years agoHTTP/2: always send GOAWAY while worker is shutting down.
Valentin Bartenev [Tue, 19 Jul 2016 17:22:44 +0000 (20:22 +0300)]
HTTP/2: always send GOAWAY while worker is shutting down.

Previously, if the worker process exited, GOAWAY was sent to connections in
idle state, but connections with active streams were closed without GOAWAY.

9 years agoEvents: support for EPOLLEXCLUSIVE.
Valentin Bartenev [Fri, 15 Jul 2016 12:18:57 +0000 (15:18 +0300)]
Events: support for EPOLLEXCLUSIVE.

This flag appeared in Linux 4.5 and is useful for avoiding thundering herd
problem.

The current Linux kernel implementation walks the list of exclusive waiters,
and queues an event to each epfd, until it finds the first waiter that has
threads blocked on it via epoll_wait().

9 years agoStyle: sorted epoll flags.
Valentin Bartenev [Fri, 15 Jul 2016 12:18:57 +0000 (15:18 +0300)]
Style: sorted epoll flags.

9 years agoEvents: the "accept_mutex" directive is turned off by default.
Valentin Bartenev [Fri, 15 Jul 2016 12:18:57 +0000 (15:18 +0300)]
Events: the "accept_mutex" directive is turned off by default.

Now it is believed that the accept mutex brings more harm than benefits.
Especially in various benchmarks it often results in situation where only
one worker grabs all connections.

9 years agoStream: split_clients module.
Vladimir Homutov [Tue, 12 Jul 2016 14:34:52 +0000 (17:34 +0300)]
Stream: split_clients module.

9 years agoStream: geo module.
Vladimir Homutov [Thu, 30 Jun 2016 13:12:50 +0000 (16:12 +0300)]
Stream: geo module.

9 years agoStream: geoip module.
Vladimir Homutov [Tue, 12 Jul 2016 14:34:43 +0000 (17:34 +0300)]
Stream: geoip module.

9 years agoStream: style.
Vladimir Homutov [Tue, 12 Jul 2016 14:34:40 +0000 (17:34 +0300)]
Stream: style.

9 years agoStream: individual build options for modules.
Vladimir Homutov [Tue, 12 Jul 2016 09:38:01 +0000 (12:38 +0300)]
Stream: individual build options for modules.

9 years agoHTTP/2: avoid left-shifting signed integer into the sign bit.
Sergey Kandaurov [Thu, 7 Jul 2016 18:03:21 +0000 (21:03 +0300)]
HTTP/2: avoid left-shifting signed integer into the sign bit.

On non-aligned platforms, properly cast argument before left-shifting it in
ngx_http_v2_parse_uint32 that is used with u_char.  Otherwise it propagates
to int to hold the value and can step over the sign bit.  Usually, on known
compilers, this results in negation.  Furthermore, a subsequent store into a
wider type, that is ngx_uint_t on 64-bit platforms, results in sign-extension.

In practice, this can be observed in debug log as a very large exclusive bit
value, when client sent PRIORITY frame with exclusive bit set:

: *14 http2 PRIORITY frame sid:5 on 1 excl:8589934591 weight:17

Found with UndefinedBehaviorSanitizer.

9 years agoAvoid left-shifting integers into the sign bit, which is undefined.
Sergey Kandaurov [Thu, 7 Jul 2016 18:02:28 +0000 (21:02 +0300)]
Avoid left-shifting integers into the sign bit, which is undefined.

Found with UndefinedBehaviorSanitizer.

9 years agoConfigure: stop polluting NGX_ namespace.
Piotr Sikora [Mon, 27 Jun 2016 22:00:06 +0000 (15:00 -0700)]
Configure: stop polluting NGX_ namespace.

While there, fix the only test that used alternative variable name.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
9 years agoConfigure: fix build with -Werror=old-style-definition.
Piotr Sikora [Mon, 27 Jun 2016 22:00:05 +0000 (15:00 -0700)]
Configure: fix build with -Werror=old-style-definition.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
9 years agoConfigure: fix build with -Werror=nonnull.
Piotr Sikora [Mon, 27 Jun 2016 22:00:04 +0000 (15:00 -0700)]
Configure: fix build with -Werror=nonnull.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
9 years agoConfigure: fix build with -Werror=unused-but-set-variable.
Piotr Sikora [Mon, 27 Jun 2016 22:00:03 +0000 (15:00 -0700)]
Configure: fix build with -Werror=unused-but-set-variable.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
9 years agoConfigure: fix build with -Werror=unused-value.
Piotr Sikora [Mon, 27 Jun 2016 22:00:02 +0000 (15:00 -0700)]
Configure: fix build with -Werror=unused-value.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
9 years agoConfigure: style.
Piotr Sikora [Mon, 27 Jun 2016 22:00:01 +0000 (15:00 -0700)]
Configure: style.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
10 years agoConfigure: remove auto/lib/test, unused since nginx-0.1.2.
Piotr Sikora [Sat, 24 Oct 2015 01:21:33 +0000 (18:21 -0700)]
Configure: remove auto/lib/test, unused since nginx-0.1.2.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
9 years agoStream: resolver.
Vladimir Homutov [Thu, 7 Jul 2016 10:15:31 +0000 (13:15 +0300)]
Stream: resolver.

9 years agoUse NGX_MAX_PATH_LEVEL where appropriate.
Ruslan Ermilov [Wed, 6 Jul 2016 10:22:29 +0000 (13:22 +0300)]
Use NGX_MAX_PATH_LEVEL where appropriate.

The macro was unused since 0.7.44.

9 years agoVersion bump.
Ruslan Ermilov [Wed, 6 Jul 2016 10:10:06 +0000 (13:10 +0300)]
Version bump.

9 years agorelease-1.11.2 tag
Maxim Dounin [Tue, 5 Jul 2016 15:56:14 +0000 (18:56 +0300)]
release-1.11.2 tag

9 years agonginx-1.11.2-RELEASE release-1.11.2
Maxim Dounin [Tue, 5 Jul 2016 15:56:14 +0000 (18:56 +0300)]
nginx-1.11.2-RELEASE

9 years agoUpdated PCRE used for win32 builds.
Maxim Dounin [Tue, 5 Jul 2016 15:30:56 +0000 (18:30 +0300)]
Updated PCRE used for win32 builds.

9 years agoStream: return module.
Roman Arutyunyan [Wed, 18 May 2016 19:08:49 +0000 (22:08 +0300)]
Stream: return module.

9 years agoStream: SSL-related variables.
Vladimir Homutov [Wed, 29 Jun 2016 09:52:52 +0000 (12:52 +0300)]
Stream: SSL-related variables.

9 years agoStream: got rid of pseudo variables.
Vladimir Homutov [Wed, 29 Jun 2016 09:46:12 +0000 (12:46 +0300)]
Stream: got rid of pseudo variables.

Stream limit_conn, upstream_hash and proxy modules now use complex values.

9 years agoStream: map module.
Vladimir Homutov [Wed, 29 Jun 2016 09:46:12 +0000 (12:46 +0300)]
Stream: map module.

9 years agoStream: core module variables.
Vladimir Homutov [Tue, 14 Jun 2016 15:28:14 +0000 (18:28 +0300)]
Stream: core module variables.

9 years agoStream: variables and script.
Vladimir Homutov [Mon, 4 Jul 2016 13:37:36 +0000 (16:37 +0300)]
Stream: variables and script.

This is a port of corresponding http code with unrelated features excluded.

9 years agoStream: added preconfiguration step.
Vladimir Homutov [Wed, 15 Jun 2016 12:10:24 +0000 (15:10 +0300)]
Stream: added preconfiguration step.

9 years agoSub filter: eliminate unnecessary buffering.
Roman Arutyunyan [Sat, 2 Jul 2016 12:59:53 +0000 (15:59 +0300)]
Sub filter: eliminate unnecessary buffering.

Previously, when a buffer was processed by the sub filter, its final bytes
could be buffered by the filter even if they don't match any pattern.
This happened because the Boyer-Moore algorithm, employed by the sub filter
since b9447fc457b4 (1.9.4), matches the last characters of patterns prior to
checking other characters.  If the last character is out of scope, initial
bytes of a potential match are buffered until the last character is available.

Now, after receiving a flush or recycled buffer, the filter performs
additional checks to reduce the number of buffered bytes.  The potential match
is checked against the initial parts of all patterns.  Non-matching bytes are
not buffered.  This improves processing of a chunked response from upstream
by sending the entire chunks without buffering unless a partial match is found
at the end of a chunk.

9 years agoSub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan [Sat, 2 Jul 2016 12:59:52 +0000 (15:59 +0300)]
Sub filter: introduced the ngx_http_sub_match() function.

No functional changes.

9 years agoInternal md5 and sha1 implementations are now always used.
Maxim Dounin [Thu, 30 Jun 2016 15:57:39 +0000 (18:57 +0300)]
Internal md5 and sha1 implementations are now always used.

This reduces the number of moving parts in ABI compatibility checks.
Additionally, it also allows to use OpenSSL in FIPS mode while still
using md5 for non-security tasks.

9 years agoRemoved unused flag accept_context_updated from ngx_event_t.
Ruslan Ermilov [Wed, 29 Jun 2016 11:30:00 +0000 (14:30 +0300)]
Removed unused flag accept_context_updated from ngx_event_t.

Also, removed practically unused flag accept_context_updated from
ngx_connection_t.

9 years agoStyle.
Roman Arutyunyan [Mon, 27 Jun 2016 15:42:29 +0000 (18:42 +0300)]
Style.

9 years agoHTTP/2: style.
Piotr Sikora [Wed, 22 Jun 2016 20:47:54 +0000 (13:47 -0700)]
HTTP/2: style.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
9 years agoStyle.
Roman Arutyunyan [Wed, 22 Jun 2016 08:50:02 +0000 (11:50 +0300)]
Style.

9 years agoStream: use ngx_pcalloc() in ngx_stream_proxy_bind().
Roman Arutyunyan [Wed, 22 Jun 2016 08:50:02 +0000 (11:50 +0300)]
Stream: use ngx_pcalloc() in ngx_stream_proxy_bind().

9 years agoFixed build on MSVC.
Roman Arutyunyan [Mon, 20 Jun 2016 12:11:50 +0000 (15:11 +0300)]
Fixed build on MSVC.

9 years agoStream: set SO_REUSEADDR for UDP upstream sockets.
Roman Arutyunyan [Mon, 20 Jun 2016 09:48:47 +0000 (12:48 +0300)]
Stream: set SO_REUSEADDR for UDP upstream sockets.

The option is only set if the socket is bound to a specific port to allow
several such sockets coexist at the same time.  This is required, for example,
when nginx acts as a transparent proxy and receives two datagrams from the same
client in a short time.

The feature is only implemented for Linux.

9 years agoStream: support for $remote_port in proxy_bind.
Roman Arutyunyan [Mon, 20 Jun 2016 08:50:44 +0000 (11:50 +0300)]
Stream: support for $remote_port in proxy_bind.

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.

9 years agoUpstream: support for port in proxy_bind and friends.
Roman Arutyunyan [Mon, 20 Jun 2016 08:50:43 +0000 (11:50 +0300)]
Upstream: support for port in proxy_bind and friends.

9 years agoIntroduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan [Mon, 20 Jun 2016 08:50:39 +0000 (11:50 +0300)]
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.

9 years agoSet IP_BIND_ADDRESS_NO_PORT socket option for upstream sockets.
Andrei Belov [Mon, 20 Jun 2016 07:41:17 +0000 (10:41 +0300)]
Set IP_BIND_ADDRESS_NO_PORT socket option for upstream sockets.

9 years agoSSL: ngx_ssl_ciphers() to set list of ciphers.
Tim Taubert [Wed, 15 Jun 2016 20:05:30 +0000 (21:05 +0100)]
SSL: ngx_ssl_ciphers() to set list of ciphers.

This patch moves various OpenSSL-specific function calls into the
OpenSSL module and introduces ngx_ssl_ciphers() to make nginx more
crypto-library-agnostic.

9 years agoHTTP/2: fixed the "http request count is zero" alert.
Valentin Bartenev [Thu, 16 Jun 2016 17:55:11 +0000 (20:55 +0300)]
HTTP/2: fixed the "http request count is zero" alert.

When the stream is terminated the HEADERS frame can still wait in the output
queue.  This frame can't be removed and must be sent to the client anyway,
since HTTP/2 uses stateful compression for headers.  So in order to postpone
closing and freeing memory of such stream the special close stream handler
is set to the write event.  After the HEADERS frame is sent the write event
is called and the stream will be finally closed.

Some events like receiving a RST_STREAM can trigger the read handler of such
stream in closing state and cause unexpected processing that can result in
another attempt to finalize the request.  To prevent it the read handler is
now set to ngx_http_empty_handler.

Thanks to Amazon.

9 years agoHTTP/2: avoid adding Content-Length for requests without body.
Valentin Bartenev [Thu, 16 Jun 2016 17:55:11 +0000 (20:55 +0300)]
HTTP/2: avoid adding Content-Length for requests without body.

There is no reason to add the "Content-Length: 0" header to a proxied request
without body if the header isn't presented in the original request.

Thanks to Amazon.

9 years agoHTTP/2: prevented double termination of a stream.
Valentin Bartenev [Thu, 16 Jun 2016 17:55:11 +0000 (20:55 +0300)]
HTTP/2: prevented double termination of a stream.

According to RFC 7540, an endpoint should not send more than one RST_STREAM
frame for any stream.

Also, now all the data frames will be skipped while termination.

9 years agoHTTP/2: fixed a segfault while processing unbuffered upload.
Valentin Bartenev [Thu, 16 Jun 2016 17:55:11 +0000 (20:55 +0300)]
HTTP/2: fixed a segfault while processing unbuffered upload.

The ngx_http_v2_finalize_connection() closes current stream, but that is an
invalid operation while processing unbuffered upload.  This results in access
to already freed memory, since the upstream module sets a cleanup handler that
also finalizes the request.

9 years agoAn internal SHA1 implementation.
Maxim Dounin [Thu, 9 Jun 2016 13:55:38 +0000 (16:55 +0300)]
An internal SHA1 implementation.

9 years agoFixed spelling.
Otto Kekäläinen [Wed, 8 Jun 2016 05:27:41 +0000 (08:27 +0300)]
Fixed spelling.

9 years agoFixed an error log message.
Valentin Bartenev [Tue, 7 Jun 2016 14:44:20 +0000 (17:44 +0300)]
Fixed an error log message.

9 years agoConfigure: revised GCC version processing.
Sergey Kandaurov [Tue, 7 Jun 2016 09:15:56 +0000 (12:15 +0300)]
Configure: revised GCC version processing.

Now GCC 6 and onwards will use -Wno-unused-parameter.

9 years agoVersion bump.
Sergey Kandaurov [Tue, 7 Jun 2016 09:26:34 +0000 (12:26 +0300)]
Version bump.

9 years agorelease-1.11.1 tag
Maxim Dounin [Tue, 31 May 2016 13:43:49 +0000 (16:43 +0300)]
release-1.11.1 tag

9 years agonginx-1.11.1-RELEASE release-1.11.1
Maxim Dounin [Tue, 31 May 2016 13:43:49 +0000 (16:43 +0300)]
nginx-1.11.1-RELEASE

9 years agoCore: skip special buffers on writing (ticket #981).
Maxim Dounin [Tue, 31 May 2016 02:13:30 +0000 (05:13 +0300)]
Core: skip special buffers on writing (ticket #981).

A special last buffer with cl->buf->pos set to NULL can be present in
a chain when writing request body if chunked encoding was used.  This
resulted in a NULL pointer dereference if it happened to be the only
buffer left after a do...while loop iteration in ngx_write_chain_to_file().

The problem originally appeared in nginx 1.3.9 with chunked encoding
support.  Additionally, rev. 3832b608dc8d (nginx 1.9.13) changed the
minimum number of buffers to trigger this from IOV_MAX (typically 1024)
to NGX_IOVS_PREALLOCATE (typically 64).

Fix is to skip such buffers in ngx_chain_to_iovec(), much like it is
done in other places.

9 years agoTrailing spaces removed.
Maxim Dounin [Mon, 30 May 2016 15:09:41 +0000 (18:09 +0300)]
Trailing spaces removed.

9 years agoHTTP/2: unbreak build on MSVC.
Valentin Bartenev [Tue, 24 May 2016 18:54:32 +0000 (21:54 +0300)]
HTTP/2: unbreak build on MSVC.

9 years agoVersion bump.
Valentin Bartenev [Tue, 24 May 2016 18:54:32 +0000 (21:54 +0300)]
Version bump.

9 years agorelease-1.11.0 tag
Maxim Dounin [Tue, 24 May 2016 15:54:42 +0000 (18:54 +0300)]
release-1.11.0 tag

9 years agonginx-1.11.0-RELEASE release-1.11.0
Maxim Dounin [Tue, 24 May 2016 15:54:41 +0000 (18:54 +0300)]
nginx-1.11.0-RELEASE

9 years agoUpdated OpenSSL used for win32 builds.
Maxim Dounin [Tue, 24 May 2016 14:44:01 +0000 (17:44 +0300)]
Updated OpenSSL used for win32 builds.

9 years agoFixed build on MSVC.
Maxim Dounin [Tue, 24 May 2016 14:43:58 +0000 (17:43 +0300)]
Fixed build on MSVC.

9 years agoHTTP/2: implemented preread buffer for request body (closes #959).
Valentin Bartenev [Tue, 24 May 2016 14:37:52 +0000 (17:37 +0300)]
HTTP/2: implemented preread buffer for request body (closes #959).

Previously, the stream's window was kept zero in order to prevent a client
from sending the request body before it was requested (see 887cca40ba6a for
details).  Until such initial window was acknowledged all requests with
data were rejected (see 0aa07850922f for details).

That approach revealed a number of problems:

 1. Some clients (notably MS IE/Edge, Safari, iOS applications) show an error
    or even crash if a stream is rejected;

 2. This requires at least one RTT for every request with body before the
    client receives window update and able to send data.

To overcome these problems the new directive "http2_body_preread_size" is
introduced.  It sets the initial window and configures a special per stream
preread buffer that is used to save all incoming data before the body is
requested and processed.

If the directive's value is lower than the default initial window (65535),
as previously, all streams with data will be rejected until the new window
is acknowledged.  Otherwise, no special processing is used and all requests
with data are welcome right from the connection start.

The default value is chosen to be 64k, which is bigger than the default
initial window.  Setting it to zero is fully complaint to the previous
behavior.

9 years agoRealip: detect duplicate real_ip_header directive.
Ruslan Ermilov [Mon, 23 May 2016 16:17:24 +0000 (19:17 +0300)]
Realip: detect duplicate real_ip_header directive.

9 years agoRealip: port support in X-Real-IP and X-Forwarded-For.
Dmitry Volyntsev [Mon, 23 May 2016 15:44:23 +0000 (18:44 +0300)]
Realip: port support in X-Real-IP and X-Forwarded-For.

Now, the module extracts optional port which may accompany an
IP address.  This custom extension is introduced, among other
things, in order to facilitate logging of original client ports.
Addresses with ports are expected to be in the RFC 3986 format,
that is, with IPv6 addresses in square brackets.  E.g.,
"X-Real-IP: [2001:0db8::1]:12345" sets client port ($remote_port)
to 12345.

9 years agoRealip: take client port from PROXY protocol header.
Dmitry Volyntsev [Mon, 23 May 2016 15:44:22 +0000 (18:44 +0300)]
Realip: take client port from PROXY protocol header.

Previously, when the client address was changed to the one from
the PROXY protocol header, the client port ($remote_port) was
reset to zero.  Now the client port is also changed to the one
from the PROXY protocol header.

9 years agoAdded the $realip_remote_port variable.
Dmitry Volyntsev [Mon, 23 May 2016 15:44:22 +0000 (18:44 +0300)]
Added the $realip_remote_port variable.

9 years agoAdded the $proxy_protocol_port variable.
Dmitry Volyntsev [Mon, 23 May 2016 15:44:21 +0000 (18:44 +0300)]
Added the $proxy_protocol_port variable.

9 years agoRenamed "u" to "sockaddr" in listen options types.
Maxim Dounin [Mon, 23 May 2016 13:37:28 +0000 (16:37 +0300)]
Renamed "u" to "sockaddr" in listen options types.

9 years agoIntroduced the ngx_sockaddr_t type.
Ruslan Ermilov [Mon, 23 May 2016 13:37:20 +0000 (16:37 +0300)]
Introduced the ngx_sockaddr_t type.

It's properly aligned and can hold any supported sockaddr.

9 years agoStream: fixed duplicate listen address detection.
Ruslan Ermilov [Mon, 23 May 2016 09:50:59 +0000 (12:50 +0300)]
Stream: fixed duplicate listen address detection.

The 6f8254ae61b8 change inadvertently fixed the duplicate port
detection similar to how it was fixed for mail in b2920b517490.
It also revealed another issue: the socket type (tcp vs. udp)
wasn't taken into account.

9 years agoUse ngx_cmp_sockaddr() where appropriate.
Ruslan Ermilov [Fri, 20 May 2016 16:10:42 +0000 (19:10 +0300)]
Use ngx_cmp_sockaddr() where appropriate.

9 years agoHTTP/2: the "421 Misdirected Request" response (closes #848).
Valentin Bartenev [Fri, 20 May 2016 15:41:17 +0000 (18:41 +0300)]
HTTP/2: the "421 Misdirected Request" response (closes #848).

Since 4fbef397c753 nginx rejects with the 400 error any attempts of
requesting different host over the same connection, if the relevant
virtual server requires verification of a client certificate.

While requesting hosts other than negotiated isn't something legal
in HTTP/1.x, the HTTP/2 specification explicitly permits such requests
for connection reuse and has introduced a special response code 421.

According to RFC 7540 Section 9.1.2 this code can be sent by a server
that is not configured to produce responses for the combination of
scheme and authority that are included in the request URI.  And the
client may retry the request over a different connection.

Now this code is used for requests that aren't authorized in current
connection.  After receiving the 421 response a client will be able
to open a new connection, provide the required certificate and retry
the request.

Unfortunately, not all clients currently are able to handle it well.
Notably Chrome just shows an error, while at least the latest version
of Firefox retries the request over a new connection.

9 years agoBelatedly changed the ngx_create_listening() prototype.
Ruslan Ermilov [Fri, 20 May 2016 14:02:04 +0000 (17:02 +0300)]
Belatedly changed the ngx_create_listening() prototype.

The function is called only with "struct sockaddr *" since 0.7.58.

9 years agoSSL: removed default DH parameters.
Maxim Dounin [Thu, 19 May 2016 11:46:32 +0000 (14:46 +0300)]
SSL: removed default DH parameters.

Using the same DH parameters on multiple servers is believed to be subject
to precomputation attacks, see http://weakdh.org/.  Additionally, 1024 bits
are not enough in the modern world as well.  Let users provide their own
DH parameters with the ssl_dhparam directive if they want to use EDH ciphers.

Note that SSL_CTX_set_dh_auto() as provided by OpenSSL 1.1.0 uses fixed
DH parameters from RFC 5114 and RFC 3526, and therefore subject to the same
precomputation attacks.  We avoid using it as well.

This change also fixes compilation with OpenSSL 1.1.0-pre5 (aka Beta 2),
as OpenSSL developers changed their policy after releasing Beta 1 and
broke API once again by making the DH struct opaque (see ticket #860).

9 years agoSSL: support for multiple curves (ticket #885).
Maxim Dounin [Thu, 19 May 2016 11:46:32 +0000 (14:46 +0300)]
SSL: support for multiple curves (ticket #885).

OpenSSL 1.0.2+ allows configuring a curve list instead of a single curve
previously supported.  This allows use of different curves depending on
what client supports (as available via the elliptic_curves extension),
and also allows use of different curves in an ECDHE key exchange and
in the ECDSA certificate.

The special value "auto" was introduced (now the default for ssl_ecdh_curve),
which means "use an internal list of curves as available in the OpenSSL
library used".  For versions prior to OpenSSL 1.0.2 it maps to "prime256v1"
as previously used.  The default in 1.0.2b+ prefers prime256v1 as well
(and X25519 in OpenSSL 1.1.0+).

As client vs. server preference of curves is controlled by the
same option as used for ciphers (SSL_OP_CIPHER_SERVER_PREFERENCE),
the ssl_prefer_server_ciphers directive now controls both.

9 years agoSSL: style.
Maxim Dounin [Thu, 19 May 2016 11:46:32 +0000 (14:46 +0300)]
SSL: style.

9 years agoSSL: error messages style.
Maxim Dounin [Thu, 19 May 2016 11:46:32 +0000 (14:46 +0300)]
SSL: error messages style.

9 years agoSSL: support for multiple certificates (ticket #814).
Maxim Dounin [Thu, 19 May 2016 11:46:32 +0000 (14:46 +0300)]
SSL: support for multiple certificates (ticket #814).

9 years agoSSL: support for per-certificate chains.
Maxim Dounin [Thu, 19 May 2016 11:46:32 +0000 (14:46 +0300)]
SSL: support for per-certificate chains.

The SSL_CTX_add0_chain_cert() function as introduced in OpenSSL 1.0.2 now
used instead of SSL_CTX_add_extra_chain_cert().

SSL_CTX_add_extra_chain_cert() adds extra certs for all certificates
in the context, while SSL_CTX_add0_chain_cert() only to a particular
certificate.  There is no difference unless multiple certificates are used,
though it is important when using multiple certificates.

Additionally, SSL_CTX_select_current_cert() is now called before using
a chain to make sure correct chain will be returned.

9 years agoSSL: made it possible to iterate though all certificates.
Maxim Dounin [Thu, 19 May 2016 11:46:32 +0000 (14:46 +0300)]
SSL: made it possible to iterate though all certificates.

A pointer to a previously configured certificate now stored in a certificate.
This makes it possible to iterate though all certificates configured in
the SSL context.  This is now used to configure OCSP stapling for all
certificates, and in ngx_ssl_session_id_context().

As SSL_CTX_use_certificate() frees previously loaded certificate of the same
type, and we have no way to find out if it's the case, X509_free() calls
are now posponed till ngx_ssl_cleanup_ctx().

Note that in OpenSSL 1.0.2+ this can be done without storing things in exdata
using the SSL_CTX_set_current_cert() and SSL_CTX_get0_certificate() functions.
These are not yet available in all supported versions though, so it's easier
to continue to use exdata for now.

9 years agoOCSP stapling: additional function to configure stapling on a cert.
Maxim Dounin [Thu, 19 May 2016 11:46:32 +0000 (14:46 +0300)]
OCSP stapling: additional function to configure stapling on a cert.

9 years agoOCSP stapling: staple now extracted via SSL_get_certificate().
Maxim Dounin [Thu, 19 May 2016 11:46:32 +0000 (14:46 +0300)]
OCSP stapling: staple now extracted via SSL_get_certificate().

This makes it possible to properly return OCSP staple with multiple
certificates configured.

Note that it only works properly in OpenSSL 1.0.1d+, 1.0.0k, 0.9.8y+.
In older versions SSL_get_certificate() fails to return correct certificate
when the certificate status callback is called.

9 years agoOCSP stapling: staple now stored in certificate, not SSL context.
Maxim Dounin [Thu, 19 May 2016 11:46:32 +0000 (14:46 +0300)]
OCSP stapling: staple now stored in certificate, not SSL context.

9 years agoOCSP stapling: staple provided in arguments.
Maxim Dounin [Thu, 19 May 2016 11:46:32 +0000 (14:46 +0300)]
OCSP stapling: staple provided in arguments.

9 years agoAdded overflow checks for version numbers (ticket #762).
Maxim Dounin [Wed, 18 May 2016 13:21:32 +0000 (16:21 +0300)]
Added overflow checks for version numbers (ticket #762).

Both minor and major versions are now limited to 999 maximum.  In case of
r->http_minor, this limit is already implied by the code.  Major version,
r->http_major, in theory can be up to 65535 with current code, but such
values are very unlikely to become real (and, additionally, such values
are not allowed by RFC 7230), so the same test was used for r->http_major.

9 years agoEvents: close descriptors on errors in ngx_epoll_test_rdhup().
Maxim Dounin [Wed, 18 May 2016 12:57:30 +0000 (15:57 +0300)]
Events: close descriptors on errors in ngx_epoll_test_rdhup().