Commit graph

1962 commits

Author SHA1 Message Date
Evgeny Shirykalov
1725db9059 JSON: report escaped strings as separate parser events
Some checks failed
buildbot / buildbot (push) Has been cancelled
The parser now emits NGX_JSON_KEY_ESCAPED and
NGX_JSON_VALUE_STRING_ESCAPED for strings holding escape sequences, so
consumers no longer rescan tokens.
2026-10-16 09:42:01 -07:00
Evgeny Shirykalov
57d05f374c JSON: modified ngx_json_unescape_string() to unescape into a new buffer 2026-10-16 09:42:01 -07:00
Vadim Zhestikov
e72a6a0bc3 SSL: ignored EIO after shutdown with kernel TLS
After SSL shutdown, lingering close reads the socket with recv().  With
kernel TLS receive offload, which OpenSSL enables for TLS 1.3 since
3.2.0, recv() fails with EIO on a record other than application data,
such as the "close notify" alert from the client, and this was logged
at the "alert" level.

Now ngx_ssl_shutdown() marks connections with kernel TLS receive
offload, and EIO on such connections is ignored, so the read ends as
at EOF.

Reported by soukichi on GitHub.

Closes: https://github.com/nginx/nginx/issues/651
2026-10-15 08:13:24 -07:00
Vadim Zhestikov
b390773fad Win32: removed the iocp event module
The I/O completion ports event method has never been completed: the
module is compiled into Windows builds, but is not documented or
supported.

Prodded by Marek Ludha.
2026-10-15 08:06:49 -07:00
Sergey Kandaurov
cae9999860 Version bump
Some checks are pending
buildbot / buildbot (push) Waiting to run
2026-10-15 15:51:50 +04:00
Sai Krishna Kumar Reddy YADAMAKANTI
63af971a1e QUIC: support BPF reload and binary upgrade
Some checks are pending
buildbot / buildbot (push) Waiting to run
The SO_COOKIE dependency is removed.  QUIC BPF dispatching now uses
separate sockets for new and established connections: listener sockets
handle new connections, while per-worker sockets handle established
ones.  Server connection IDs encode a random worker key, which BPF
uses to route established packets directly to the correct worker
socket.  New connections are routed through listen keys using a
dual slot scheme that enables both reload and binary upgrade.

On reload, new workers register new sockets and keys while old workers
continue receiving established connections through their encoded keys.
On binary upgrade, the new master uses the opposite slot, and exiting
masters clear their entries so traffic shifts to the surviving
instance.

Co-authored-by: Roman Arutyunyan <arut@nginx.com>
2026-09-29 21:46:41 +04:00
Sourav Bhowmik
d115763f8e Rejected zero size in buffer-size directives
When set to zero, this resulted in a buffer with no room to read into.
As there is no meaningful interpretation of a zero-sized buffer, such
configuration is explicitly rejected.

Reported by kh-lee
2026-09-25 22:27:38 +04:00
Sergey Kandaurov
ef0aa967dc Version bump
Some checks failed
buildbot / buildbot (push) Has been cancelled
2026-09-16 16:13:02 +04:00
Sergey Kandaurov
ea5b634fdc Control API: fixed socket inheritance on binary upgrade
The environment may be replaced while parsing configuration, as it
happens with the perl module, which calls ngx_set_environment() when
creating an interpreter.  As a result, the control socket was not
inherited on binary upgrade.

The variable is now read before ngx_init_cycle(), similarly to
inherited listening sockets.
2026-09-11 16:27:35 +04:00
Sergey Kandaurov
69dcf98c1c Version bump 2026-09-07 20:08:48 +04:00
Ava Hahn
1c1c17c104 Control API: in memory config dump.
The /control/config endpoint returns the currently parsed and running
configuration on GET request.

Example:

$ curl 127.0.0.1:1234/1/control/config | jq
[
  {
    "name": "/path/to/nginx.conf",
    "content": "..."
  },
  {
    "name": "/path/to/included.conf",
    "content": "..."
  }
]

Co-authored-by: Pavel Pautov <p.pautov@f5.com>
2026-09-01 10:34:56 -07:00
Ava Hahn
4bc459a15c Control API.
A new nginx option -l specifies control socket listen address.
The socket is providing an HTTP/1 REST API for retrieving information
about running nginx instance.

Example:

$ nginx -l 127.0.0.1:1234

