aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--example/ndpi_util.c8
-rw-r--r--src/include/ndpi_api.h8
-rw-r--r--src/lib/ndpi_main.c13
3 files changed, 21 insertions, 8 deletions
diff --git a/example/ndpi_util.c b/example/ndpi_util.c
index 8fe104b3e..1bb094a1e 100644
--- a/example/ndpi_util.c
+++ b/example/ndpi_util.c
@@ -62,16 +62,13 @@
#define GTP_U_V1_PORT 2152
#define TZSP_PORT 37008
-#define SIZEOF_ID_STRUCT (sizeof(struct ndpi_id_struct))
-#define SIZEOF_FLOW_STRUCT (sizeof(struct ndpi_flow_struct))
-
#include "ndpi_main.h"
#include "ndpi_util.h"
/* ***************************************************** */
void ndpi_free_flow_info_half(struct ndpi_flow_info *flow) {
- if(flow->ndpi_flow) { ndpi_free_flow(flow->ndpi_flow); flow->ndpi_flow = NULL; }
+ if(flow->ndpi_flow) { ndpi_flow_free(flow->ndpi_flow); flow->ndpi_flow = NULL; }
if(flow->src_id) { ndpi_free(flow->src_id); flow->src_id = NULL; }
if(flow->dst_id) { ndpi_free(flow->dst_id); flow->dst_id = NULL; }
}
@@ -106,6 +103,7 @@ static void free_wrapper(void *freeable) {
struct ndpi_workflow * ndpi_workflow_init(const struct ndpi_workflow_prefs * prefs, pcap_t * pcap_handle) {
set_ndpi_malloc(malloc_wrapper), set_ndpi_free(free_wrapper);
+ set_ndpi_flow_malloc(NULL), set_ndpi_flow_free(NULL);
/* TODO: just needed here to init ndpi malloc wrapper */
struct ndpi_detection_module_struct * module = ndpi_init_detection_module();
@@ -356,7 +354,7 @@ static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow
patchIPv6Address(newflow->lower_name), patchIPv6Address(newflow->upper_name);
}
- if((newflow->ndpi_flow = ndpi_malloc(SIZEOF_FLOW_STRUCT)) == NULL) {
+ if((newflow->ndpi_flow = ndpi_flow_malloc(SIZEOF_FLOW_STRUCT)) == NULL) {
NDPI_LOG(0, workflow->ndpi_struct, NDPI_LOG_ERROR, "[NDPI] %s(2): not enough memory\n", __FUNCTION__);
free(newflow);
return(NULL);
diff --git a/src/include/ndpi_api.h b/src/include/ndpi_api.h
index ca295b4e1..bcc5fe51f 100644
--- a/src/include/ndpi_api.h
+++ b/src/include/ndpi_api.h
@@ -31,6 +31,9 @@
extern "C" {
#endif
+#define SIZEOF_ID_STRUCT (sizeof(struct ndpi_id_struct))
+#define SIZEOF_FLOW_STRUCT (sizeof(struct ndpi_flow_struct))
+
#define NDPI_DETECTION_ONLY_IPV4 ( 1 << 0 )
#define NDPI_DETECTION_ONLY_IPV6 ( 1 << 1 )
@@ -79,8 +82,9 @@ extern "C" {
void * ndpi_realloc(void *ptr, size_t old_size, size_t new_size);
char * ndpi_strdup(const char *s);
void ndpi_free(void *ptr);
+ void * ndpi_flow_malloc(size_t size);
+ void ndpi_flow_free(void *ptr);
-
/**
* Search the first occurrence of substring -find- in -s-
* The search is limited to the first -slen- characters of the string
@@ -591,6 +595,8 @@ extern "C" {
/* Utility functions to set ndpi malloc/free/print wrappers */
void set_ndpi_malloc(void* (*__ndpi_malloc)(size_t size));
void set_ndpi_free(void (*__ndpi_free)(void *ptr));
+ void set_ndpi_flow_malloc(void* (*__ndpi_flow_malloc)(size_t size));
+ void set_ndpi_flow_free(void (*__ndpi_flow_free)(void *ptr));
void set_ndpi_debug_function(struct ndpi_detection_module_struct *ndpi_str, ndpi_debug_function_ptr ndpi_debug_printf);
#ifdef __cplusplus
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
index 5c8589c3f..5e65dbe5f 100644
--- a/src/lib/ndpi_main.c
+++ b/src/lib/ndpi_main.c
@@ -213,6 +213,9 @@ u_int8_t ndpi_ips_match(u_int32_t src, u_int32_t dst,
/* ****************************************** */
+static void *(*_ndpi_flow_malloc)(size_t size);
+static void (*_ndpi_flow_free)(void *ptr);
+
static void *(*_ndpi_malloc)(size_t size);
static void (*_ndpi_free)(void *ptr);
@@ -310,6 +313,7 @@ static int removeDefaultPort(ndpi_port_range *range,
/* ****************************************** */
void * ndpi_malloc(size_t size) { return(_ndpi_malloc ? _ndpi_malloc(size) : malloc(size)); }
+void * ndpi_flow_malloc(size_t size) { return(_ndpi_flow_malloc ? _ndpi_flow_malloc(size) : ndpi_malloc(size)); }
/* ****************************************** */
@@ -327,6 +331,7 @@ void * ndpi_calloc(unsigned long count, size_t size)
/* ****************************************** */
void ndpi_free(void *ptr) { if(_ndpi_free) _ndpi_free(ptr); else free(ptr); }
+void ndpi_flow_free(void *ptr) { if(_ndpi_flow_free) _ndpi_flow_free(ptr); else ndpi_free_flow((struct ndpi_flow_struct *) ptr); }
/* ****************************************** */
@@ -1757,8 +1762,10 @@ static int ndpi_add_host_ip_subprotocol(struct ndpi_detection_module_struct *ndp
#endif
void set_ndpi_malloc(void* (*__ndpi_malloc)(size_t size)) { _ndpi_malloc = __ndpi_malloc; }
+void set_ndpi_flow_malloc(void* (*__ndpi_flow_malloc)(size_t size)) { _ndpi_flow_malloc = __ndpi_flow_malloc; }
void set_ndpi_free(void (*__ndpi_free)(void *ptr)) { _ndpi_free = __ndpi_free; }
+void set_ndpi_flow_free(void (*__ndpi_flow_free)(void *ptr)) { _ndpi_flow_free = __ndpi_flow_free; }
void ndpi_debug_printf(unsigned int proto, struct ndpi_detection_module_struct *ndpi_str, ndpi_log_level_t log_level, const char * format, ...)
{
@@ -4680,8 +4687,10 @@ int ndpi_match_bigram(struct ndpi_detection_module_struct *ndpi_struct,
void ndpi_free_flow(struct ndpi_flow_struct *flow) {
if(flow) {
- if(flow->http.url) ndpi_free(flow->http.url);
- if(flow->http.content_type) ndpi_free(flow->http.content_type);
+ if(flow->http.url)
+ ndpi_free(flow->http.url);
+ if(flow->http.content_type)
+ ndpi_free(flow->http.content_type);
ndpi_free(flow);
}
}