diff options
author | Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> | 2025-06-03 09:45:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-03 09:45:46 +0200 |
commit | 70a72f163800dd37dca1ec586ae0a58a6cef8206 (patch) | |
tree | 42e08401cc3ec36d6c83961ed6894c698559eedf /fuzz/fuzz_readerutils_workflow.cpp | |
parent | 40fe26b2f165b6a42d07bf53671c99c85e2d243d (diff) |
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.
Diffstat (limited to 'fuzz/fuzz_readerutils_workflow.cpp')
-rw-r--r-- | fuzz/fuzz_readerutils_workflow.cpp | 21 |
1 files changed, 9 insertions, 12 deletions
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); |