Minor changes in ndpi_detection_giveup() (#1861)
Check the mining cache at the end of the function, like all the others LRU caches. Rewrite the STUN checks: same identical semantic but in a cleaner way, hopefully
This commit is contained in:
+39
-51
@@ -6000,6 +6000,7 @@ static void ndpi_add_connection_as_zoom(struct ndpi_detection_module_struct *ndp
|
||||
ndpi_protocol ndpi_detection_giveup(struct ndpi_detection_module_struct *ndpi_str, struct ndpi_flow_struct *flow,
|
||||
u_int8_t enable_guess, u_int8_t *protocol_was_guessed) {
|
||||
ndpi_protocol ret = NDPI_PROTOCOL_NULL;
|
||||
u_int16_t cached_proto;
|
||||
|
||||
/* *** We can't access ndpi_str->packet from this function!! *** */
|
||||
|
||||
@@ -6009,7 +6010,8 @@ ndpi_protocol ndpi_detection_giveup(struct ndpi_detection_module_struct *ndpi_st
|
||||
return(ret);
|
||||
|
||||
/* Init defaults */
|
||||
ret.master_protocol = flow->detected_protocol_stack[1], ret.app_protocol = flow->detected_protocol_stack[0];
|
||||
ret.master_protocol = flow->detected_protocol_stack[1];
|
||||
ret.app_protocol = flow->detected_protocol_stack[0];
|
||||
ret.protocol_by_ip = flow->guessed_protocol_id_by_ip;
|
||||
ret.category = flow->category;
|
||||
|
||||
@@ -6017,60 +6019,46 @@ ndpi_protocol ndpi_detection_giveup(struct ndpi_detection_module_struct *ndpi_st
|
||||
if(ret.app_protocol != NDPI_PROTOCOL_UNKNOWN)
|
||||
return(ret);
|
||||
|
||||
/* TODO: this lookup seems in the wrong place here...
|
||||
Move it somewhere else (?) or setting flow->guessed_protocol_id directly in the mining dissector? */
|
||||
if(ndpi_str->mining_cache) {
|
||||
u_int16_t cached_proto;
|
||||
|
||||
if(ndpi_lru_find_cache(ndpi_str->mining_cache, make_mining_key(flow),
|
||||
&cached_proto, 0 /* Don't remove it as it can be used for other connections */,
|
||||
ndpi_get_current_time(flow))) {
|
||||
ndpi_set_detected_protocol(ndpi_str, flow, cached_proto, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI_PARTIAL_CACHE);
|
||||
ret.master_protocol = flow->detected_protocol_stack[1], ret.app_protocol = flow->detected_protocol_stack[0];
|
||||
ndpi_fill_protocol_category(ndpi_str, flow, &ret);
|
||||
return(ret);
|
||||
}
|
||||
}
|
||||
|
||||
if(flow->guessed_protocol_id == NDPI_PROTOCOL_STUN)
|
||||
goto check_stun_export;
|
||||
else if(enable_guess) {
|
||||
if(flow->stun.num_binding_requests > 0 &&
|
||||
flow->stun.num_processed_pkts > 0) {
|
||||
*protocol_was_guessed = 1;
|
||||
ndpi_set_detected_protocol(ndpi_str, flow, NDPI_PROTOCOL_STUN, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI_PARTIAL);
|
||||
}
|
||||
}
|
||||
|
||||
if((flow->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN) &&
|
||||
(flow->guessed_protocol_id == NDPI_PROTOCOL_STUN)) {
|
||||
check_stun_export:
|
||||
*protocol_was_guessed = 1;
|
||||
if((flow->guessed_protocol_id == NDPI_PROTOCOL_STUN) ||
|
||||
(enable_guess &&
|
||||
flow->stun.num_binding_requests > 0 &&
|
||||
flow->stun.num_processed_pkts > 0)) {
|
||||
ndpi_set_detected_protocol(ndpi_str, flow, NDPI_PROTOCOL_STUN, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI_PARTIAL);
|
||||
ret.app_protocol = flow->detected_protocol_stack[0];
|
||||
}
|
||||
|
||||
ret.master_protocol = flow->detected_protocol_stack[1], ret.app_protocol = flow->detected_protocol_stack[0];
|
||||
/* Check some caches */
|
||||
|
||||
if((ret.master_protocol == NDPI_PROTOCOL_UNKNOWN)
|
||||
&& (ret.app_protocol == NDPI_PROTOCOL_UNKNOWN)) {
|
||||
/* Check some caches */
|
||||
if(ndpi_search_into_bittorrent_cache(ndpi_str, flow,
|
||||
flow->c_address.v4, flow->c_port,
|
||||
flow->s_address.v4, flow->s_port)) {
|
||||
/* This looks like BitTorrent */
|
||||
ndpi_set_detected_protocol(ndpi_str, flow, NDPI_PROTOCOL_BITTORRENT, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI_PARTIAL_CACHE);
|
||||
ret.app_protocol = NDPI_PROTOCOL_BITTORRENT;
|
||||
} else if((flow->l4_proto == IPPROTO_UDP) && /* Zoom/UDP used for video */
|
||||
((ntohs(flow->s_port) == 8801 && ndpi_search_into_zoom_cache(ndpi_str, flow, 1)) ||
|
||||
(ntohs(flow->c_port) == 8801 && ndpi_search_into_zoom_cache(ndpi_str, flow, 0)))) {
|
||||
/* This looks like Zoom */
|
||||
ndpi_set_detected_protocol(ndpi_str, flow, NDPI_PROTOCOL_ZOOM, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI_PARTIAL_CACHE);
|
||||
ret.app_protocol = NDPI_PROTOCOL_ZOOM;
|
||||
} else if(stun_search_into_zoom_cache(ndpi_str, flow)) {
|
||||
/* This looks like Zoom */
|
||||
ndpi_set_detected_protocol(ndpi_str, flow, NDPI_PROTOCOL_ZOOM, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI_PARTIAL_CACHE);
|
||||
ret.app_protocol = flow->detected_protocol_stack[0];
|
||||
}
|
||||
/* Does it looks like BitTorrent? */
|
||||
if(ret.app_protocol == NDPI_PROTOCOL_UNKNOWN &&
|
||||
ndpi_search_into_bittorrent_cache(ndpi_str, flow,
|
||||
flow->c_address.v4, flow->c_port,
|
||||
flow->s_address.v4, flow->s_port)) {
|
||||
ndpi_set_detected_protocol(ndpi_str, flow, NDPI_PROTOCOL_BITTORRENT, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI_PARTIAL_CACHE);
|
||||
ret.app_protocol = flow->detected_protocol_stack[0];
|
||||
}
|
||||
/* Does it looks like some Mining protocols? */
|
||||
if(ret.app_protocol == NDPI_PROTOCOL_UNKNOWN &&
|
||||
ndpi_str->mining_cache &&
|
||||
ndpi_lru_find_cache(ndpi_str->mining_cache, make_mining_key(flow),
|
||||
&cached_proto, 0 /* Don't remove it as it can be used for other connections */,
|
||||
ndpi_get_current_time(flow))) {
|
||||
ndpi_set_detected_protocol(ndpi_str, flow, cached_proto, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI_PARTIAL_CACHE);
|
||||
ret.app_protocol = flow->detected_protocol_stack[0];
|
||||
}
|
||||
/* Does it looks like Zoom? */
|
||||
if(ret.app_protocol == NDPI_PROTOCOL_UNKNOWN &&
|
||||
flow->l4_proto == IPPROTO_UDP && /* Zoom/UDP used for video */
|
||||
((ntohs(flow->s_port) == 8801 && ndpi_search_into_zoom_cache(ndpi_str, flow, 1)) ||
|
||||
(ntohs(flow->c_port) == 8801 && ndpi_search_into_zoom_cache(ndpi_str, flow, 0)))) {
|
||||
ndpi_set_detected_protocol(ndpi_str, flow, NDPI_PROTOCOL_ZOOM, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI_PARTIAL_CACHE);
|
||||
ret.app_protocol = flow->detected_protocol_stack[0];
|
||||
}
|
||||
/* Does it looks like Zoom (via STUN)? */
|
||||
if(ret.app_protocol == NDPI_PROTOCOL_UNKNOWN &&
|
||||
stun_search_into_zoom_cache(ndpi_str, flow)) {
|
||||
ndpi_set_detected_protocol(ndpi_str, flow, NDPI_PROTOCOL_ZOOM, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI_PARTIAL_CACHE);
|
||||
ret.app_protocol = flow->detected_protocol_stack[0];
|
||||
}
|
||||
|
||||
/* Classification by-port is the last resort */
|
||||
|
||||
@@ -10,7 +10,7 @@ LRU cache bittorrent: 0/24/0 (insert/search/found)
|
||||
LRU cache zoom: 0/0/0 (insert/search/found)
|
||||
LRU cache stun: 6/164/24 (insert/search/found)
|
||||
LRU cache tls_cert: 0/0/0 (insert/search/found)
|
||||
LRU cache mining: 0/1/0 (insert/search/found)
|
||||
LRU cache mining: 0/0/0 (insert/search/found)
|
||||
LRU cache msteams: 0/0/0 (insert/search/found)
|
||||
LRU cache stun_zoom: 0/0/0 (insert/search/found)
|
||||
Automa host: 0/0 (search/found)
|
||||
|
||||
@@ -13,7 +13,7 @@ LRU cache bittorrent: 0/9/0 (insert/search/found)
|
||||
LRU cache zoom: 0/0/0 (insert/search/found)
|
||||
LRU cache stun: 6/42/18 (insert/search/found)
|
||||
LRU cache tls_cert: 0/8/0 (insert/search/found)
|
||||
LRU cache mining: 0/4/0 (insert/search/found)
|
||||
LRU cache mining: 0/3/0 (insert/search/found)
|
||||
LRU cache msteams: 24/13/9 (insert/search/found)
|
||||
LRU cache stun_zoom: 0/0/0 (insert/search/found)
|
||||
Automa host: 85/71 (search/found)
|
||||
|
||||
Reference in New Issue
Block a user