Implemented ndpi_process_partial_detection() API call to handle partial matches due to the nDPI specified configuration
This commit is contained in:
@@ -915,9 +915,8 @@ 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) {
|
if((!flow->detection_completed) && flow->ndpi_flow)
|
||||||
flow->detected_protocol = ndpi_detection_giveup(ndpi_thread_info[0].workflow->ndpi_struct, flow->ndpi_flow, enable_protocol_guess);
|
flow->detected_protocol = ndpi_detection_giveup(ndpi_thread_info[0].workflow->ndpi_struct, flow->ndpi_flow, enable_protocol_guess);
|
||||||
}
|
|
||||||
|
|
||||||
process_ndpi_collected_info(ndpi_thread_info[thread_id].workflow, flow);
|
process_ndpi_collected_info(ndpi_thread_info[thread_id].workflow, flow);
|
||||||
|
|
||||||
|
|||||||
+12
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* ndpi_api.h
|
* ndpi_api.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 2011-17 - ntop.org
|
* Copyright (C) 2011-19 - ntop.org
|
||||||
*
|
*
|
||||||
* This file is part of nDPI, an open source deep packet inspection
|
* This file is part of nDPI, an open source deep packet inspection
|
||||||
* library based on the OpenDPI and PACE technology by ipoque GmbH
|
* library based on the OpenDPI and PACE technology by ipoque GmbH
|
||||||
@@ -207,6 +207,17 @@ extern "C" {
|
|||||||
void ndpi_set_protocol_detection_bitmask2(struct ndpi_detection_module_struct *ndpi_struct,
|
void ndpi_set_protocol_detection_bitmask2(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
const NDPI_PROTOCOL_BITMASK * detection_bitmask);
|
const NDPI_PROTOCOL_BITMASK * detection_bitmask);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to be called to see in case of unknown match to see if there is
|
||||||
|
* a partial match that has been prevented by the current nDPI preferences configuration
|
||||||
|
*
|
||||||
|
* @par ndpi_struct = the detection module
|
||||||
|
* @par flow = the flow given for the detection module
|
||||||
|
* @return the detected protocol even if the flow is not completed;
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
ndpi_protocol ndpi_get_partial_detection(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
|
struct ndpi_flow_struct *flow);
|
||||||
/**
|
/**
|
||||||
* Function to be called before we give up with detection for a given flow.
|
* Function to be called before we give up with detection for a given flow.
|
||||||
* This function reduces the NDPI_UNKNOWN_PROTOCOL detection
|
* This function reduces the NDPI_UNKNOWN_PROTOCOL detection
|
||||||
|
|||||||
+56
-4
@@ -4165,6 +4165,52 @@ static u_int16_t ndpi_guess_host_protocol_id(struct ndpi_detection_module_struct
|
|||||||
|
|
||||||
/* ********************************************************************************* */
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
|
static ndpi_protocol ndpi_process_partial_detection(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
|
struct ndpi_flow_struct *flow) {
|
||||||
|
ndpi_protocol ret;
|
||||||
|
ndpi_protocol_match_result ret_match;
|
||||||
|
|
||||||
|
ret.master_protocol = flow->guessed_protocol_id;
|
||||||
|
ret.app_protocol = ndpi_match_host_subprotocol(ndpi_struct, flow,
|
||||||
|
(char *)flow->host_server_name,
|
||||||
|
strlen((const char*)flow->host_server_name),
|
||||||
|
&ret_match,
|
||||||
|
flow->guessed_protocol_id);
|
||||||
|
ret.category = ret_match.protocol_category;
|
||||||
|
|
||||||
|
if(ret.app_protocol == NDPI_PROTOCOL_UNKNOWN)
|
||||||
|
ret.app_protocol = ret.master_protocol;
|
||||||
|
|
||||||
|
ndpi_int_change_protocol(ndpi_struct, flow, ret.app_protocol, ret.master_protocol);
|
||||||
|
return(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
|
/*
|
||||||
|
You can call this function at any time in case of unknown match to see if there is
|
||||||
|
a partial match that has been prevented by the current nDPI preferences configuration
|
||||||
|
*/
|
||||||
|
ndpi_protocol ndpi_get_partial_detection(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
|
struct ndpi_flow_struct *flow) {
|
||||||
|
if((flow->guessed_protocol_id == NDPI_PROTOCOL_HTTP)
|
||||||
|
&& (ndpi_struct->http_dont_dissect_response == 0)
|
||||||
|
&& (flow->host_server_name[0] != '\0')
|
||||||
|
&& (!NDPI_ISSET(&flow->excluded_protocol_bitmask, flow->guessed_host_protocol_id)))
|
||||||
|
return(ndpi_process_partial_detection(ndpi_struct, flow));
|
||||||
|
else if((flow->guessed_protocol_id == NDPI_PROTOCOL_DNS)
|
||||||
|
&& (ndpi_struct->dns_dont_dissect_response == 0)
|
||||||
|
&& (flow->host_server_name[0] != '\0')
|
||||||
|
&& (!NDPI_ISSET(&flow->excluded_protocol_bitmask, flow->guessed_host_protocol_id)))
|
||||||
|
return(ndpi_process_partial_detection(ndpi_struct, flow));
|
||||||
|
else {
|
||||||
|
ndpi_protocol ret = { NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_CATEGORY_UNSPECIFIED };
|
||||||
|
return(ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
ndpi_protocol ndpi_detection_giveup(struct ndpi_detection_module_struct *ndpi_struct,
|
ndpi_protocol ndpi_detection_giveup(struct ndpi_detection_module_struct *ndpi_struct,
|
||||||
struct ndpi_flow_struct *flow, u_int8_t enable_guess) {
|
struct ndpi_flow_struct *flow, u_int8_t enable_guess) {
|
||||||
ndpi_protocol ret = { NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_CATEGORY_UNSPECIFIED };
|
ndpi_protocol ret = { NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_CATEGORY_UNSPECIFIED };
|
||||||
@@ -4177,11 +4223,18 @@ ndpi_protocol ndpi_detection_giveup(struct ndpi_detection_module_struct *ndpi_st
|
|||||||
|
|
||||||
if(flow->guessed_protocol_id == NDPI_PROTOCOL_STUN)
|
if(flow->guessed_protocol_id == NDPI_PROTOCOL_STUN)
|
||||||
goto check_stun_export;
|
goto check_stun_export;
|
||||||
else if((flow->l4.tcp.ssl_seen_client_cert == 1) && (flow->protos.stun_ssl.ssl.client_certificate[0] != '\0')) {
|
else if((flow->l4.tcp.ssl_seen_client_cert == 1)
|
||||||
|
&& (flow->protos.stun_ssl.ssl.client_certificate[0] != '\0')) {
|
||||||
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_SSL, NDPI_PROTOCOL_UNKNOWN);
|
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_SSL, NDPI_PROTOCOL_UNKNOWN);
|
||||||
} else {
|
} else {
|
||||||
if(!enable_guess)
|
ndpi_protocol ret_g = ndpi_get_partial_detection(ndpi_struct, flow);
|
||||||
return(ret);
|
|
||||||
|
if(ret_g.master_protocol != NDPI_PROTOCOL_UNKNOWN)
|
||||||
|
return(ret_g);
|
||||||
|
else {
|
||||||
|
if(!enable_guess)
|
||||||
|
return(ret);
|
||||||
|
}
|
||||||
|
|
||||||
if((flow->guessed_protocol_id == NDPI_PROTOCOL_UNKNOWN)
|
if((flow->guessed_protocol_id == NDPI_PROTOCOL_UNKNOWN)
|
||||||
&& (flow->packet.l4_protocol == IPPROTO_TCP)
|
&& (flow->packet.l4_protocol == IPPROTO_TCP)
|
||||||
@@ -4207,7 +4260,6 @@ ndpi_protocol ndpi_detection_giveup(struct ndpi_detection_module_struct *ndpi_st
|
|||||||
|
|
||||||
if((guessed_protocol_id != NDPI_PROTOCOL_UNKNOWN)
|
if((guessed_protocol_id != NDPI_PROTOCOL_UNKNOWN)
|
||||||
|| (guessed_host_protocol_id != NDPI_PROTOCOL_UNKNOWN)) {
|
|| (guessed_host_protocol_id != NDPI_PROTOCOL_UNKNOWN)) {
|
||||||
|
|
||||||
if((guessed_protocol_id == 0)
|
if((guessed_protocol_id == 0)
|
||||||
&& (flow->protos.stun_ssl.stun.num_binding_requests > 0)
|
&& (flow->protos.stun_ssl.stun.num_binding_requests > 0)
|
||||||
&& (flow->protos.stun_ssl.stun.num_processed_pkts > 0))
|
&& (flow->protos.stun_ssl.stun.num_processed_pkts > 0))
|
||||||
|
|||||||
@@ -153,8 +153,10 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
|
|||||||
|| ((dns_header.authority_rrs > 0) && (dns_header.authority_rrs <= NDPI_MAX_DNS_REQUESTS))
|
|| ((dns_header.authority_rrs > 0) && (dns_header.authority_rrs <= NDPI_MAX_DNS_REQUESTS))
|
||||||
|| ((dns_header.additional_rrs > 0) && (dns_header.additional_rrs <= NDPI_MAX_DNS_REQUESTS)))
|
|| ((dns_header.additional_rrs > 0) && (dns_header.additional_rrs <= NDPI_MAX_DNS_REQUESTS)))
|
||||||
) {
|
) {
|
||||||
/* This is a good reply */
|
/* This is a good reply: we dissect it both for request and response */
|
||||||
if(ndpi_struct->dns_dont_dissect_response == 0) {
|
|
||||||
|
/* Leave the statement below commented necessary in case of call to ndpi_get_partial_detection() */
|
||||||
|
/* if(ndpi_struct->dns_dont_dissect_response == 0) */ {
|
||||||
x++;
|
x++;
|
||||||
|
|
||||||
if(flow->packet.payload[x] != '\0') {
|
if(flow->packet.payload[x] != '\0') {
|
||||||
|
|||||||
@@ -157,7 +157,9 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(!ndpi_struct->http_dont_dissect_response) {
|
/* Leave the statement below commented necessary in case of call to ndpi_get_partial_detection() */
|
||||||
|
|
||||||
|
/* if(!ndpi_struct->http_dont_dissect_response) */ {
|
||||||
if((flow->http.url == NULL)
|
if((flow->http.url == NULL)
|
||||||
&& (packet->http_url_name.len > 0)
|
&& (packet->http_url_name.len > 0)
|
||||||
&& (packet->host_line.len > 0)) {
|
&& (packet->host_line.len > 0)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user