Fix for handling IP address based custom categories
This commit is contained in:
+13
-4
@@ -763,8 +763,10 @@ static void printFlow(u_int16_t id, struct ndpi_flow_info *flow, u_int16_t threa
|
|||||||
ndpi_get_proto_name(ndpi_thread_info[thread_id].workflow->ndpi_struct, flow->detected_protocol.app_protocol));
|
ndpi_get_proto_name(ndpi_thread_info[thread_id].workflow->ndpi_struct, flow->detected_protocol.app_protocol));
|
||||||
|
|
||||||
if(flow->detected_protocol.category != 0)
|
if(flow->detected_protocol.category != 0)
|
||||||
fprintf(out, "[cat: %s]", ndpi_category_get_name(ndpi_thread_info[thread_id].workflow->ndpi_struct,
|
fprintf(out, "[cat: %s/%u]",
|
||||||
flow->detected_protocol.category));
|
ndpi_category_get_name(ndpi_thread_info[thread_id].workflow->ndpi_struct,
|
||||||
|
flow->detected_protocol.category),
|
||||||
|
(unsigned int)flow->detected_protocol.category);
|
||||||
|
|
||||||
fprintf(out, "[%u pkts/%llu bytes ", flow->src2dst_packets, (long long unsigned int) flow->src2dst_bytes);
|
fprintf(out, "[%u pkts/%llu bytes ", flow->src2dst_packets, (long long unsigned int) flow->src2dst_bytes);
|
||||||
fprintf(out, "%s %u pkts/%llu bytes]",
|
fprintf(out, "%s %u pkts/%llu bytes]",
|
||||||
@@ -1501,9 +1503,16 @@ static void setupDetection(u_int16_t thread_id, pcap_t * pcap_handle) {
|
|||||||
category = strtok(NULL, "\t");
|
category = strtok(NULL, "\t");
|
||||||
|
|
||||||
if(category) {
|
if(category) {
|
||||||
|
int fields[4];
|
||||||
|
|
||||||
// printf("Loading %s\t%s\n", name, category);
|
// printf("Loading %s\t%s\n", name, category);
|
||||||
ndpi_load_hostname_category(ndpi_thread_info[thread_id].workflow->ndpi_struct,
|
|
||||||
name, (ndpi_protocol_category_t)atoi(category));
|
if(sscanf(name, "%d.%d.%d.%d", &fields[0], &fields[1], &fields[2], &fields[3]) == 4)
|
||||||
|
ndpi_load_ip_category(ndpi_thread_info[thread_id].workflow->ndpi_struct,
|
||||||
|
name, (ndpi_protocol_category_t)atoi(category));
|
||||||
|
else
|
||||||
|
ndpi_load_hostname_category(ndpi_thread_info[thread_id].workflow->ndpi_struct,
|
||||||
|
name, (ndpi_protocol_category_t)atoi(category));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-4
@@ -2457,9 +2457,8 @@ char * strsep(char **sp, char *sep)
|
|||||||
|
|
||||||
/* ******************************************************************** */
|
/* ******************************************************************** */
|
||||||
|
|
||||||
|
int ndpi_handle_rule(struct ndpi_detection_module_struct *ndpi_mod,
|
||||||
int ndpi_handle_rule(struct ndpi_detection_module_struct *ndpi_mod, char* rule, u_int8_t do_add) {
|
char* rule, u_int8_t do_add) {
|
||||||
|
|
||||||
char *at, *proto, *elem;
|
char *at, *proto, *elem;
|
||||||
ndpi_proto_defaults_t *def;
|
ndpi_proto_defaults_t *def;
|
||||||
int subprotocol_id, i;
|
int subprotocol_id, i;
|
||||||
@@ -2575,7 +2574,6 @@ int ndpi_handle_rule(struct ndpi_detection_module_struct *ndpi_mod, char* rule,
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
int ndpi_load_protocols_file(struct ndpi_detection_module_struct *ndpi_mod, char* path) {
|
int ndpi_load_protocols_file(struct ndpi_detection_module_struct *ndpi_mod, char* path) {
|
||||||
|
|
||||||
FILE *fd = fopen(path, "r");
|
FILE *fd = fopen(path, "r");
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@@ -4057,6 +4055,13 @@ int ndpi_enable_loaded_categories(struct ndpi_detection_module_struct *ndpi_str)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(ndpi_str->custom_categories.ipAddresses != NULL)
|
||||||
|
ndpi_Destroy_Patricia((patricia_tree_t*)ndpi_str->custom_categories.ipAddresses,
|
||||||
|
free_ptree_data);
|
||||||
|
|
||||||
|
ndpi_str->custom_categories.ipAddresses = ndpi_str->custom_categories.ipAddresses_shadow;
|
||||||
|
ndpi_str->custom_categories.ipAddresses_shadow = ndpi_New_Patricia(32 /* IPv4 */);
|
||||||
|
|
||||||
ndpi_str->custom_categories.categories_loaded = 1;
|
ndpi_str->custom_categories.categories_loaded = 1;
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user