aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2022-11-05 23:30:53 +0100
committerToni Uhlig <matzeton@googlemail.com>2022-11-06 12:58:55 +0100
commit7515c8aeec3f6e60aa7e97e6903f6306ca7af34e (patch)
tree2583c254db17121facfd4b6b43cfe44abc064c55
parent25f4ef74acb73340bd7cba7a7d45ab7191232283 (diff)
Experimental systemd support.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r--.github/workflows/build.yml11
-rw-r--r--.gitlab-ci.yml8
-rw-r--r--CMakeLists.txt6
-rw-r--r--config.h2
-rw-r--r--nDPId.c2
-rw-r--r--nDPIsrvd.c15
-rw-r--r--packages/systemd/ndpid@.service12
-rw-r--r--packages/systemd/ndpisrvd.service11
8 files changed, 56 insertions, 11 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index af65f4c9f..65f26b1ea 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -57,7 +57,7 @@ jobs:
- name: Configure nDPId
run: |
mkdir build && cd build
- cmake .. -DENABLE_COVERAGE=ON -DBUILD_EXAMPLES=ON -DBUILD_NDPI=ON -DENABLE_SANITIZER=ON ${{ matrix.ndpid_zlib }} ${{ matrix.ndpid_gcrypt }}
+ cmake .. -DENABLE_SYSTEMD=ON -DENABLE_COVERAGE=ON -DBUILD_EXAMPLES=ON -DBUILD_NDPI=ON -DENABLE_SANITIZER=ON ${{ matrix.ndpid_zlib }} ${{ matrix.ndpid_gcrypt }}
- name: Build nDPId
run: |
make -C build all VERBOSE=1
@@ -81,7 +81,14 @@ jobs:
make -C ./build dist
- name: CPack DEB
run: |
- cd ./build && cpack -G DEB && cd ..
+ cd ./build && cpack -G DEB && sudo dpkg -i nDPId-*.deb && cd ..
+ - name: systemd test
+ run: |
+ sudo systemctl daemon-reload
+ sudo systemctl enable ndpid@lo
+ sudo systemctl start ndpid@lo
+ sudo systemctl status ndpisrvd.service ndpid@lo.service
+ sudo systemctl stop ndpid@lo
- name: Build against libnDPI-${{ matrix.ndpi_min_version }}
run: |
mkdir build-local-ndpi && cd build-local-ndpi
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index d763fbba1..054bd441f 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -23,12 +23,18 @@ build_and_test:
# static linked build
- mkdir build-cmake-submodule
- cd build-cmake-submodule
- - env CMAKE_C_FLAGS='-Werror' cmake .. -DENABLE_COVERAGE=ON -DBUILD_EXAMPLES=ON -DBUILD_NDPI=ON -DENABLE_SANITIZER=ON -DENABLE_ZLIB=ON
+ - env CMAKE_C_FLAGS='-Werror' cmake .. -DENABLE_SYSTEMD=ON -DENABLE_COVERAGE=ON -DBUILD_EXAMPLES=ON -DBUILD_NDPI=ON -DENABLE_SANITIZER=ON -DENABLE_ZLIB=ON
- make libnDPI
- tree libnDPI
- make install VERBOSE=1 DESTDIR="$(realpath ../_install)"
- cpack -G DEB
+ - sudo dpkg -i nDPId-*.deb
- cd ..
+ - test -x /bin/systemctl && sudo systemctl daemon-reload
+ - test -x /bin/systemctl && sudo systemctl enable ndpid@lo
+ - test -x /bin/systemctl && sudo systemctl start ndpid@lo
+ - test -x /bin/systemctl && sudo systemctl status ndpisrvd.service ndpid@lo.service
+ - test -x /bin/systemctl && sudo systemctl stop ndpid@lo
- ./test/run_tests.sh ./libnDPI ./build-cmake-submodule/nDPId-test
# generate coverage report
- make -C ./build-cmake-submodule coverage
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 69301cce6..172b0ffb7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -45,6 +45,7 @@ option(ENABLE_SANITIZER "Enable ASAN/LSAN/UBSAN." OFF)
option(ENABLE_SANITIZER_THREAD "Enable TSAN (does not work together with ASAN)." OFF)
option(ENABLE_MEMORY_PROFILING "Enable dynamic memory tracking." OFF)
option(ENABLE_ZLIB "Enable zlib support for nDPId (experimental)." OFF)
+option(ENABLE_SYSTEMD "Install systemd components." OFF)
option(BUILD_EXAMPLES "Build C examples." ON)
option(BUILD_NDPI "Clone and build nDPI from github." OFF)
if(BUILD_NDPI)
@@ -324,6 +325,11 @@ if(BUILD_EXAMPLES)
install(DIRECTORY examples/c-collectd/www DESTINATION share/nDPId/nDPIsrvd-collectd)
endif()
+if(ENABLE_SYSTEMD)
+ install(FILES packages/systemd/ndpisrvd.service DESTINATION lib/systemd/system)
+ install(FILES packages/systemd/ndpid@.service DESTINATION lib/systemd/system)
+endif()
+
install(TARGETS nDPId DESTINATION sbin)
install(TARGETS nDPIsrvd nDPId-test DESTINATION bin)
install(FILES dependencies/nDPIsrvd.py examples/py-flow-dashboard/plotly_dash.py
diff --git a/config.h b/config.h
index 3bcab1454..afc8d1d20 100644
--- a/config.h
+++ b/config.h
@@ -45,7 +45,7 @@
/* nDPIsrvd default config options */
#define nDPIsrvd_PIDFILE "/tmp/ndpisrvd.pid"
-#define nDPIsrvd_MAX_REMOTE_DESCRIPTORS 32
+#define nDPIsrvd_MAX_REMOTE_DESCRIPTORS 128
#define nDPIsrvd_MAX_WRITE_BUFFERS 1024
#endif
diff --git a/nDPId.c b/nDPId.c
index 79fbb1bc0..2703a10dd 100644
--- a/nDPId.c
+++ b/nDPId.c
@@ -5109,7 +5109,7 @@ static int validate_options(void)
else
{
nDPId_options.instance_alias = strdup(hname);
- logger_early(0, "No instance alias given, using your hostname '%s'", nDPId_options.instance_alias);
+ logger_early(1, "No instance alias given, using your hostname '%s'", nDPId_options.instance_alias);
if (nDPId_options.instance_alias == NULL)
{
retval = 1;
diff --git a/nDPIsrvd.c b/nDPIsrvd.c
index 891080f23..81e0d7c44 100644
--- a/nDPIsrvd.c
+++ b/nDPIsrvd.c
@@ -95,7 +95,8 @@ static struct
int bufferbloat_fallback_to_blocking;
} nDPIsrvd_options = {.max_remote_descriptors = nDPIsrvd_MAX_REMOTE_DESCRIPTORS,
.max_write_buffers = nDPIsrvd_MAX_WRITE_BUFFERS,
- .bufferbloat_fallback_to_blocking = 1};
+ .bufferbloat_fallback_to_blocking = 1,
+ .user = "nobody"};
static void logger_nDPIsrvd(struct remote_desc const * const remote,
char const * const prefix,
@@ -1599,11 +1600,13 @@ int main(int argc, char ** argv)
}
errno = 0;
- if (nDPIsrvd_options.user != NULL && change_user_group(nDPIsrvd_options.user,
- nDPIsrvd_options.group,
- nDPIsrvd_options.pidfile,
- nDPIsrvd_options.collector_un_sockpath,
- nDPIsrvd_options.distributor_un_sockpath) != 0)
+ if (nDPIsrvd_options.user != NULL &&
+ change_user_group(nDPIsrvd_options.user,
+ nDPIsrvd_options.group,
+ nDPIsrvd_options.pidfile,
+ nDPIsrvd_options.collector_un_sockpath,
+ nDPIsrvd_options.distributor_un_sockpath) != 0 &&
+ errno != EPERM)
{
if (errno != 0)
{
diff --git a/packages/systemd/ndpid@.service b/packages/systemd/ndpid@.service
new file mode 100644
index 000000000..26cea6cb1
--- /dev/null
+++ b/packages/systemd/ndpid@.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=nDPId Service on interface %i
+After=ndpisrvd.service
+Requires=ndpisrvd.service
+
+[Service]
+Type=simple
+ExecStart=/usr/sbin/nDPId -i %i -l -A -z -c /var/run/ndpisrvd-collector
+Restart=on-failure
+
+[Install]
+WantedBy=multi-user.target
diff --git a/packages/systemd/ndpisrvd.service b/packages/systemd/ndpisrvd.service
new file mode 100644
index 000000000..9218f6599
--- /dev/null
+++ b/packages/systemd/ndpisrvd.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=nDPIsrvd Service
+After=network.target
+
+[Service]
+Type=simple
+ExecStart=/usr/bin/nDPIsrvd -l -c /var/run/ndpisrvd-collector
+Restart=on-failure
+
+[Install]
+WantedBy=multi-user.target