Added new ndpi_detection_giveup() API call to call before giving up for a given flow
Code cleanup
This commit is contained in:
@@ -653,6 +653,9 @@ static void node_proto_guess_walker(const void *node, ndpi_VISIT which, int dept
|
|||||||
u_int16_t thread_id = *((u_int16_t *) user_data);
|
u_int16_t thread_id = *((u_int16_t *) user_data);
|
||||||
|
|
||||||
if((which == ndpi_preorder) || (which == ndpi_leaf)) { /* Avoid walking the same node multiple times */
|
if((which == ndpi_preorder) || (which == ndpi_leaf)) { /* Avoid walking the same node multiple times */
|
||||||
|
if((!flow->detection_completed) && flow->ndpi_flow)
|
||||||
|
flow->detected_protocol = ndpi_detection_giveup(ndpi_thread_info[0].ndpi_struct, flow->ndpi_flow);
|
||||||
|
|
||||||
if(enable_protocol_guess) {
|
if(enable_protocol_guess) {
|
||||||
if(flow->detected_protocol.protocol == NDPI_PROTOCOL_UNKNOWN) {
|
if(flow->detected_protocol.protocol == NDPI_PROTOCOL_UNKNOWN) {
|
||||||
node_guess_undetected_protocol(thread_id, flow);
|
node_guess_undetected_protocol(thread_id, flow);
|
||||||
|
|||||||
@@ -116,7 +116,14 @@ extern "C" {
|
|||||||
void
|
void
|
||||||
ndpi_set_protocol_detection_bitmask2(struct ndpi_detection_module_struct *ndpi_struct,
|
ndpi_set_protocol_detection_bitmask2(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
const NDPI_PROTOCOL_BITMASK * detection_bitmask);
|
const NDPI_PROTOCOL_BITMASK * detection_bitmask);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This function has to be called before we give up with detection for a given flow
|
||||||
|
*/
|
||||||
|
ndpi_protocol ndpi_detection_giveup(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
|
struct ndpi_flow_struct *flow);
|
||||||
|
|
||||||
|
/**
|
||||||
* This function will processes one packet and returns the ID of the detected protocol.
|
* This function will processes one packet and returns the ID of the detected protocol.
|
||||||
* This is the main packet processing function.
|
* This is the main packet processing function.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -861,7 +861,7 @@ struct ndpi_flow_struct {
|
|||||||
u_int16_t protocol_stack_info;
|
u_int16_t protocol_stack_info;
|
||||||
|
|
||||||
/* init parameter, internal used to set up timestamp,... */
|
/* init parameter, internal used to set up timestamp,... */
|
||||||
u_int16_t guessed_protocol_id, guessed_host_proto_id;
|
u_int16_t guessed_protocol_id, guessed_host_protocol_id;
|
||||||
|
|
||||||
u_int8_t protocol_id_already_guessed:1, host_already_guessed:1, init_finished:1, setup_packet_direction:1, packet_direction:1;
|
u_int8_t protocol_id_already_guessed:1, host_already_guessed:1, init_finished:1, setup_packet_direction:1, packet_direction:1;
|
||||||
|
|
||||||
|
|||||||
+22
-34
@@ -3156,11 +3156,6 @@ ndpi_protocol ndpi_l4_detection_process_packet(struct ndpi_detection_module_stru
|
|||||||
|
|
||||||
if(flow->packet.payload_packet_len != 0) {
|
if(flow->packet.payload_packet_len != 0) {
|
||||||
ndpi_selection_packet |= NDPI_SELECTION_BITMASK_PROTOCOL_HAS_PAYLOAD;
|
ndpi_selection_packet |= NDPI_SELECTION_BITMASK_PROTOCOL_HAS_PAYLOAD;
|
||||||
|
|
||||||
if(!flow->protocol_id_already_guessed) {
|
|
||||||
flow->guessed_protocol_id = (int16_t)ndpi_guess_protocol_id(ndpi_struct, l4_proto, sport, dport);
|
|
||||||
flow->protocol_id_already_guessed = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(flow->packet.tcp_retransmission == 0)
|
if(flow->packet.tcp_retransmission == 0)
|
||||||
@@ -3192,21 +3187,27 @@ ndpi_protocol ndpi_l4_detection_process_packet(struct ndpi_detection_module_stru
|
|||||||
} else
|
} else
|
||||||
ret.protocol = flow->detected_protocol_stack[0];
|
ret.protocol = flow->detected_protocol_stack[0];
|
||||||
|
|
||||||
if((ret.protocol == NDPI_PROTOCOL_UNKNOWN)
|
return(ret);
|
||||||
&& flow->packet.iph
|
}
|
||||||
&& (!flow->host_already_guessed)) {
|
|
||||||
|
|
||||||
if((flow->guessed_host_proto_id = ndpi_network_ptree_match(ndpi_struct,
|
/* ********************************************************************************* */
|
||||||
(struct in_addr *)&flow->packet.iph->saddr)) == NDPI_PROTOCOL_UNKNOWN) {
|
|
||||||
flow->guessed_host_proto_id = ndpi_network_ptree_match(ndpi_struct, (struct in_addr *)&flow->packet.iph->daddr);
|
ndpi_protocol ndpi_detection_giveup(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
|
struct ndpi_flow_struct *flow) {
|
||||||
|
ndpi_protocol ret = { NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_UNKNOWN };
|
||||||
|
|
||||||
|
if(flow->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN) {
|
||||||
|
if(flow->http_detected)
|
||||||
|
ndpi_int_change_protocol(ndpi_struct, flow, NDPI_PROTOCOL_HTTP, NDPI_PROTOCOL_UNKNOWN);
|
||||||
|
else {
|
||||||
|
flow->detected_protocol_stack[1] = flow->guessed_protocol_id, flow->detected_protocol_stack[0] = flow->guessed_host_protocol_id;
|
||||||
|
|
||||||
|
if(flow->detected_protocol_stack[1] == flow->detected_protocol_stack[0])
|
||||||
|
flow->detected_protocol_stack[1] = NDPI_PROTOCOL_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
flow->host_already_guessed = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if((ret.protocol == NDPI_PROTOCOL_UNKNOWN) && (ret.master_protocol != NDPI_PROTOCOL_UNKNOWN))
|
ret.master_protocol = flow->detected_protocol_stack[1], ret.protocol = flow->detected_protocol_stack[0];
|
||||||
ret.protocol = flow->guessed_host_proto_id;
|
|
||||||
|
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3288,6 +3289,8 @@ ndpi_protocol ndpi_detection_process_packet(struct ndpi_detection_module_struct
|
|||||||
u_int8_t protocol;
|
u_int8_t protocol;
|
||||||
u_int32_t saddr, daddr;
|
u_int32_t saddr, daddr;
|
||||||
|
|
||||||
|
flow->protocol_id_already_guessed = 1;
|
||||||
|
|
||||||
#ifdef NDPI_DETECTION_SUPPORT_IPV6
|
#ifdef NDPI_DETECTION_SUPPORT_IPV6
|
||||||
if(flow->packet.iphv6 != NULL) {
|
if(flow->packet.iphv6 != NULL) {
|
||||||
protocol = flow->packet.iphv6->ip6_ctlun.ip6_un1.ip6_un1_nxt, saddr = 0, daddr = 0;
|
protocol = flow->packet.iphv6->ip6_ctlun.ip6_un1.ip6_un1_nxt, saddr = 0, daddr = 0;
|
||||||
@@ -3304,11 +3307,10 @@ ndpi_protocol ndpi_detection_process_packet(struct ndpi_detection_module_struct
|
|||||||
else sport = dport = 0;
|
else sport = dport = 0;
|
||||||
|
|
||||||
flow->guessed_protocol_id = (int16_t)ndpi_guess_protocol_id(ndpi_struct, protocol, sport, dport);
|
flow->guessed_protocol_id = (int16_t)ndpi_guess_protocol_id(ndpi_struct, protocol, sport, dport);
|
||||||
flow->protocol_id_already_guessed = 1;
|
|
||||||
|
|
||||||
if((protocol != IPPROTO_TCP) && (protocol != IPPROTO_UDP)) {
|
if(flow->packet.iph) {
|
||||||
flow->detected_protocol_stack[0] = flow->guessed_protocol_id;
|
if((flow->guessed_host_protocol_id = ndpi_network_ptree_match(ndpi_struct, (struct in_addr *)&flow->packet.iph->saddr)) == NDPI_PROTOCOL_UNKNOWN)
|
||||||
goto ret_protocols;
|
flow->guessed_host_protocol_id = ndpi_network_ptree_match(ndpi_struct, (struct in_addr *)&flow->packet.iph->daddr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3336,20 +3338,6 @@ ndpi_protocol ndpi_detection_process_packet(struct ndpi_detection_module_struct
|
|||||||
} else
|
} else
|
||||||
ret.protocol = flow->detected_protocol_stack[0];
|
ret.protocol = flow->detected_protocol_stack[0];
|
||||||
|
|
||||||
if((ret.protocol == NDPI_PROTOCOL_UNKNOWN)
|
|
||||||
&& flow->packet.iph
|
|
||||||
&& (!flow->host_already_guessed)) {
|
|
||||||
|
|
||||||
if((flow->guessed_host_proto_id = ndpi_network_ptree_match(ndpi_struct, (struct in_addr *)&flow->packet.iph->saddr)) == NDPI_PROTOCOL_UNKNOWN) {
|
|
||||||
flow->guessed_host_proto_id = ndpi_network_ptree_match(ndpi_struct, (struct in_addr *)&flow->packet.iph->daddr);
|
|
||||||
}
|
|
||||||
|
|
||||||
flow->host_already_guessed = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if((ret.protocol == NDPI_PROTOCOL_UNKNOWN) && (ret.master_protocol != NDPI_PROTOCOL_UNKNOWN))
|
|
||||||
ret.protocol = flow->guessed_host_proto_id;
|
|
||||||
|
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user