$ curl 127.0.0.1:1234/1/control/processes | jq
[
  {
    "pid": 41536,
    "name": "worker process",
    "exiting": false
  }
]

Co-authored-by: Roman Arutyunyan <arut@nginx.com>
Co-authored-by: Pavel Pautov <p.pautov@f5.com>
Co-authored-by: Dmitry Plotnikov <d.plotnikov@f5.com>
Co-authored-by: Sergey Kandaurov <pluknet@nginx.com>
Co-authored-by: Ivan Ovchinnikov <i.ovchinnikov@f5.com>
2026-09-01 10:34:56 -07:00
Dmitry Plotnikov
032e181dad JSON: fixed overflow detection in length calculation
Some checks are pending
buildbot / buildbot (push) Waiting to run
2026-08-31 14:22:50 -07:00
Roman Arutyunyan
76364bdd29 Core: delete accept timer on worker shutdown
Previously, when the worker file descriptor table was full, a listen
connection might be disabled and a timeout might be set for re-enabling
it.  If during this period the worker received the NGX_CMD_QUIT signal,
the accept connection would be recycled, but the timer would remain set.
On timer expiration, an attempt to accept a new connection would result
in "accept4() failed (9: Bad file descriptor)" alert because c->fd was
reset to -1.

Fix is to delete accept timer when closing listen connections.
2026-08-25 21:33:21 +04:00
Roman Semenov
55db1978e2 Core: allowed top-level scalars in the JSON parser
RFC 8259 permits any JSON value as a complete document, not just
objects and arrays.  The start state now accepts strings, numbers,
and the true/false/null literals as well.  A bare top-level number,
having no closing delimiter, is emitted when input ends.
2026-08-24 11:08:31 -07:00
Roman Semenov
746609903e Core: added json parser
An event-driven JSON parser implementing the grammar of RFC 8259.
The full grammar is recognized: objects, arrays, strings with \uXXXX
escapes (including UTF-16 surrogate pairs), numbers, and the
true/false/null literals.  Tokens are reported to a caller-supplied
handler, with nesting bounded by a configurable maximum depth.

Based on previous work by Maxim Dounin.

Co-authored-by: Dmitry Volyntsev <d.volyntsev@f5.com>
2026-08-24 11:08:31 -07:00
Roman Semenov
bc1cb5686b Core: added JSON unescape functionality
Decodes JSON string escape sequences in place as defined by
RFC 8259, Section 7: the two-character escapes and \uXXXX,
with non-BMP code points encoded as UTF-16 surrogate pairs
and emitted as UTF-8.
2026-08-24 11:08:31 -07:00
Vadim Zhestikov
e3cffe3044 Version bump 2026-08-19 19:24:25 -07:00
Sergey Kandaurov
cfb1d17326 Core: PROXY protocol v2 write support
Add ngx_proxy_protocol_v2_write() that writes the fixed 16-byte
PPv2 header and address block, and appends a list of TLVs.

An address block is written using IPv4/IPv6 mixed-family promotion:
the highest family present on either side (IPv6 > IPv4) is used for
the header, and the other address is promoted into it.  Both v4-mapped
addresses are demoted to IPv4.

When PROXY protocol v2 is configured and the downstream connection
is SSL, standard PROXY protocol v2 TLVs are populated:

    PP2_TYPE_ALPN              from SSL_get0_alpn_selected()
    PP2_TYPE_AUTHORITY         from SSL_get_servername()
    PP2_SUBTYPE_SSL_VERSION    from SSL_get_version()
    PP2_SUBTYPE_SSL_CIPHER     from SSL_get_cipher_name()
    PP2_SUBTYPE_SSL_CN         from client cert subject CN
    PP2_SUBTYPE_SSL_SIG_ALG    from server certificate
    PP2_SUBTYPE_SSL_KEY_ALG    from server certificate

The CRC32c TLV is written last and covers the entire header in place.

