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. --- src/include/ndpi_api.h | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'src/include/ndpi_api.h') diff --git a/src/include/ndpi_api.h b/src/include/ndpi_api.h index 8688fb2a4..a59a0925e 100644 --- a/src/include/ndpi_api.h +++ b/src/include/ndpi_api.h @@ -224,15 +224,28 @@ extern "C" { * it do not forget to call first ndpi_finalize_initialization() * * You can call this function multiple times, (i.e. to create multiple - * indipendent detection contexts) but all these calls MUST NOT run + * independent detection contexts) but all these calls MUST NOT run * in parallel * - * @g_ctx = global context associated to the new detection module; NULL if no global context is needed + * @par g_ctx = global context associated to the new detection module; NULL if no global context is needed * @return the initialized detection module * */ struct ndpi_detection_module_struct *ndpi_init_detection_module(struct ndpi_global_context *g_ctx); + + /** + * Similar to `ndpi_init_detection_module` but you can also set the protocol bitmask + * By default, all protocols are enabled + * + * @par g_ctx = global context associated to the new detection module; NULL if no global context is needed + * @par detection_bitmask = protocol bitmask. If NULL, all protocols will be enabled + * @return the initialized detection module + * + */ + struct ndpi_detection_module_struct *ndpi_init_detection_module_ext(struct ndpi_global_context *g_ctx, + const NDPI_INTERNAL_PROTOCOL_BITMASK *detection_bitmask); + /** * Completes the initialization (2nd step) * @@ -267,17 +280,6 @@ extern "C" { */ void ndpi_exit_detection_module(struct ndpi_detection_module_struct *ndpi_struct); - /** - * Sets the protocol bitmask2 - * - * @par ndpi_struct = the detection module - * @par detection_bitmask = the protocol bitmask to set - * @return 0 if ok, -1 if error - * - */ - int ndpi_set_protocol_detection_bitmask2(struct ndpi_detection_module_struct *ndpi_struct, - const NDPI_PROTOCOL_BITMASK * detection_bitmask); - /** * Function to be called before we give up with detection for a given flow. * This function reduces the NDPI_UNKNOWN_PROTOCOL detection -- cgit v1.2.3