Some optimizations during flow guess

This commit is contained in:
Luca Deri
2021-02-10 19:51:26 +01:00
parent fffff3760b
commit d99d636696
+16 -10
View File
@@ -4673,13 +4673,11 @@ uint8_t ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_str,
static int ndpi_do_guess(struct ndpi_detection_module_struct *ndpi_str, struct ndpi_flow_struct *flow, ndpi_protocol *ret) { static int ndpi_do_guess(struct ndpi_detection_module_struct *ndpi_str, struct ndpi_flow_struct *flow, ndpi_protocol *ret) {
ret->master_protocol = ret->app_protocol = NDPI_PROTOCOL_UNKNOWN, ret->category = 0; ret->master_protocol = ret->app_protocol = NDPI_PROTOCOL_UNKNOWN, ret->category = 0;
if((!flow->protocol_id_already_guessed) && (flow->packet.iphv6 || flow->packet.iph)) { if(flow->packet.iphv6 || flow->packet.iph) {
u_int16_t sport, dport; u_int16_t sport, dport;
u_int8_t protocol; u_int8_t protocol;
u_int8_t user_defined_proto; u_int8_t user_defined_proto;
flow->protocol_id_already_guessed = 1;
if(flow->packet.iphv6 != NULL) { if(flow->packet.iphv6 != NULL) {
protocol = flow->packet.iphv6->ip6_hdr.ip6_un1_nxt; protocol = flow->packet.iphv6->ip6_hdr.ip6_un1_nxt;
} else } else
@@ -4693,7 +4691,7 @@ uint8_t ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_str,
sport = dport = 0; sport = dport = 0;
/* guess protocol */ /* guess protocol */
flow->guessed_protocol_id = (int16_t) ndpi_guess_protocol_id(ndpi_str, flow, protocol, sport, dport, &user_defined_proto); flow->guessed_protocol_id = (int16_t) ndpi_guess_protocol_id(ndpi_str, flow, protocol, sport, dport, &user_defined_proto);
flow->guessed_host_protocol_id = ndpi_guess_host_protocol_id(ndpi_str, flow); flow->guessed_host_protocol_id = ndpi_guess_host_protocol_id(ndpi_str, flow);
if(ndpi_str->custom_categories.categories_loaded && flow->packet.iph) { if(ndpi_str->custom_categories.categories_loaded && flow->packet.iph) {
@@ -4706,7 +4704,9 @@ uint8_t ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_str,
/* This is a custom protocol and it has priority over everything else */ /* This is a custom protocol and it has priority over everything else */
ret->master_protocol = NDPI_PROTOCOL_UNKNOWN, ret->master_protocol = NDPI_PROTOCOL_UNKNOWN,
ret->app_protocol = flow->guessed_protocol_id ? flow->guessed_protocol_id : flow->guessed_host_protocol_id; ret->app_protocol = flow->guessed_protocol_id ? flow->guessed_protocol_id : flow->guessed_host_protocol_id;
ndpi_fill_protocol_category(ndpi_str, flow, ret);
/* The call below is useful but not necessary, so let's skip for the moment... */
// ndpi_fill_protocol_category(ndpi_str, flow, ret);
return(-1); return(-1);
} }
@@ -4719,13 +4719,13 @@ uint8_t ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_str,
*ret = ndpi_detection_giveup(ndpi_str, flow, 0, &protocol_was_guessed); *ret = ndpi_detection_giveup(ndpi_str, flow, 0, &protocol_was_guessed);
} }
ndpi_fill_protocol_category(ndpi_str, flow, ret); /* The call below is useful but not necessary, so let's skip for the moment... */
// ndpi_fill_protocol_category(ndpi_str, flow, ret);
return(-1); return(-1);
} }
} else { } else {
/* guess host protocol */ /* guess host protocol */
if(flow->packet.iph) { if(flow->packet.iph) {
flow->guessed_host_protocol_id = ndpi_guess_host_protocol_id(ndpi_str, flow); flow->guessed_host_protocol_id = ndpi_guess_host_protocol_id(ndpi_str, flow);
/* /*
@@ -4758,7 +4758,9 @@ uint8_t ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_str,
ret->master_protocol = flow->guessed_protocol_id, ret->app_protocol = flow->guessed_host_protocol_id; ret->master_protocol = flow->guessed_protocol_id, ret->app_protocol = flow->guessed_host_protocol_id;
num_calls = ndpi_check_flow_func(ndpi_str, flow, &ndpi_selection_packet); num_calls = ndpi_check_flow_func(ndpi_str, flow, &ndpi_selection_packet);
ndpi_fill_protocol_category(ndpi_str, flow, ret);
/* The call below is useful but not necessary, so let's skip for the moment... */
// ndpi_fill_protocol_category(ndpi_str, flow, ret);
return(-1); return(-1);
} }
@@ -4854,8 +4856,12 @@ uint8_t ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_str,
if(flow->packet.iphv6 != NULL) if(flow->packet.iphv6 != NULL)
ndpi_selection_packet |= NDPI_SELECTION_BITMASK_PROTOCOL_IPV6 | NDPI_SELECTION_BITMASK_PROTOCOL_IPV4_OR_IPV6; ndpi_selection_packet |= NDPI_SELECTION_BITMASK_PROTOCOL_IPV6 | NDPI_SELECTION_BITMASK_PROTOCOL_IPV4_OR_IPV6;
if(ndpi_do_guess(ndpi_str, flow, &ret) == -1) if(!flow->protocol_id_already_guessed) {
goto invalidate_ptr; flow->protocol_id_already_guessed = 1;
if(ndpi_do_guess(ndpi_str, flow, &ret) == -1)
goto invalidate_ptr;
}
num_calls = ndpi_check_flow_func(ndpi_str, flow, &ndpi_selection_packet); num_calls = ndpi_check_flow_func(ndpi_str, flow, &ndpi_selection_packet);