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/protocols/http.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/lib/protocols/http.c') diff --git a/src/lib/protocols/http.c b/src/lib/protocols/http.c index 6fe6cab33..f9d6abd90 100644 --- a/src/lib/protocols/http.c +++ b/src/lib/protocols/http.c @@ -722,8 +722,6 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_ ndpi_hostname_sni_set(flow, packet->host_line.ptr, packet->host_line.len); if(strlen(flow->host_server_name) > 0) { - ndpi_check_dga_name(ndpi_struct, flow, flow->host_server_name, 1); - if(ndpi_is_valid_hostname(flow->host_server_name, strlen(flow->host_server_name)) == 0) { char str[128]; @@ -749,6 +747,10 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_ ndpi_http_parse_subprotocol(ndpi_struct, flow); + if(strlen(flow->host_server_name) > 0) { + ndpi_check_dga_name(ndpi_struct, flow, flow->host_server_name, 1, 0); + } + /** check result of host subprotocol detection -- cgit v1.2.3