Co-authored-by: Vadim Zhestikov <v.zhestikov@f5.com>
2026-08-11 23:39:53 +04:00
Sergey Kandaurov
49181eb14a Core: PROXY protocol v2 macros 2026-08-11 23:39:53 +04:00
Vadim Zhestikov
05549db082 Core: CRC32c (Castagnoli93) implementation
This change implements the Castagnoli polynomial code 0x11EDC6F41,
as described in RFC4960, Appendix B.  It will be used to calculate
PROXY protocol v2 CRC32c checksums.
2026-08-11 23:39:53 +04:00
Henry Yuan
836704c6e8 Core: added data model and JSON serialization libraries.
Co-authored-by: Valentin Bartenev <vbart@nginx.com>
Co-authored-by: Ruslan Ermilov <ru@nginx.com>
Co-authored-by: Vladimir Homutov <vl@nginx.com>
Co-authored-by: Evgeny Shirykalov <e.shirykalov@f5.com>
Co-authored-by: Dmitry Plotnikov <d.plotnikov@f5.com>
2026-08-10 11:23:36 -07:00
Sergey Kandaurov
33eedb5ae6 Format specifier fixes in error logging
Some checks failed
buildbot / buildbot (push) Has been cancelled
Co-authored-by: Nishat Shabbir <nishat@bugqore.com>
2026-07-25 00:50:53 +04:00
Vadim Zhestikov
dbfd4b52ab Version bump 2026-07-16 12:27:25 -07:00
Roman Arutyunyan
18ccebb1a8 Fix setting the IPV6_DONTFRAG socket option
Some checks failed
buildbot / buildbot (push) Has been cancelled
The fix includes the socket option level (IPPROTO_IPV6) in the feature
test and the macro (NGX_HAVE_IPV6_DONTFRAG) in the
ngx_configure_listening_sockets() function.

Reported by Eric Fortis.
2026-07-08 21:23:26 +04:00
Andrew Clayton
e01f4fe3a9 Version bump 2026-06-23 15:22:11 +01:00
Eugene Grebenschikov
6067896f03 Core: added SipHash-2-4 implementation
Added ngx_siphash() function implementing the SipHash-2-4
algorithm for fast pseudorandom number generation with good
statistical properties.

Co-authored-by: Sergey Kandaurov <pluknet@nginx.com>
2026-06-02 15:30:30 -07:00
Eugene Grebenschikov
25273ede01 Version bump 2026-06-02 15:30:30 -07:00
Andrew Clayton
80ee028b80 Version bump 2026-05-13 20:19:15 +01:00
Andrew Clayton
b0a4d0fb82 Avoid undefined behaviour in ngx_pstrdup()
In the third call to ngx_pstrdup() for setting cycle->conf_param.data in
ngx_init_cycle() we would pass in a nulled ngx_str_t in the case there
was no -g command line option passed to nginx.

This would result in a

  memcpy(dst, NULL, 0)

which up to and including C23 is Undefined Behaviour.

Currently Clang and GCC (in this particular case) just treat this as a
no-op, so things just happen to work.

However some undefined behaviour sanitizers will throw an error when
this is hit, e.g. Clang and the zig compiler and it's probably best not
to rely on this behaviour.

It's worth noting that the next C standard will make this (and other
NULL related operations) defined behaviour.

Link: <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>
Closes: https://github.com/nginx/nginx/issues/1079
2026-04-20 19:56:40 +01:00
Andrew Clayton
9772267278 Version bump 2026-04-13 14:20:23 +01:00
Eugene Grebenschikov
2ff1a969f3 Removed CLOCK_MONOTONIC_FAST support.
CLOCK_MONOTONIC_FAST, like CLOCK_MONOTONIC_COARSE, has low accuracy. It
shows noticeable timing variation for short intervals, which is visible
in metrics like $upstream_response_time for fast upstream responses.
This change complements the work started in commit f29d7ade5.
In addition to the reasons described in f29d7ade5, the performance of
CLOCK_MONOTONIC is good enough on modern hardware when using a TSC
timecounter. This is especially true when it is accessed through a
shared page, as implemented in FreeBSD 10.0 (see git commits
869fd80fd449 and aea810386d8e for details).

Co-authored-by: Sergey Kandaurov <pluknet@nginx.com>
2026-04-03 11:57:21 -07:00
Sergey Kandaurov
390767e6ec Version bump. 2026-03-31 12:32:19 +04:00
Dmitry Plotnikov
c6c77e8875 Added COMPAT section to ngx_log_t. 2026-03-23 09:38:11 -07:00
Sergey Kandaurov
920dc099c1 The "multipath" parameter of the "listen" directive.
When configured, it enables Multipath TCP support on a listen socket.
As of now it works on Linux starting with Linux 5.6 and glibc 2.32,
where it is enabled with an IPPROTO_MPTCP socket(2) protocol.

To avoid EADDRINUSE errors in bind() and listen() when transitioning
between sockets with different protocols, SO_REUSEPORT is set on both
sockets.  See f7f1607bf for potential implications.

