Added ndpi_extra_dissection_possible() API call

This commit is contained in:
Luca Deri
2019-09-26 23:50:02 +02:00
parent 194cdcf581
commit 17f560a1cd
3 changed files with 186 additions and 131 deletions
+2 -1
View File
@@ -807,7 +807,8 @@ extern "C" {
int ndpi_flowv6_flow_hash(u_int8_t l4_proto, struct ndpi_in6_addr *src_ip, struct ndpi_in6_addr *dst_ip, int ndpi_flowv6_flow_hash(u_int8_t l4_proto, struct ndpi_in6_addr *src_ip, struct ndpi_in6_addr *dst_ip,
u_int16_t src_port, u_int16_t dst_port, u_int8_t icmp_type, u_int8_t icmp_code, u_int16_t src_port, u_int16_t dst_port, u_int8_t icmp_type, u_int8_t icmp_code,
u_char *hash_buf, u_int8_t hash_buf_len); u_char *hash_buf, u_int8_t hash_buf_len);
u_int8_t ndpi_extra_dissection_possible(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow);
u_int8_t ndpi_is_safe_ssl_cipher(u_int32_t cipher); u_int8_t ndpi_is_safe_ssl_cipher(u_int32_t cipher);
const char* ndpi_cipher2str(u_int32_t cipher); const char* ndpi_cipher2str(u_int32_t cipher);
u_int16_t ndpi_guess_host_protocol_id(struct ndpi_detection_module_struct *ndpi_struct, u_int16_t ndpi_guess_host_protocol_id(struct ndpi_detection_module_struct *ndpi_struct,
+40 -1
View File
@@ -6288,4 +6288,43 @@ int ndpi_flowv6_flow_hash(u_int8_t l4_proto, struct ndpi_in6_addr *src_ip, struc
return(0); /* OK */ return(0); /* OK */
} }
/* **************************************** */ /* ******************************************************************** */
/*
This function tells if it's possible to further dissect a given flow
0 - All possible dissection has been completed
1 - Additional dissection is possible
*/
u_int8_t ndpi_extra_dissection_possible(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
#if 0
printf("[DEBUG] %s(%u.%u)\n", __FUNCTION__,
flow->detected_protocol_stack[0],
flow->detected_protocol_stack[1]);
#endif
if(flow->check_extra_packets) return(1);
switch(flow->detected_protocol_stack[0]) {
case NDPI_PROTOCOL_TLS:
if(!flow->l4.tcp.tls_srv_cert_fingerprint_processed)
return(1);
break;
case NDPI_PROTOCOL_HTTP:
if(flow->host_server_name[0] == '\0')
return(1);
break;
case NDPI_PROTOCOL_DNS:
if((ndpi_struct->dns_dont_dissect_response == 0)
&& (flow->host_server_name[0] == '\0'))
return(1);
break;
}
return(0);
}
/* ******************************************************************** */
+21 -6
View File
@@ -30,7 +30,7 @@
#define FLAGS_MASK 0x8000 #define FLAGS_MASK 0x8000
/* #define DNS_DEBUG 1 */ // #define DNS_DEBUG 1
/* *********************************************** */ /* *********************************************** */
@@ -75,16 +75,21 @@ static uint32_t dns_validchar[8] = {
/* *********************************************** */ /* *********************************************** */
static int search_valid_dns(struct ndpi_flow_struct *flow, struct ndpi_dns_packet_header *dns_header, int payload_offset, u_int8_t*is_query) { static int search_valid_dns(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
struct ndpi_dns_packet_header *dns_header,
int payload_offset, u_int8_t *is_query) {
int x = payload_offset; int x = payload_offset;
memcpy(dns_header, (struct ndpi_dns_packet_header*) &flow->packet.payload[x], sizeof(struct ndpi_dns_packet_header)); memcpy(dns_header, (struct ndpi_dns_packet_header*)&flow->packet.payload[x],
sizeof(struct ndpi_dns_packet_header));
dns_header->tr_id = ntohs(dns_header->tr_id); dns_header->tr_id = ntohs(dns_header->tr_id);
dns_header->flags = ntohs(dns_header->flags); dns_header->flags = ntohs(dns_header->flags);
dns_header->num_queries = ntohs(dns_header->num_queries); dns_header->num_queries = ntohs(dns_header->num_queries);
dns_header->num_answers = ntohs(dns_header->num_answers); dns_header->num_answers = ntohs(dns_header->num_answers);
dns_header->authority_rrs = ntohs(dns_header->authority_rrs); dns_header->authority_rrs = ntohs(dns_header->authority_rrs);
dns_header->additional_rrs = ntohs(dns_header->additional_rrs); dns_header->additional_rrs = ntohs(dns_header->additional_rrs);
x += sizeof(struct ndpi_dns_packet_header); x += sizeof(struct ndpi_dns_packet_header);
/* 0x0000 QUERY */ /* 0x0000 QUERY */
@@ -108,7 +113,12 @@ static int search_valid_dns(struct ndpi_flow_struct *flow, struct ndpi_dns_packe
flow->protos.dns.query_type = get16(&x, flow->packet.payload); flow->protos.dns.query_type = get16(&x, flow->packet.payload);
#ifdef DNS_DEBUG #ifdef DNS_DEBUG
NDPI_LOG_DBG2(ndpi_struct, "query_type=%2d\n", flow->protos.dns.query_type); NDPI_LOG_DBG2(ndpi_struct, "query_type=%2d\n", flow->protos.dns.query_type);
printf("[DNS] query_type=%d\n", flow->protos.dns.query_type);
#endif #endif
if(ndpi_struct->dns_dont_dissect_response)
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DNS, NDPI_PROTOCOL_UNKNOWN);
break; break;
} else } else
x++; x++;
@@ -195,6 +205,7 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
u_int16_t s_port = 0, d_port = 0; u_int16_t s_port = 0, d_port = 0;
NDPI_LOG_DBG(ndpi_struct, "search DNS\n"); NDPI_LOG_DBG(ndpi_struct, "search DNS\n");
if(flow->packet.udp != NULL) { if(flow->packet.udp != NULL) {
s_port = ntohs(flow->packet.udp->source); s_port = ntohs(flow->packet.udp->source);
d_port = ntohs(flow->packet.udp->dest); d_port = ntohs(flow->packet.udp->dest);
@@ -212,7 +223,7 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
&& (flow->packet.payload_packet_len > sizeof(struct ndpi_dns_packet_header)+payload_offset)) { && (flow->packet.payload_packet_len > sizeof(struct ndpi_dns_packet_header)+payload_offset)) {
struct ndpi_dns_packet_header dns_header; struct ndpi_dns_packet_header dns_header;
int j = 0, max_len, off; int j = 0, max_len, off;
int invalid = search_valid_dns(flow, &dns_header, payload_offset, &is_query); int invalid = search_valid_dns(ndpi_struct, flow, &dns_header, payload_offset, &is_query);
if(invalid) { if(invalid) {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
@@ -275,13 +286,17 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
NDPI_LOG_INFO(ndpi_struct, "found DNS\n"); NDPI_LOG_INFO(ndpi_struct, "found DNS\n");
ndpi_set_detected_protocol(ndpi_struct, flow, (d_port == 5355) ? NDPI_PROTOCOL_LLMNR : NDPI_PROTOCOL_DNS, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, (d_port == 5355) ? NDPI_PROTOCOL_LLMNR : NDPI_PROTOCOL_DNS, NDPI_PROTOCOL_UNKNOWN);
} else { } else {
if((flow->packet.detected_protocol_stack[0] == NDPI_PROTOCOL_DNS)
|| (flow->packet.detected_protocol_stack[1] == NDPI_PROTOCOL_DNS))
;
else
NDPI_EXCLUDE_PROTO(ndpi_struct, flow); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} }
} }
} }
void init_dns_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) void init_dns_dissector(struct ndpi_detection_module_struct *ndpi_struct,
{ u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) {
ndpi_set_bitmask_protocol_detection("DNS", ndpi_struct, detection_bitmask, *id, ndpi_set_bitmask_protocol_detection("DNS", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_DNS, NDPI_PROTOCOL_DNS,
ndpi_search_dns, ndpi_search_dns,