Commit Graph

70 Commits

Author SHA1 Message Date
Zhidao HONG
a3c3a29493 NJS: supported loadable modules. 2023-05-08 16:00:25 +08:00
Zhidao HONG
14d6d97bac HTTP: added basic URI rewrite.
This commit introduced the basic URI rewrite. It allows users to change request URI. Note the "rewrite" option ignores the contained query if any and the query from the request is preserverd.
An example:
"routes": [
    {
        "match": {
            "uri": "/v1/test"
        },
        "action": {
            "return": 200
        }
    },
    {
        "action": {
            "rewrite": "/v1$uri",
            "pass": "routes"
        }
    }
]

Reviewed-by: Alejandro Colomar <alx@nginx.com>
2023-04-20 23:20:41 +08:00
Andrew Clayton
b9177d36e7 Remove a bunch of dead code.
This removes a bunch of unused files that would have been touched by
subsequent commits that switch to using nxt_bool_t (AKA unit6_t) in
structures.

In auto/sources we have

  NXT_LIB_SRC0=" \
      src/nxt_buf_filter.c \
      src/nxt_job_file.c \
      src/nxt_stream_module.c \
      src/nxt_stream_source.c \
      src/nxt_upstream_source.c \
      src/nxt_http_source.c \
      src/nxt_fastcgi_source.c \
      src/nxt_fastcgi_record_parse.c \
  \
      src/nxt_mem_pool_cleanup.h \
      src/nxt_mem_pool_cleanup.c \
  "

None of these seem to actually be used anywhere (other than within
themselves). That variable is _not_ referenced anywhere else.

Also remove the unused related header files: src/nxt_buf_filter.h,
src/nxt_fastcgi_source.h, src/nxt_http_source.h, src/nxt_job_file.h,
src/nxt_stream_source.h and src/nxt_upstream_source.h

Also, these files do not seem to be used, no mention under auto/ or build/

  src/nxt_file_cache.c
  src/nxt_cache.c
  src/nxt_job_file_cache.c

src/nxt_cache.h is #included in src/nxt_main.h, but AFAICT is not
actually used.

With all the above removed

  $ ./configure --openssl --debug --tests && make -j && make -j tests &&
  make libnxt

all builds.

Buildbot passes.

NOTE: You may need to do a 'make clean' before the next build attempt.

Reviewed-by: Alejandro Colomar <alx@nginx.com>
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-04-24 19:39:09 +01:00
Andrew Clayton
3ecdd2c69c Isolation: Rename NXT_HAVE_CLONE -> NXT_HAVE_LINUX_NS.
Due to the need to replace our use of clone/__NR_clone on Linux with
fork(2)/unshare(2) for enabling Linux namespaces(7) to keep the
pthreads(7) API working.  Let's rename NXT_HAVE_CLONE to
NXT_HAVE_LINUX_NS, i.e name it after the feature, not how it's
implemented, then in future if we change how we do namespaces again we
don't have to rename this.

Reviewed-by: Alejandro Colomar <alx@nginx.com>
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2023-02-17 21:24:18 +00:00
Andrew Clayton
c9e433a13d Isolation: wired up cgroup to build system.
This commit enables the building of the cgroup code. This is only built
when the cgroupv2 filesystem is found.

If cgroupv2 support is found then

  cgroupv2: .................. YES

will be printed by ./configure

Reviewed-by: Alejandro Colomar <alx@nginx.com>
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2022-12-10 14:00:20 +00:00
Zhidao HONG
e3bbf5b3b5 NJS: added http request prototype. 2022-11-22 10:13:18 +08:00
Zhidao HONG
4d6d146e92 Basic njs support. 2022-11-20 23:16:51 +08:00
Zhidao HONG
4735931ace Var: separating nxt_tstr_t from nxt_var_t.
It's for the introduction of njs support.
For each option that supports native variable and JS template literals introduced next,
it's unified as template string.

