From 0a47f745cc87f967f0d8513b4178321e21a02efc Mon Sep 17 00:00:00 2001 From: Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> Date: Mon, 5 Sep 2022 13:59:51 +0200 Subject: Avoid useless host automa lookup (#1724) The host automa is used for two tasks: * protocol sub-classification (obviously); * DGA evaluation: the idea is that if a domain is present in this automa, it can't be a DGA, regardless of its format/name. In most dissectors both checks are executed, i.e. the code is something like: ``` ndpi_match_host_subprotocol(..., flow->host_server_name, ...); ndpi_check_dga_name(..., flow->host_server_name,...); ``` In that common case, we can perform only one automa lookup: if we check the sub-classification before the DGA, we can avoid the second lookup in the DGA function itself. --- src/lib/ndpi_main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/lib/ndpi_main.c') diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index fed529297..1f47daa7c 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -8511,7 +8511,7 @@ static int ndpi_is_vowel(char c) { int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str, struct ndpi_flow_struct *flow, - char *name, u_int8_t is_hostname) { + char *name, u_int8_t is_hostname, u_int8_t check_subproto) { if(ndpi_dga_function != NULL) { /* A custom DGA function is defined */ int rc = ndpi_dga_function(name, is_hostname); @@ -8542,7 +8542,8 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str, if(flow && (flow->detected_protocol_stack[1] != NDPI_PROTOCOL_UNKNOWN)) return(0); /* Ignore DGA check for protocols already fully detected */ - if(ndpi_match_string_subprotocol(ndpi_str, name, strlen(name), &ret_match) > 0) + if(check_subproto && + ndpi_match_string_subprotocol(ndpi_str, name, strlen(name), &ret_match) > 0) return(0); /* Ignore DGA for known domain names */ if(isdigit((int)name[0])) { -- cgit v1.2.3