aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Deri <deri@ntop.org>2018-05-14 22:58:14 +0200
committerLuca Deri <deri@ntop.org>2018-05-14 22:58:14 +0200
commit66b759ca690425aa94b88b05f5a23818dce0b4be (patch)
treead4dd7439df3ed96057e9d9e1c7d36c036a4535d
parent529492e81fa9866f0b4cd22227eb6a499ac5da68 (diff)
Hidden ndpi_detection_module_struct definition
-rw-r--r--example/ndpiReader.c16
-rw-r--r--example/ndpi_util.c12
-rw-r--r--libndpi.sym4
-rw-r--r--src/include/ndpi_api.h57
-rw-r--r--src/include/ndpi_main.h1
-rw-r--r--src/include/ndpi_typedefs.h10
-rw-r--r--src/lib/Makefile.am2
-rw-r--r--src/lib/Makefile.simple2
-rw-r--r--src/lib/ndpi_main.c20
9 files changed, 62 insertions, 62 deletions
diff --git a/example/ndpiReader.c b/example/ndpiReader.c
index 2aa08feba..c3b49aa41 100644
--- a/example/ndpiReader.c
+++ b/example/ndpiReader.c
@@ -378,29 +378,31 @@ int cmpFlows(const void *_a, const void *_b) {
void extcap_config() {
int i, argidx = 0;
struct ndpi_proto_sorter *protos;
-
+ u_int ndpi_num_supported_protocols = ndpi_get_ndpi_num_supported_protocols(ndpi_info_mod);
+ ndpi_proto_defaults_t *proto_defaults = ndpi_get_proto_defaults(ndpi_info_mod);
+
/* -i <interface> */
printf("arg {number=%d}{call=-i}{display=Capture Interface}{type=string}"
"{tooltip=The interface name}\n", argidx++);
printf("arg {number=%d}{call=-i}{display=Pcap File to Analyze}{type=fileselect}"
"{tooltip=The pcap file to analyze (if the interface is unspecified)}\n", argidx++);
- protos = (struct ndpi_proto_sorter*)malloc(sizeof(struct ndpi_proto_sorter) * ndpi_info_mod->ndpi_num_supported_protocols);
+ protos = (struct ndpi_proto_sorter*)malloc(sizeof(struct ndpi_proto_sorter) * ndpi_num_supported_protocols);
if(!protos) exit(0);
- for(i=0; i<(int) ndpi_info_mod->ndpi_num_supported_protocols; i++) {
+ for(i=0; i<(int) ndpi_num_supported_protocols; i++) {
protos[i].id = i;
- snprintf(protos[i].name, sizeof(protos[i].name), "%s", ndpi_info_mod->proto_defaults[i].protoName);
+ snprintf(protos[i].name, sizeof(protos[i].name), "%s", proto_defaults[i].protoName);
}
- qsort(protos, ndpi_info_mod->ndpi_num_supported_protocols, sizeof(struct ndpi_proto_sorter), cmpProto);
+ qsort(protos, ndpi_num_supported_protocols, sizeof(struct ndpi_proto_sorter), cmpProto);
printf("arg {number=%d}{call=-9}{display=nDPI Protocol Filter}{type=selector}"
"{tooltip=nDPI Protocol to be filtered}\n", argidx);
printf("value {arg=%d}{value=%d}{display=%s}\n", argidx, -1, "All Protocols (no nDPI filtering)");
- for(i=0; i<(int)ndpi_info_mod->ndpi_num_supported_protocols; i++)
+ for(i=0; i<(int)ndpi_num_supported_protocols; i++)
printf("value {arg=%d}{value=%d}{display=%s (%d)}\n", argidx, protos[i].id,
protos[i].name, protos[i].id);
@@ -1933,7 +1935,7 @@ static void printResults(u_int64_t tot_usec) {
if(!quiet_mode) {
printf("\nnDPI Memory statistics:\n");
- printf("\tnDPI Memory (once): %-13s\n", formatBytes(sizeof(struct ndpi_detection_module_struct), buf, sizeof(buf)));
+ printf("\tnDPI Memory (once): %-13s\n", formatBytes(ndpi_get_ndpi_detection_module_size(), buf, sizeof(buf)));
printf("\tFlow Memory (per flow): %-13s\n", formatBytes(sizeof(struct ndpi_flow_struct), buf, sizeof(buf)));
printf("\tActual Memory: %-13s\n", formatBytes(current_ndpi_memory, buf, sizeof(buf)));
printf("\tPeak Memory: %-13s\n", formatBytes(max_ndpi_memory, buf, sizeof(buf)));
diff --git a/example/ndpi_util.c b/example/ndpi_util.c
index d83f1fdca..9695558ae 100644
--- a/example/ndpi_util.c
+++ b/example/ndpi_util.c
@@ -113,14 +113,17 @@ static uint16_t ndpi_get_proto_id(struct ndpi_detection_module_struct *ndpi_mod,
uint16_t proto_id;
char *e;
unsigned long p = strtol(name,&e,0);
+ ndpi_proto_defaults_t *proto_defaults = ndpi_get_proto_defaults(ndpi_mod);
+
if(e && !*e) {
if(p < NDPI_MAX_SUPPORTED_PROTOCOLS+NDPI_MAX_NUM_CUSTOM_PROTOCOLS &&
- ndpi_mod->proto_defaults[p].protoName) return (uint16_t)p;
+ proto_defaults[p].protoName) return (uint16_t)p;
return NDPI_PROTOCOL_UNKNOWN;
}
+
for(proto_id=NDPI_PROTOCOL_UNKNOWN; proto_id < NDPI_MAX_SUPPORTED_PROTOCOLS+NDPI_MAX_NUM_CUSTOM_PROTOCOLS; proto_id++) {
- if(ndpi_mod->proto_defaults[proto_id].protoName &&
- !strcasecmp(ndpi_mod->proto_defaults[proto_id].protoName,name))
+ if(proto_defaults[proto_id].protoName &&
+ !strcasecmp(proto_defaults[proto_id].protoName,name))
return proto_id;
}
return NDPI_PROTOCOL_UNKNOWN;
@@ -181,7 +184,8 @@ struct ndpi_workflow* ndpi_workflow_init(const struct ndpi_workflow_prefs * pref
NDPI_LOG(0, NULL, NDPI_LOG_ERROR, "global structure initialization failed\n");
exit(-1);
}
- module->ndpi_log_level = nDPI_LogLevel;
+
+ ndpi_set_log_level(module, nDPI_LogLevel);
if(_debug_protocols != NULL && ! _debug_protocols_ok) {
if(parse_debug_proto(module,_debug_protocols))
diff --git a/libndpi.sym b/libndpi.sym
index db9b7480f..66cffbb18 100644
--- a/libndpi.sym
+++ b/libndpi.sym
@@ -69,3 +69,7 @@ ndpi_fill_protocol_category
ndpi_load_hostname_category
ndpi_enable_loaded_categories
ndpi_set_detection_preferences
+ndpi_get_proto_defaults
+ndpi_get_ndpi_num_supported_protocols
+ndpi_get_ndpi_num_custom_protocols
+ndpi_get_ndpi_detection_module_size
diff --git a/src/include/ndpi_api.h b/src/include/ndpi_api.h
index c2c129ec0..16ac45de0 100644
--- a/src/include/ndpi_api.h
+++ b/src/include/ndpi_api.h
@@ -58,7 +58,7 @@ extern "C" {
* else 0
*
*/
- int check_punycode_string(char * buff , int len);
+ int check_punycode_string(char *buff, int len);
/**
@@ -78,7 +78,6 @@ extern "C" {
*/
u_int32_t ndpi_detection_get_sizeof_ndpi_id_struct(void);
-
/**
* nDPI personal allocation and free functions
**/
@@ -115,7 +114,6 @@ extern "C" {
*/
char* ndpi_strncasestr(const char *s, const char *find, size_t slen);
-
/**
* Returns the nDPI protocol id for IP-based protocol detection
*
@@ -128,7 +126,6 @@ extern "C" {
u_int16_t ndpi_network_ptree_match(struct ndpi_detection_module_struct *ndpi_struct,
struct in_addr *pin);
-
/**
* Init single protocol match
*
@@ -155,7 +152,6 @@ extern "C" {
*/
void ndpi_free_flow(struct ndpi_flow_struct *flow);
-
/**
* Enables cache support.
* In nDPI is used for some protocol (i.e. Skype)
@@ -168,7 +164,6 @@ extern "C" {
void ndpi_enable_cache(struct ndpi_detection_module_struct *ndpi_mod,
char* host, u_int port);
-
/**
* Destroys the detection module
*
@@ -177,7 +172,6 @@ extern "C" {
*/
void ndpi_exit_detection_module(struct ndpi_detection_module_struct *ndpi_struct);
-
/**
* Sets a single protocol bitmask
* This function does not increment the index of the callback_buffer
@@ -192,7 +186,8 @@ extern "C" {
* @par b_add_detection_bitmask = if set as "true" add the protocol bitmask to the detection bitmask
*
*/
- void ndpi_set_bitmask_protocol_detection(char *label, struct ndpi_detection_module_struct *ndpi_struct,
+ void ndpi_set_bitmask_protocol_detection(char *label,
+ struct ndpi_detection_module_struct *ndpi_struct,
const NDPI_PROTOCOL_BITMASK *detection_bitmask,
const u_int32_t idx,
u_int16_t ndpi_protocol_id,
@@ -202,7 +197,6 @@ extern "C" {
u_int8_t b_save_bitmask_unknow,
u_int8_t b_add_detection_bitmask);
-
/**
* Sets the protocol bitmask2
*
@@ -213,7 +207,6 @@ extern "C" {
void 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
@@ -270,8 +263,6 @@ extern "C" {
const u_int64_t current_tick,
struct ndpi_id_struct *src,
struct ndpi_id_struct *dst);
-
-
/**
* Get the main protocol of the passed flows for the detected module
*
@@ -283,8 +274,7 @@ extern "C" {
*/
u_int16_t ndpi_get_flow_masterprotocol(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow);
-
-
+
/**
* API call that is called internally by ndpi_detection_process_packet or by apps
* that want to avoid calling ndpi_detection_process_packet as they have already
@@ -316,7 +306,6 @@ extern "C" {
u_int8_t ndpi_detection_get_l4(const u_int8_t *l3, u_int16_t l3_len, const u_int8_t **l4_return, u_int16_t *l4_len_return,
u_int8_t *l4_protocol_return, u_int32_t flags);
-
/**
* Search and return the protocol based on matched ports
*
@@ -333,8 +322,6 @@ extern "C" {
u_int16_t sport,
u_int32_t dhost,
u_int16_t dport);
-
-
/**
* Search and return the protocol guessed that is undetected
*
@@ -353,8 +340,6 @@ extern "C" {
u_int16_t sport,
u_int32_t dhost,
u_int16_t dport);
-
-
/**
* Check if the string passed match with a protocol
*
@@ -369,8 +354,6 @@ extern "C" {
char *string_to_match,
u_int string_to_match_len,
u_int8_t is_host_match);
-
-
/**
* Check if the host passed match with a protocol
*
@@ -405,8 +388,6 @@ extern "C" {
char *string_to_match,
u_int string_to_match_len,
u_int16_t master_protocol_id);
-
-
/**
* Exclude protocol from search
*
@@ -419,8 +400,6 @@ extern "C" {
struct ndpi_flow_struct *flow,
u_int16_t master_protocol_id,
const char *_file, const char *_func,int _line);
-
-
/**
* Check if the string -bigram_to_match- match with a bigram of -automa-
*
@@ -444,7 +423,8 @@ extern "C" {
* @return the buffer contains the master_protocol and protocol name
*
*/
- char* ndpi_protocol2name(struct ndpi_detection_module_struct *ndpi_mod, ndpi_protocol proto, char *buf, u_int buf_len);
+ char* ndpi_protocol2name(struct ndpi_detection_module_struct *ndpi_mod,
+ ndpi_protocol proto, char *buf, u_int buf_len);
/**
* Find out if a given category is custom/user-defined
@@ -543,7 +523,6 @@ extern "C" {
ndpi_protocol_breed_t ndpi_get_proto_breed(struct ndpi_detection_module_struct *ndpi_struct,
u_int16_t proto);
-
/**
* Return the string name of the protocol breed
*
@@ -555,7 +534,6 @@ extern "C" {
char* ndpi_get_proto_breed_name(struct ndpi_detection_module_struct *ndpi_struct,
ndpi_protocol_breed_t breed_id);
-
/**
* Return the ID of the protocol
*
@@ -566,7 +544,6 @@ extern "C" {
*/
int ndpi_get_protocol_id(struct ndpi_detection_module_struct *ndpi_mod, char *proto);
-
/**
* Return the ID of the category
*
@@ -577,7 +554,6 @@ extern "C" {
*/
int ndpi_get_category_id(struct ndpi_detection_module_struct *ndpi_mod, char *cat);
-
/**
* Write the list of the supported protocols
*
@@ -585,7 +561,6 @@ extern "C" {
*/
void ndpi_dump_protocols(struct ndpi_detection_module_struct *mod);
-
/**
* Read a file and load the protocols
*
@@ -604,7 +579,6 @@ extern "C" {
int ndpi_load_protocols_file(struct ndpi_detection_module_struct *ndpi_mod,
char* path);
-
/**
* Get the total number of the supported protocols
*
@@ -614,7 +588,6 @@ extern "C" {
*/
u_int ndpi_get_num_supported_protocols(struct ndpi_detection_module_struct *ndpi_mod);
-
/**
* Get the nDPI version release
*
@@ -623,7 +596,6 @@ extern "C" {
*/
char* ndpi_revision(void);
-
/**
* Set the automa for the protocol search
*
@@ -634,7 +606,6 @@ extern "C" {
void ndpi_set_automa(struct ndpi_detection_module_struct *ndpi_struct,
void* automa);
-
#ifdef NDPI_PROTOCOL_HTTP
/**
* Retrieve information for HTTP flows
@@ -647,7 +618,6 @@ extern "C" {
ndpi_http_method ndpi_get_http_method(struct ndpi_detection_module_struct *ndpi_mod,
struct ndpi_flow_struct *flow);
-
/**
* Get the HTTP url
*
@@ -659,7 +629,6 @@ extern "C" {
char* ndpi_get_http_url(struct ndpi_detection_module_struct *ndpi_mod,
struct ndpi_flow_struct *flow);
-
/**
* Get the HTTP content-type
*
@@ -672,7 +641,6 @@ extern "C" {
struct ndpi_flow_struct *flow);
#endif
-
#ifdef NDPI_PROTOCOL_TOR
/**
* Check if the flow could be detected as TOR protocol
@@ -697,7 +665,6 @@ extern "C" {
*/
void* ndpi_init_automa(void);
-
/**
* Free Aho-Corasick automata allocated with ndpi_init_automa();
*
@@ -706,7 +673,6 @@ extern "C" {
*/
void ndpi_free_automa(void *_automa);
-
/**
* Add a string to match to an automata
*
@@ -718,7 +684,6 @@ extern "C" {
*/
int ndpi_add_string_value_to_automa(void *_automa, char *str, unsigned long num);
-
/**
* Add a string to match to an automata. Same as ndpi_add_string_value_to_automa() with num set to 1
*
@@ -729,7 +694,6 @@ extern "C" {
*/
int ndpi_add_string_to_automa(void *_automa, char *str);
-
/**
* Finalize the automa (necessary before start searching)
*
@@ -738,7 +702,6 @@ extern "C" {
*/
void ndpi_finalize_automa(void *_automa);
-
/**
* Add a string to match to an automata
*
@@ -758,9 +721,15 @@ extern "C" {
struct ndpi_flow_struct *flow,
ndpi_protocol *ret);
int ndpi_set_detection_preferences(struct ndpi_detection_module_struct *ndpi_mod,
- ndpi_detection_preference pref,
+ ndpi_detection_preference pref,
int value);
+ ndpi_proto_defaults_t* ndpi_get_proto_defaults(struct ndpi_detection_module_struct *ndpi_mod);
+ u_int ndpi_get_ndpi_num_supported_protocols(struct ndpi_detection_module_struct *ndpi_mod);
+ u_int ndpi_get_ndpi_num_custom_protocols(struct ndpi_detection_module_struct *ndpi_mod);
+ u_int ndpi_get_ndpi_detection_module_size();
+ void ndpi_set_log_level(struct ndpi_detection_module_struct *ndpi_mod, u_int l);
+
/**
* Add a string to match to an automata
*
diff --git a/src/include/ndpi_main.h b/src/include/ndpi_main.h
index 79eeab8f1..b76335e02 100644
--- a/src/include/ndpi_main.h
+++ b/src/include/ndpi_main.h
@@ -61,7 +61,6 @@ extern "C" {
u_int64_t ndpi_bytestream_dec_or_hex_to_number64(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read);
u_int32_t ndpi_bytestream_to_ipv4(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read);
-
void ndpi_set_detected_protocol(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
u_int16_t upper_detected_protocol,
diff --git a/src/include/ndpi_typedefs.h b/src/include/ndpi_typedefs.h
index 83fad2930..33b898c20 100644
--- a/src/include/ndpi_typedefs.h
+++ b/src/include/ndpi_typedefs.h
@@ -61,10 +61,10 @@ typedef struct ndpi_protocol_bitmask_struct {
/* NDPI_DEBUG_FUNCTION_PTR (cast) */
typedef void (*ndpi_debug_function_ptr) (u_int32_t protocol, void *module_struct,
- ndpi_log_level_t log_level, const char *file, const char *func, unsigned line,
+ ndpi_log_level_t log_level, const char *file,
+ const char *func, unsigned line,
const char *format, ...);
-
/* ************************************************************ */
/* ******************* NDPI NETWORKS HEADERS ****************** */
/* ************************************************************ */
@@ -709,7 +709,8 @@ struct ndpi_packet_struct {
struct ndpi_int_one_line_struct http_x_session_type;
struct ndpi_int_one_line_struct server_line;
struct ndpi_int_one_line_struct http_method;
- struct ndpi_int_one_line_struct http_response; /* the first "word" in this pointer is the response code in the packet (200, etc) */
+ struct ndpi_int_one_line_struct http_response; /* the first "word" in this pointer is the
+ response code in the packet (200, etc) */
u_int8_t http_num_headers; /* number of found (valid) header lines in HTTP request or response */
u_int16_t l3_packet_len;
@@ -744,7 +745,6 @@ struct ndpi_subprotocol_conf_struct {
void (*func) (struct ndpi_detection_module_struct *, char *attr, char *value, int protocol_id);
};
-
typedef struct {
u_int16_t port_low, port_high;
} ndpi_port_range;
@@ -843,6 +843,7 @@ struct hs_list {
};
#endif
+#ifdef NDPI_LIB_COMPILATION
struct ndpi_detection_module_struct {
NDPI_PROTOCOL_BITMASK detection_bitmask;
NDPI_PROTOCOL_BITMASK generic_http_packet_bitmask;
@@ -965,6 +966,7 @@ struct ndpi_detection_module_struct {
void *hyperscan; /* Intel Hyperscan */
};
+#endif
struct ndpi_flow_struct {
u_int16_t detected_protocol_stack[NDPI_PROTOCOL_SIZE];
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index ea29f89f7..b1ff5a072 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -1,6 +1,6 @@
lib_LTLIBRARIES = libndpi.la
-CFLAGS += -fPIC -DPIC # --coverage
+CFLAGS += -fPIC -DPIC -DNDPI_LIB_COMPILATION # --coverage
libndpi_la_CPPFLAGS = -I$(top_srcdir)/src/include/ -I$(top_srcdir)/src/lib/third_party/include/ @HS_INC@
libndpi_la_LDFLAGS = -version-info 1:0:0 -export-symbols $(top_srcdir)/libndpi.sym
diff --git a/src/lib/Makefile.simple b/src/lib/Makefile.simple
index 2a6649131..1aae55636 100644
--- a/src/lib/Makefile.simple
+++ b/src/lib/Makefile.simple
@@ -5,7 +5,7 @@
# cd src/lib
# make -f Makefile.simple
#
-CFLAGS += -fPIC -DPIC -I../include -Ithird_party/include
+CFLAGS += -fPIC -DPIC -I../include -Ithird_party/include -DNDPI_LIB_COMPILATION
RANLIB=ranlib
OBJECTS = $(patsubst protocols/%.c, protocols/%.o, $(wildcard protocols/*.c)) $(patsubst third_party/src/%.c, third_party/src/%.o, $(wildcard third_party/src/*.c)) ndpi_main.o
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
index 0205a6354..43f8d93c6 100644
--- a/src/lib/ndpi_main.c
+++ b/src/lib/ndpi_main.c
@@ -5655,3 +5655,23 @@ void NDPI_DUMP_BITMASK(NDPI_PROTOCOL_BITMASK a) {
u_int8_t ndpi_get_api_version() {
return(NDPI_API_VERSION);
}
+
+ndpi_proto_defaults_t* ndpi_get_proto_defaults(struct ndpi_detection_module_struct *ndpi_mod) {
+ return(ndpi_mod->proto_defaults);
+}
+
+u_int ndpi_get_ndpi_num_supported_protocols(struct ndpi_detection_module_struct *ndpi_mod) {
+ return(ndpi_mod->ndpi_num_supported_protocols);
+}
+
+u_int ndpi_get_ndpi_num_custom_protocols(struct ndpi_detection_module_struct *ndpi_mod) {
+ return(ndpi_mod->ndpi_num_custom_protocols);
+}
+
+u_int ndpi_get_ndpi_detection_module_size() {
+ return(sizeof(struct ndpi_detection_module_struct));
+}
+
+void ndpi_set_log_level(struct ndpi_detection_module_struct *ndpi_mod, u_int l) {
+ ndpi_mod->ndpi_log_level = l;
+}