No functional changes.
2022-11-20 23:15:01 +08:00
Andrew Clayton
f8b892e1fa Fixed the build on MacOS (and others).
@alejandro-colomar reported that the build was broken on MacOS

cc  -o build/unitd -pipe -fPIC -fvisibility=hidden -O -W -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -fstrict-aliasing -Wstrict-overflow=5 -Wmissing-prototypes -Werror -g   \
		build/src/nxt_main.o  build/libnxt.a \
		    \
                      \
                    -L/usr/local/Cellar/pcre2/10.40/lib -lpcre2-8
Undefined symbols for architecture x86_64:
  "_nxt_fs_mkdir_parent", referenced from:
      _nxt_runtime_pid_file_create in libnxt.a(nxt_runtime.o)
      _nxt_runtime_controller_socket in libnxt.a(nxt_controller.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [build/unitd] Error 1

This was due to commit 57fc920 ("Socket: Created control socket & pid file
directories.").

This happened because this commit introduced the usage of
nxt_fs_mkdir_parent() in core code which uses nxt_fs_mkdir(), both of
these are defined in src/nxt_fs.c. It turns out however that this file
doesn't get built on MacOS (or any system that isn't Linux or that
lacks a FreeBSD compatible nmount(2) system call) due to the following

In auto/sources we have

  if [ $NXT_HAVE_ROOTFS = YES ]; then
      NXT_LIB_SRCS="$NXT_LIB_SRCS src/nxt_fs.c"
  fi

NXT_HAVE_ROOTFS is set in auto/isolation

  If [ $NXT_HAVE_MOUNT = YES -a $NXT_HAVE_UNMOUNT = YES ]; then
      NXT_HAVE_ROOTFS=YES

      cat << END >> $NXT_AUTO_CONFIG_H
  #ifndef NXT_HAVE_ISOLATION_ROOTFS
  #define NXT_HAVE_ISOLATION_ROOTFS  1
  #endif
  END

  fi

While we do have a check for a generic umount(2) which is found on
MacOS, for mount(2) we currently only check for the Linux mount(2) and
FreeBSD nmount(2) system calls. So NXT_HAVE_ROOTFS is set to NO on MacOS
and we don't build src/nxt_fs.c

This fixes the immediate build issue by taking the mount/umount OS
support out of nxt_fs.c into a new nxt_fs_mount.c file which is guarded
by the above while we now build nxt_fs.c unconditionally.

This should fix the build on any _supported_ system.

Reported-by: Alejandro Colomar <alx@nginx.com>
Fixes: 57fc920 ("Socket: Created control socket & pid file directories.")
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2022-10-14 12:25:47 +01:00
Valentin Bartenev
ce26dd729e Implemented basic statistics API. 2022-08-29 14:27:09 +08:00
Alejandro Colomar
22c5100666 Removed dead code.
nxt_sockaddr_ntop() stopped being used in commit (git) 029942f4eb.
It has been replaced mostly by nxt_sockaddr_text().

    commit 029942f4eb
    Author: Igor Sysoev <igor@sysoev.ru>
    Date:   Wed Feb 22 15:09:59 2017 +0300

        I/O operations refactoring.

nxt_job_sockaddr_parse() stopped being used in commit (git) 794248090a.

    commit 794248090a
    Author: Igor Sysoev <igor@sysoev.ru>
    Date:   Wed Mar 4 14:04:08 2020 +0300

        Legacy upstream code removed.

Also, remove functions and types used only by those two functions:

nxt_job_sockaddr_unix_parse()
nxt_job_sockaddr_inet6_parse()
nxt_job_sockaddr_inet_parse()
nxt_job_sockaddr_parse_t
nxt_job_resolve()
nxt_job_resolve_t
2022-08-11 18:43:12 +02:00
Zhidao HONG
8761501b48 Log: split access log from nxt_router.c.
No functional changes.
2022-07-14 11:14:20 +08:00
Tiago Natel de Moura
ff6a7053f5 Introduced SCM_CREDENTIALS / SCM_CREDS in the socket control msgs. 2021-11-09 15:48:44 +03:00
Valentin Bartenev
7bf6253941 Custom implementation of Base64 decoding function.
Compared to the previous implementation based on OpenSSL, the new implementation
has these advantages:

 1. Strict and reliable detection of invalid strings, including strings with
    less than 4 bytes of garbage at the end;

 2. Allows to use Base64 strings without '=' padding.
2021-10-26 15:43:44 +03:00
Axel Duch
e3af18834d Router: matching regular expressions support. 2020-11-17 15:03:30 +00:00
Tiago Natel de Moura
a8a7eeb1fc Moved isolation related code to "nxt_isolation.c". 2020-08-20 15:22:58 +01:00
Valentin Bartenev
93146616cf Basic variables support. 2020-08-13 02:46:54 +03:00
Igor Sysoev
65799c7252 Upstream chunked transfer encoding support. 2020-06-23 14:16:45 +03:00
Tiago Natel de Moura
e2b53e16c6 Added "rootfs" feature. 2020-05-28 14:57:41 +01:00
Tiago Natel de Moura
e9e5ddd5a5 Refactor of process management.
The process abstraction has changed to:

  setup(task, process)
  start(task, process_data)
  prefork(task, process, mp)

The prefork() occurs in the main process right before fork.

The file src/nxt_main_process.c is completely free of process
specific logic.

The creation of a process now supports a PROCESS_CREATED state.  The
The setup() function of each process can set its state to either
created or ready.  If created, a MSG_PROCESS_CREATED is sent to main
process, where external setup can be done (required for rootfs under
container).

The core processes (discovery, controller and router) doesn't need
external setup, then they all proceeds to their start() function
straight away.

In the case of applications, the load of the module happens at the
process setup() time and The module's init() function has changed
to be the start() of the process.

The module API has changed to:

  setup(task, process, conf)
  start(task, data)

As a direct benefit of the PROCESS_CREATED message, the clone(2) of
processes using pid namespaces now doesn't need to create a pipe
to make the child block until parent setup uid/gid mappings nor it
needs to receive the child pid.
2020-03-09 16:28:25 +00:00
Valentin Bartenev
8d727774e3 Implemented "return" action.
The "return" action can be used to immediately generate a simple HTTP response
with an arbitrary status:

  {
      "action": {
          "return": 404
      }
  }

This is especially useful for denying access to specific resources.
2020-03-27 17:22:52 +03:00
Igor Sysoev
7935ea4543 Round robin upstream added. 2020-03-06 18:28:54 +03:00
Axel Duch
8677bf8d41 Router: introducing routing on client address. 2019-12-24 13:58:10 +00:00
Tiago Natel
411daeaa53 Isolation: allowed the use of credentials with unpriv userns.
The setuid/setgid syscalls requires root capabilities but if the kernel
supports unprivileged user namespace then the child process has the full
set of capabilities in the new namespace, then we can allow setting "user"
and "group" in such cases (this is a common security use case).

Tests were added to ensure user gets meaningful error messages for
uid/gid mapping misconfigurations.
2019-12-06 16:52:50 +00:00
Tiago Natel
ed2492a66a Moved credential-related code to nxt_credential.c.
This is required to avoid include cycles, as some nxt_clone_* functions
depend on the credential structures, but nxt_process depends on clone
structures.
2019-12-06 13:28:05 +00:00
Igor Sysoev
ddde9c23cf Initial proxy support. 2019-11-14 16:39:54 +03:00
Valentin Bartenev
08a8d1510d Basic support for serving static files. 2019-09-19 02:47:09 +03:00
Tiago de Bem Natel de Moura
c554941b4f Initial applications isolation support using Linux namespaces. 2019-09-19 15:25:23 +03:00
Max Romanov
e501c74ddc Introducing websocket support in router and libunit. 2019-08-20 16:31:53 +03:00
Igor Sysoev
d4ccaae900 Initial routing implementation. 2019-02-27 16:41:11 +03:00
Valentin Bartenev
6cc4080af2 Removed unused "--upstream" command line option. 2018-10-23 18:55:16 +03:00
Valentin Bartenev
029c1a9f50 Renamed "go" application type to "external".
There's nothing specific to Go language.  This type of application object can
be used to run any external application that utilizes libunit API.
2018-10-09 17:53:31 +03:00
Valentin Bartenev
8d844bc2aa Controller: certificates storage interface. 2018-09-20 15:27:08 +03:00
Igor Sysoev
96cd68b340 Added SSL/TLS support on connection level. 2018-09-20 15:05:37 +03:00
Max Romanov
1bb22d1e92 Unit application library.
Library now used in all language modules.
Old 'nxt_app_*' code removed.

See src/test/nxt_unit_app_test.c for usage sample.
2018-08-06 17:27:33 +03:00
Igor Sysoev
7e41f9d108 Refactored thread ID functions.
nxt_thread_tid() was moved to src/nxt_thread.c
nxt_thread_get_tid() was moved to src/nxt_thread_id.h.
src/nxt_thread_id.c was removed.
2018-07-27 16:53:26 +03:00
Valentin Bartenev
07b554c2b4 Configure scripts cleanup.
Thanks to 洪志道 (Hong Zhi Dao).
2018-04-11 18:29:48 +03:00
Igor Sysoev
9a6d3c5775 HTTP keep-alive connections support. 2017-12-28 16:01:06 +03:00
Max Romanov
630ec3f1ec Using compiler capability to generate dependencies.
This closes #58 issue on GitHub.
2017-12-01 16:28:06 +03:00
Andrey Zelenkov
78a77c3e38 Tests: move existing tests to "src" folder. 2017-11-21 18:55:28 +03:00
Valentin Bartenev
096562c0b1 Improved applications versions handling. 2017-10-05 16:46:18 +03:00
Valentin Bartenev
45c1d41f34 Removed fibers from compilation.
It's not used anyway, but breaks building with musl.

This closes issue #5 on GitHub.
2017-09-22 16:42:42 +03:00
Igor Sysoev
cdc7e4479f Lib unit tests have been renamed to tests. 2017-08-30 00:31:02 +03:00
Max Romanov
92f3b85298 The process type enum exposed to go module. 2017-08-29 14:18:00 -07:00
Igor Sysoev
9d487df10d The master process has been renamed to the main process. 2017-08-29 02:59:35 +03:00
Igor Sysoev
b84aa64dcb Removed configure option --no-threads. 2017-08-24 17:43:32 +03:00
Igor Sysoev
949548da29 The new module configuration interface.
Configuration and building example:

  ./configure
  ./configure python
  ./configure php
  ./configure go
  make all

or

  ./configure
  make nginext
  ./configure python
  make python
  ./configure php
  make php
  ./configure go
  make go

Modules configuration options and building examples:

  ./configure python --module=python2 --config=python2.7-config
  make python2

  ./configure php --module=php7 --config=php7.0-config
                  --lib-path=/usr/local/php7.0
  make php7

  ./configure go --go=go1.6 --go-path=${HOME}/go1.6
  make go1.6
2017-08-17 21:47:19 +03:00
Max Romanov
f2e9afdf42 Port RPC interface introduced.
Usage:
1. Register handlers in incoming port with nxt_port_rpc_register_handler().
2. Use return value as a stream identifier for next nxt_port_socket_write().
2017-08-02 13:14:31 +03:00
Valentin Bartenev
842aa9ab46 Configuration: basic validation of schema. 2017-07-05 18:44:43 +03:00
Valentin Bartenev
53074c3b29 Configuration: reduced names of structures, functions, and macros. 2017-06-28 18:56:33 +03:00