Skip to content

Commit 42fe9f9

Browse files
committed
categories: add mmap .ndb backend for custom category lists
Introduce a compiled .ndb backend (mmap) for external custom category matching, with LEGACY / NDB_ONLY / HYBRID modes, while keeping the existing -G / Aho-Corasick list path unchanged. Adds ndpi_load_category_ndb_file() / ndpi_unload_category_ndb(), ndpiReader --category-ndb and --category-ndb-reload-interval, a polling-based hot-reload helper, offline builder ndpi_gen_categories_bin, shared hostname normalization (generator + runtime), and on-disk layout in ndpi_categories_bin.h (domains plus IPv4/IPv6 prefix entries). The generator writes the database atomically (temporary file + fsync + rename) so ndpiReader can reload a new valid file without restart.
1 parent ea3586e commit 42fe9f9

21 files changed

Lines changed: 3252 additions & 35 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
/example/ndpiReader
5656
/example/ndpiReader.exe
5757
/example/ndpiSimpleIntegration
58+
/example/ndpi_gen_categories_bin
5859
/utils/Makefile
5960
/utils/hosts2domains
6061
/utils/print_rank

Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ EXTRA_DIST = README.md README.fuzzer.md CHANGELOG.md CONTRIBUTING.md \
1919
autogen.sh wireshark windows utils packages dga \
2020
influxdb/Makefile.in influxdb/metric_anomaly.c influxdb/README.txt \
2121
rrdtool/Makefile.in rrdtool/README.txt rrdtool/rrd_anomaly.c rrdtool/rrd_similarity.c \
22-
doc/requirements.txt doc/conf.py doc/flow_risks.rst doc/protocols.rst doc/guide/nDPI_QuickStartGuide.pages \
22+
doc/requirements.txt doc/categories-ndb.md doc/conf.py doc/flow_risks.rst doc/protocols.rst doc/guide/nDPI_QuickStartGuide.pages \
2323
doc/guide/nDPI_QuickStartGuide.pdf doc/img/logo.png doc/index.rst \
2424
doc/Makefile doc/what_is_ndpi.rst \
2525
doc/FAQ.rst \

configure.ac

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,11 @@ echo "Setting API version to ${NDPI_API_VERSION}"
279279
AC_DEFINE_UNQUOTED(NDPI_GIT_RELEASE, "${GIT_RELEASE}", [GIT Release])
280280
AC_DEFINE_UNQUOTED(NDPI_GIT_DATE, "${GIT_DATE}", [Last GIT change])
281281

282-
NDPI_CFLAGS="-W -Wall -Wextra -Wno-address-of-packed-member ${NDPI_CFLAGS}"
282+
NDPI_CFLAGS="-W -Wall -Wextra ${NDPI_CFLAGS}"
283+
dnl> gcc < 5 does not support -Wno-address-of-packed-member (unknown -Wno-* is fatal with -Werror)
284+
AX_CHECK_COMPILE_FLAG([-Wno-address-of-packed-member], [
285+
NDPI_CFLAGS="${NDPI_CFLAGS} -Wno-address-of-packed-member"
286+
], [], [-Werror])
283287

284288
dnl> MacOS brew.sh
285289
HOMEBREW_DIR=/opt/homebrew
@@ -408,6 +412,8 @@ if test -d ${srcdir}/../nDPI-custom; then :
408412
AC_MSG_RESULT([Compiling with custom nDPI protocols])
409413
fi
410414

415+
dnl> example/ndpi_gen_categories_bin is linked without $(LIBS); Winsock must still be linked.
416+
NDPI_GEN_EXTRA_LIBS=
411417
case "$host" in
412418
*-*-mingw32*|*-*-msys)
413419
PCAP_INC=""
@@ -427,6 +433,7 @@ case "$host" in
427433
esac
428434
NDPI_CFLAGS="-D__USE_MINGW_ANSI_STDIO -D__STDC_FORMAT_MACROS ${NDPI_CFLAGS}"
429435
LIBS="${LIBS} -lws2_32"
436+
NDPI_GEN_EXTRA_LIBS="-lws2_32"
430437
BUILD_MINGW=1
431438
EXE_SUFFIX=".exe"
432439
AS_IF([test "${enable_npcap+set}" != set && test "${with_only_libndpi+set}" != set],,
@@ -619,6 +626,7 @@ AC_SUBST(NDPI_API_VERSION)
619626
AC_SUBST(EXTRA_TARGETS)
620627
AC_SUBST(BUILD_MINGW)
621628
AC_SUBST(BUILD_MINGW_X64)
629+
AC_SUBST(NDPI_GEN_EXTRA_LIBS)
622630
AC_SUBST(BUILD_FUZZTARGETS)
623631
AC_SUBST(JSONC_CFLAGS)
624632
AC_SUBST(JSONC_LIBS)

0 commit comments

Comments
 (0)