From 70a72f163800dd37dca1ec586ae0a58a6cef8206 Mon Sep 17 00:00:00 2001 From: Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> Date: Tue, 3 Jun 2025 09:45:46 +0200 Subject: New API to enable/disable protocols; remove `ndpi_set_protocol_detection_bitmask2()` (#2853) The main goal is not to have the bitmask depending on the total number of protocols anymore: `NDPI_INTERNAL_PROTOCOL_BITMASK` depends only on internal protocols, i.e. on `NDPI_MAX_INTERNAL_PROTOCOLS`, i.e. custom-defined protocols are not counted. See #2136 Keep the old data structure `NDPI_PROTOCOL_BITMASK` with the old semantic. Since we need to change the API (and all the application code...) anyway, simplify the API: by default all the protocols are enabled. If you need otherwise, please use `ndpi_init_detection_module_ext()` instead of `ndpi_init_detection_module()` (you can find an example in the `ndpiReader` code). To update the application code you likely only need to remove these 3 lines from your code: ``` - NDPI_PROTOCOL_BITMASK all; - NDPI_BITMASK_SET_ALL(all); - ndpi_set_protocol_detection_bitmask2(ndpi_str, &all); ``` Removed an unused field and struct definition. --- fuzz/fuzz_readerutils_workflow.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'fuzz/fuzz_readerutils_workflow.cpp') diff --git a/fuzz/fuzz_readerutils_workflow.cpp b/fuzz/fuzz_readerutils_workflow.cpp index a92877aaa..919d87f25 100644 --- a/fuzz/fuzz_readerutils_workflow.cpp +++ b/fuzz/fuzz_readerutils_workflow.cpp @@ -25,12 +25,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { struct ndpi_workflow_prefs prefs; pcap_t *pcap_handle; ndpi_serialization_format serialization_format; - NDPI_PROTOCOL_BITMASK enabled_bitmask; ndpi_risk flow_risk; struct ndpi_flow_info *flow = NULL; /* unused */ const u_char *pkt; struct pcap_pkthdr *header; - int r, rc; + int r; char errbuf[PCAP_ERRBUF_SIZE]; FILE *fd; u_int8_t debug_protos_index; @@ -90,19 +89,17 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { g_ctx = ndpi_global_init(); - w = ndpi_workflow_init(&prefs, pcap_handle, 1, serialization_format, g_ctx); + + + w = ndpi_workflow_init(&prefs, pcap_handle, 1, serialization_format, g_ctx, NULL); if(w) { - NDPI_BITMASK_SET_ALL(enabled_bitmask); - rc = ndpi_set_protocol_detection_bitmask2(w->ndpi_struct, &enabled_bitmask); - if(rc == 0) { - ndpi_finalize_initialization(w->ndpi_struct); + ndpi_finalize_initialization(w->ndpi_struct); - header = NULL; + header = NULL; + r = pcap_next_ex(pcap_handle, &header, &pkt); + while (r > 0) { + ndpi_workflow_process_packet(w, header, pkt, &flow_risk, &flow); r = pcap_next_ex(pcap_handle, &header, &pkt); - while (r > 0) { - ndpi_workflow_process_packet(w, header, pkt, &flow_risk, &flow); - r = pcap_next_ex(pcap_handle, &header, &pkt); - } } ndpi_workflow_free(w); -- cgit v1.2.3