Based on previous work by Maxime Dourov and Anthony Doeraene.
2026-03-19 01:13:51 +04:00
Roman Arutyunyan
60d0329a20 Version bump. 2026-03-11 19:32:17 +04:00
Roman Arutyunyan
edb4d2ffa7 Resolver: fixed off-by-one read in ngx_resolver_copy().
It is believed to be harmless, see a similar change 077a890a76.

Reported-by: geeknik <geeknik@protonmail.ch>
2026-02-23 22:12:32 +04:00
Roman Arutyunyan
d662a5cc46 Version bump. 2026-02-11 18:56:27 +04:00
Sergey Kandaurov
3afd85e4b5 Output chain: clear the last_buf flag unless inherited.
For instance, the last_buf flag is used in the http proxy module when
creating HTTP/2 requests to indicate the output is closed.  The flag
is inherited in ngx_output_chain() to a destination buffer when reading
the buffered request body.  Then it is used in the proxy output filter
to mark the last HTTP/2 DATA frame with END_STREAM.

The problem happens when reusing the destination buffer, such as to
re-read the buffered request body on next upstream, because this buffer
may contain a dirty last_buf value, which breaks sending HTTP/2 request
body in multiple output filter calls.

The flush and last_in_chain flags are cleared for consistency.
2026-01-29 14:52:41 +04:00
Aleksei Bavshin
5c2947d844 Version bump. 2025-12-16 14:22:33 -07:00
Sergey Kandaurov
a386df6b23 Version bump. 2025-11-06 15:34:58 +04:00
Sergey Kandaurov
3494f25c3e Version bump. 2025-10-08 19:56:41 +04:00
Sergey Kandaurov
6f81314a07 Mail: xtext encoding (RFC 3461) in XCLIENT LOGIN.
The XCLIENT command uses xtext encoding for attribute values,
as specified in https://www.postfix.org/XCLIENT_README.html.

Reported by Igor Morgenstern of Aisle Research.
2025-09-26 17:04:20 +04:00
Sergey Kandaurov
36d40e5610 Version bump. 2025-08-13 21:21:40 +04:00
Sergey Kandaurov
279fe352cb Version bump. 2025-06-25 14:19:13 +04:00
Andrew Clayton
4eaecc5e8a Use NULL instead of 0 for null pointer constant.
There were a few random places where 0 was being used as a null pointer
constant.

We have a NULL macro for this very purpose, use it.

There is also some interest in actually deprecating the use of 0 as a
null pointer constant in C.

This was found with -Wzero-as-null-pointer-constant which was enabled
for C in GCC 15 (not enabled with Wall or Wextra... yet).

Link: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117059>
2025-06-21 10:36:45 +04:00
Sergey Kandaurov
5b8a5c08ce Core: added support for TCP keepalive parameters on macOS.
The support first appeared in OS X Mavericks 10.9 and documented since
OS X Yosemite 10.10.

It has a subtle implementation difference from other operating systems
in that the TCP_KEEPALIVE socket option (used in place of TCP_KEEPIDLE)
isn't inherited from a listening socket to an accepted socket.

An apparent reason for this behaviour is that it might be preserved for
the sake of backward compatibility.  The TCP_KEEPALIVE socket option is
not inherited since appearance in OS X Panther 10.3, which long predates
two other TCP_KEEPINTVL and TCP_KEEPCNT socket options.

Thanks to Andy Pan for initial work.
2025-05-27 01:59:02 +04:00
Aleksei Bavshin
b9d0ba6677 Core: improved NGX_ALIGNMENT detection on some x86_64 platforms.
Previously, the default pool alignment used sizeof(unsigned long), with
the expectation that this would match to a platform word size.  Certain
64-bit platforms prove this assumption wrong by keeping the 32-bit long
type, which is fully compliant with the C standard.

This introduces a possibility of suboptimal misaligned access to the
data allocated with ngx_palloc() on the affected platforms, which is
addressed here by changing the default NGX_ALIGNMENT to a pointer size.

As we override the detection in auto/os/conf for all the machine types
except x86, and Unix-like 64-bit systems prefer the 64-bit long, the
impact of the change should be limited to Win64 x64.
2025-04-18 12:57:26 -07:00
Roman Arutyunyan
0626e60a75 Version bump. 2025-04-16 18:55:19 +04:00
Sergey Kandaurov
f274b3f72f Version bump. 2025-02-18 15:49:18 +04:00