diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/include/ndpi_api.h | 6 | ||||
-rw-r--r-- | src/include/ndpi_typedefs.h | 12 | ||||
-rw-r--r-- | src/lib/ndpi_content_match.c.inc | 12 | ||||
-rw-r--r-- | src/lib/ndpi_main.c | 50 | ||||
-rw-r--r-- | src/lib/protocols/bittorrent.c | 2 |
5 files changed, 47 insertions, 35 deletions
diff --git a/src/include/ndpi_api.h b/src/include/ndpi_api.h index 364fd0101..a39acd536 100644 --- a/src/include/ndpi_api.h +++ b/src/include/ndpi_api.h @@ -68,6 +68,12 @@ extern "C" { u_int16_t ndpi_host_ptree_match(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t host); /** + * Init single protocol match + */ + void ndpi_init_protocol_match(struct ndpi_detection_module_struct *ndpi_mod, + ndpi_protocol_match *match); + + /** * This function returns a new initialized detection module. * @param ticks_per_second the timestamp resolution per second (like 1000 for millisecond resolution) * @param __ndpi_malloc function pointer to a memory allocator diff --git a/src/include/ndpi_typedefs.h b/src/include/ndpi_typedefs.h index 33fe5430c..c52d43716 100644 --- a/src/include/ndpi_typedefs.h +++ b/src/include/ndpi_typedefs.h @@ -1015,4 +1015,16 @@ struct ndpi_flow_struct { struct ndpi_id_struct *dst; }; +typedef struct { + char *string_to_match, *proto_name; + int protocol_id; + ndpi_protocol_breed_t protocol_breed; +} ndpi_protocol_match; + +typedef struct { + u_int32_t network; + u_int8_t cidr; + u_int8_t value; +} ndpi_network; + #endif/* __NDPI_TYPEDEFS_H__ */ diff --git a/src/lib/ndpi_content_match.c.inc b/src/lib/ndpi_content_match.c.inc index 6bbc754cc..59d36b42f 100644 --- a/src/lib/ndpi_content_match.c.inc +++ b/src/lib/ndpi_content_match.c.inc @@ -18,18 +18,6 @@ * */ -typedef struct { - char *string_to_match, *proto_name; - int protocol_id; - ndpi_protocol_breed_t protocol_breed; -} ndpi_protocol_match; - -typedef struct { - u_int32_t network; - u_int8_t cidr; - u_int8_t value; -} ndpi_network; - /* ****************************************************** */ static ndpi_network host_protocol_list[] = { diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index 636d3ca73..a42afa3d1 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -577,30 +577,36 @@ static int ndpi_remove_host_url_subprotocol(struct ndpi_detection_module_struct /* ******************************************************************** */ -static void init_string_based_protocols(struct ndpi_detection_module_struct *ndpi_mod) { - int i; - - for(i=0; host_match[i].string_to_match != NULL; i++) { - u_int16_t no_master[2] = { NDPI_PROTOCOL_NO_MASTER_PROTO, NDPI_PROTOCOL_NO_MASTER_PROTO }; - ndpi_port_range ports_a[MAX_DEFAULT_PORTS], ports_b[MAX_DEFAULT_PORTS]; - - ndpi_add_host_url_subprotocol(ndpi_mod, host_match[i].string_to_match, - host_match[i].protocol_id, host_match[i].protocol_breed); +void ndpi_init_protocol_match(struct ndpi_detection_module_struct *ndpi_mod, + ndpi_protocol_match *match) { + u_int16_t no_master[2] = { NDPI_PROTOCOL_NO_MASTER_PROTO, NDPI_PROTOCOL_NO_MASTER_PROTO }; + ndpi_port_range ports_a[MAX_DEFAULT_PORTS], ports_b[MAX_DEFAULT_PORTS]; + + ndpi_add_host_url_subprotocol(ndpi_mod, match->string_to_match, + match->protocol_id, match->protocol_breed); + + if(ndpi_mod->proto_defaults[match->protocol_id].protoName == NULL) { + ndpi_mod->proto_defaults[match->protocol_id].protoName = ndpi_strdup(match->proto_name); + ndpi_mod->proto_defaults[match->protocol_id].protoId = match->protocol_id; + ndpi_mod->proto_defaults[match->protocol_id].protoBreed = match->protocol_breed; + } + + ndpi_set_proto_defaults(ndpi_mod, + ndpi_mod->proto_defaults[match->protocol_id].protoBreed, + ndpi_mod->proto_defaults[match->protocol_id].protoId, + no_master, no_master, + ndpi_mod->proto_defaults[match->protocol_id].protoName, + ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */, + ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */); +} - if(ndpi_mod->proto_defaults[host_match[i].protocol_id].protoName == NULL) { - ndpi_mod->proto_defaults[host_match[i].protocol_id].protoName = ndpi_strdup(host_match[i].proto_name); - ndpi_mod->proto_defaults[host_match[i].protocol_id].protoId = host_match[i].protocol_id; - ndpi_mod->proto_defaults[host_match[i].protocol_id].protoBreed = host_match[i].protocol_breed; - } +/* ******************************************************************** */ - ndpi_set_proto_defaults(ndpi_mod, - ndpi_mod->proto_defaults[host_match[i].protocol_id].protoBreed, - ndpi_mod->proto_defaults[host_match[i].protocol_id].protoId, - no_master, no_master, - ndpi_mod->proto_defaults[host_match[i].protocol_id].protoName, - ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */, - ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */); - } +static void init_string_based_protocols(struct ndpi_detection_module_struct *ndpi_mod) { + int i; + + for(i=0; host_match[i].string_to_match != NULL; i++) + ndpi_init_protocol_match(ndpi_mod, &host_match[i]); #ifdef DEBUG ac_automata_display(ndpi_mod->host_automa.ac_automa, 'n'); diff --git a/src/lib/protocols/bittorrent.c b/src/lib/protocols/bittorrent.c index 13dbb1418..cc1e365fe 100644 --- a/src/lib/protocols/bittorrent.c +++ b/src/lib/protocols/bittorrent.c @@ -46,7 +46,7 @@ static void ndpi_add_connection_as_bittorrent(struct ndpi_detection_module_struc if(bt_magic) bt_hash = &bt_magic[19], peer_id = &bt_magic[39]; } else - bt_hash = &flow->packet.payload[28], peer_id = &flow->packet.payload[48]; + bt_hash = (const char*)&flow->packet.payload[28], peer_id = (const char*)&flow->packet.payload[48]; if(bt_hash) memcpy(flow->bittorent_hash, bt_hash, 20); } |