aboutsummaryrefslogtreecommitdiff
path: root/src/include/ndpi_typedefs.h
diff options
context:
space:
mode:
authorIvan Nardi <12729895+IvanNardi@users.noreply.github.com>2025-06-09 09:00:17 +0200
committerGitHub <noreply@github.com>2025-06-09 09:00:17 +0200
commitcbd7136b3480774a10f18744d33d3694ffee221b (patch)
treea9981734e85c500ab4605e913cd6ee8b8197492d /src/include/ndpi_typedefs.h
parent75395cb264f9bfd38d27ac0ba506acc9eab22e34 (diff)
Remove `NDPI_PROTOCOL_BITMASK`; add a new generic bitmask data structure (#2871)
The main difference is that the memory is allocated at runtime Typical usercase: ``` struct ndpi_bitmask b; ndpi_bitmask_alloc(&b, ndpi_get_num_internal_protocols()); ndpi_bitmask_set(&b, $BIT); ndpi_bitmask_is_set(&b, $BIT); [...] ndpi_bitmask_dealloc(&b); ``` See #2136
Diffstat (limited to 'src/include/ndpi_typedefs.h')
-rw-r--r--src/include/ndpi_typedefs.h43
1 files changed, 17 insertions, 26 deletions
diff --git a/src/include/ndpi_typedefs.h b/src/include/ndpi_typedefs.h
index 2947866fe..20f5cd335 100644
--- a/src/include/ndpi_typedefs.h
+++ b/src/include/ndpi_typedefs.h
@@ -262,34 +262,25 @@ typedef u_int32_t ndpi_ndpi_mask;
#define MAX_NUM_RISK_INFOS 8
-/* NDPI_PROTO_BITMASK_STRUCT */
-#ifdef NDPI_CFFI_PREPROCESSING
-#undef NDPI_NUM_FDS_BITS
-#define NDPI_NUM_FDS_BITS 16
-#endif
-
-typedef struct ndpi_protocol_bitmask_struct {
- ndpi_ndpi_mask fds_bits[NDPI_NUM_FDS_BITS];
-} ndpi_protocol_bitmask_struct_t;
-
-
-#ifdef NDPI_CFFI_PREPROCESSING
-#undef NDPI_NUM_FDS_BITS_DISSECTORS
-#define NDPI_NUM_FDS_BITS_DISSECTORS 9
-#endif
-
-typedef struct ndpi_dissector_bitmask_struct {
- ndpi_ndpi_mask fds_bits[NDPI_NUM_FDS_BITS_DISSECTORS];
-} ndpi_dissector_bitmask_struct_t;
+struct ndpi_bitmask {
+ u_int16_t max_bits;
+ u_int16_t num_fds;
+ ndpi_ndpi_mask *fds;
+};
-#ifdef NDPI_CFFI_PREPROCESSING
-#undef NDPI_NUM_FDS_BITS_INTERNAL
-#define NDPI_NUM_FDS_BITS_INTERNAL 15
+#define NDPI_MAX_NUM_DISSECTORS 288 /* Multiple of 32 */
+#ifndef NDPI_CFFI_PREPROCESSING
+#define NDPI_NUM_FDS_DISSECTORS howmanybits(NDPI_MAX_NUM_DISSECTORS, 32)
+#else
+#define NDPI_NUM_FDS_DISSECTORS 9
#endif
-typedef struct ndpi_internal_protocol_bitmask_struct {
- ndpi_ndpi_mask fds_bits[NDPI_NUM_FDS_BITS_INTERNAL];
-} ndpi_internal_protocol_bitmask_struct_t;
+/* Similar to `struct ndpi_bitmask` but with pre-allocated memory, i.e. fixed size.
+ Used only internally in `ndpi_flow_struct`
+ */
+struct ndpi_dissector_bitmask {
+ ndpi_ndpi_mask fds[NDPI_NUM_FDS_DISSECTORS];
+};
struct ndpi_detection_module_struct;
@@ -1664,7 +1655,7 @@ struct ndpi_flow_struct {
/* **Packet** metadata for flows where monitoring is enabled. It is reset after each packet! */
struct ndpi_metadata_monitoring *monit;
- NDPI_DISSECTOR_BITMASK excluded_dissectors_bitmask;
+ struct ndpi_dissector_bitmask excluded_dissectors_bitmask;
/* NDPI_PROTOCOL_BITTORRENT */
u_int8_t bittorrent_stage; // can be 0 - 255