From dd4807f8ee66d2e4ff81ec43481943c4d17fb574 Mon Sep 17 00:00:00 2001 From: Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> Date: Fri, 31 Jan 2025 17:42:47 +0100 Subject: bittorrent: add configuration for "hash" metadata (#2706) Fix confidence value for same TCP flows --- src/include/ndpi_private.h | 2 ++ src/lib/ndpi_main.c | 3 +++ src/lib/protocols/bittorrent.c | 8 ++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/include/ndpi_private.h b/src/include/ndpi_private.h index fc422f630..85fa162a5 100644 --- a/src/include/ndpi_private.h +++ b/src/include/ndpi_private.h @@ -285,6 +285,8 @@ struct ndpi_detection_module_config_struct { int stun_relayed_address_enabled; int stun_peer_address_enabled; + int bittorrent_hash_enabled; + int dns_subclassification_enabled; int dns_parse_response_enabled; diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index 105d3a434..f3104a9a8 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -11635,6 +11635,9 @@ static const struct cfg_param { { "stun", "metadata.attribute.relayed_address", "enable", NULL, NULL, CFG_PARAM_ENABLE_DISABLE, __OFF(stun_relayed_address_enabled), NULL }, { "stun", "metadata.attribute.peer_address", "enable", NULL, NULL, CFG_PARAM_ENABLE_DISABLE, __OFF(stun_peer_address_enabled), NULL }, + { "bittorrent", "metadata.hash", "enable", NULL, NULL, CFG_PARAM_ENABLE_DISABLE, __OFF(bittorrent_hash_enabled), NULL }, + + { "dns", "subclassification", "enable", NULL, NULL, CFG_PARAM_ENABLE_DISABLE, __OFF(dns_subclassification_enabled), NULL }, { "dns", "process_response", "enable", NULL, NULL, CFG_PARAM_ENABLE_DISABLE, __OFF(dns_parse_response_enabled), NULL }, diff --git a/src/lib/protocols/bittorrent.c b/src/lib/protocols/bittorrent.c index 01080906f..2b20e5884 100644 --- a/src/lib/protocols/bittorrent.c +++ b/src/lib/protocols/bittorrent.c @@ -184,13 +184,15 @@ static void ndpi_add_connection_as_bittorrent(struct ndpi_detection_module_struc struct ndpi_flow_struct *flow, int bt_offset, int check_hash, ndpi_confidence_t confidence) { - if(check_hash) + if(ndpi_struct->cfg.bittorrent_hash_enabled && + check_hash) ndpi_search_bittorrent_hash(ndpi_struct, flow, bt_offset); ndpi_set_detected_protocol_keeping_master(ndpi_struct, flow, NDPI_PROTOCOL_BITTORRENT, confidence); - if(flow->protos.bittorrent.hash[0] == '\0') { + if(ndpi_struct->cfg.bittorrent_hash_enabled && + flow->protos.bittorrent.hash[0] == '\0') { /* Don't use just 1 as in TCP DNS more packets could be returned (e.g. ACK). */ flow->max_extra_packets_to_check = 3; flow->extra_packets_func = search_bittorrent_again; @@ -511,6 +513,8 @@ static u_int8_t is_port(u_int16_t a, u_int16_t b, u_int16_t what) { static void ndpi_skip_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { + if(flow->detected_protocol_stack[0] == NDPI_PROTOCOL_BITTORRENT) + return; if(search_into_bittorrent_cache(ndpi_struct, flow)) ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 0, NDPI_CONFIDENCE_DPI_CACHE); else -- cgit v1.2.3