aboutsummaryrefslogtreecommitdiff
path: root/example/reader_util.c
diff options
context:
space:
mode:
authorIvan Nardi <12729895+IvanNardi@users.noreply.github.com>2025-06-23 11:24:18 +0200
committerGitHub <noreply@github.com>2025-06-23 11:24:18 +0200
commit978ca1ba1ab0f9d3f7d3c46e6f80a829b08205db (patch)
treef7748c2d810c75c0155fa3f81e3146a797f6fdba /example/reader_util.c
parent6cbc8d1471be221766fac49ed73f5b0e837917be (diff)
New API to enable/disable protocols. Removed `NDPI_LAST_IMPLEMENTED_PROTOCOL` (#2894)
Change the API to enable/disable protocols: you can set that via the standard `ndpi_set_config()` function, as every configuration parameters. By default, all protocols are enabled. Split the (local) context initialization into two phases: * `ndpi_init_detection_module()`: generic part. It does not depend on the configuration and on the protocols being enabled or not. It also calculates the real number of internal protocols * `ndpi_finalize_initialization()`: apply the configuration. All the initialization stuff that depend on protocols being enabled or not must be put here This is the last step to have the protocols number fully calculated at runtime Remove a (now) useless fuzzer. Important API changes: * remove `NDPI_LAST_IMPLEMENTED_PROTOCOL` define * remove `ndpi_get_num_internal_protocols()`. To get the number of configured protocols (internal and custom) you must use `ndpi_get_num_protocols()` after having called `ndpi_finalize_initialization()`
Diffstat (limited to 'example/reader_util.c')
-rw-r--r--example/reader_util.c58
1 files changed, 2 insertions, 56 deletions
diff --git a/example/reader_util.c b/example/reader_util.c
index e27981ca0..8233f3fe7 100644
--- a/example/reader_util.c
+++ b/example/reader_util.c
@@ -335,59 +335,6 @@ void ndpi_free_flow_info_half(struct ndpi_flow_info *flow) {
/* ***************************************************** */
-static char _proto_delim[] = " \t,:;";
-int parse_proto_name_list(char *str, struct ndpi_bitmask *bitmask, int inverted_logic) {
- char *n;
- uint16_t proto;
- char op;
- struct ndpi_detection_module_struct *module;
-
- if(!inverted_logic)
- op = 1; /* Default action: add to the bitmask */
- else
- op = 0; /* Default action: remove from the bitmask */
- /* Use a temporary module with all protocols enabled */
- module = ndpi_init_detection_module(NULL);
- if(!module)
- return 1;
- /* Try to be fast: we need only the protocol name -> protocol id mapping! */
- ndpi_set_config(module, "any", "ip_list.load", "0");
- ndpi_set_config(module, NULL, "flow_risk_lists.load", "0");
- ndpi_finalize_initialization(module);
-
- for(n = strtok(str,_proto_delim); n && *n; n = strtok(NULL,_proto_delim)) {
- if(*n == '-') {
- op = !inverted_logic ? 0 : 1;
- n++;
- } else if(*n == '+') {
- op = !inverted_logic ? 1 : 0;
- n++;
- }
- if(!strcmp(n,"all")) {
- if(op)
- ndpi_bitmask_set_all(bitmask);
- else
- ndpi_bitmask_reset(bitmask);
- continue;
- }
- proto = ndpi_get_proto_by_name(module, n);
- if(proto == NDPI_PROTOCOL_UNKNOWN && strcmp(n,"unknown") && strcmp(n,"0")) {
- LOG(NDPI_LOG_ERROR, "Invalid protocol %s\n", n);
- ndpi_exit_detection_module(module);
- return 1;
- }
- if(op)
- ndpi_bitmask_set(bitmask, proto);
- else
- ndpi_bitmask_clear(bitmask, proto);
- }
-
- ndpi_exit_detection_module(module);
- return 0;
-}
-
-/* ***************************************************** */
-
bool load_public_lists(struct ndpi_detection_module_struct *ndpi_str) {
char *lists_path = "../lists/public_suffix_list.dat";
struct stat st;
@@ -408,12 +355,11 @@ bool load_public_lists(struct ndpi_detection_module_struct *ndpi_str) {
struct ndpi_workflow* ndpi_workflow_init(const struct ndpi_workflow_prefs * prefs,
pcap_t * pcap_handle, int do_init_flows_root,
ndpi_serialization_format serialization_format,
- struct ndpi_global_context *g_ctx,
- struct ndpi_bitmask *enabled_bitmask) {
+ struct ndpi_global_context *g_ctx) {
struct ndpi_detection_module_struct * module;
struct ndpi_workflow * workflow;
- module = ndpi_init_detection_module_ext(g_ctx, enabled_bitmask);
+ module = ndpi_init_detection_module(g_ctx);
if(module == NULL) {
LOG(NDPI_LOG_ERROR, "global structure initialization failed\n");