From 91bb77a8806ee2987e856f66674cf3aa8b1d60db Mon Sep 17 00:00:00 2001 From: Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> Date: Wed, 22 Dec 2021 19:54:06 +0100 Subject: A final(?) effort to reduce memory usage per flow (#1389) Remove some unused fields and re-organize other ones. In particular: * Update the parameters of `ndpi_ssl_version2str()` function * Zattoo, Thunder: these timestamps aren't really used. * Ftp/mail: these protocols are dissected only over TCP. * Attention must be paid to TLS.Bittorrent flows to avoid invalid read/write to `flow->protos.bittorrent.hash` field. This is the last(?) commit of a long series (see 22241a1d, 227e586e, 730c2360, a8ffcd8b) aiming to reduce library memory consumption. Before, at nDPI 4.0 (more precisly, at a6b10cf7, because memory stats were wrong until that commit): ``` nDPI Memory statistics: nDPI Memory (once): 221.15 KB Flow Memory (per flow): 2.94 KB ``` Now: ``` nDPI Memory statistics: nDPI Memory (once): 231.71 KB Flow Memory (per flow): 1008 B <--------- ``` i.e. memory usage per flow has been reduced by 66%, dropping below the psychological threshold of 1 KB. To further reduce this value, we probably need to look into #1279: let's fight this battle another day. --- src/lib/protocols/thunder.c | 27 --------------------------- 1 file changed, 27 deletions(-) (limited to 'src/lib/protocols/thunder.c') diff --git a/src/lib/protocols/thunder.c b/src/lib/protocols/thunder.c index 31fa720d4..1b33c41d7 100644 --- a/src/lib/protocols/thunder.c +++ b/src/lib/protocols/thunder.c @@ -32,18 +32,7 @@ static void ndpi_int_thunder_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow/* , ndpi_protocol_type_t protocol_type */) { - struct ndpi_packet_struct *packet = &ndpi_struct->packet; - struct ndpi_id_struct *src = flow->src; - struct ndpi_id_struct *dst = flow->dst; - ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_THUNDER, NDPI_PROTOCOL_UNKNOWN); - - if (src != NULL) { - src->thunder_ts = packet->current_time_ms; - } - if (dst != NULL) { - dst->thunder_ts = packet->current_time_ms; - } } @@ -149,22 +138,6 @@ void ndpi_int_search_thunder_http(struct ndpi_detection_module_struct struct ndpi_id_struct *src = flow->src; struct ndpi_id_struct *dst = flow->dst; - - if (flow->detected_protocol_stack[0] == NDPI_PROTOCOL_THUNDER) { - if (src != NULL && ((u_int32_t) - (packet->current_time_ms - src->thunder_ts) < ndpi_struct->thunder_timeout)) { - NDPI_LOG_DBG2(ndpi_struct, - "thunder : save src connection packet detected\n"); - src->thunder_ts = packet->current_time_ms; - } else if (dst != NULL && ((u_int32_t) - (packet->current_time_ms - dst->thunder_ts) < ndpi_struct->thunder_timeout)) { - NDPI_LOG_DBG2(ndpi_struct, - "thunder : save dst connection packet detected\n"); - dst->thunder_ts = packet->current_time_ms; - } - return; - } - if (packet->payload_packet_len > 5 && memcmp(packet->payload, "GET /", 5) == 0 && NDPI_SRC_OR_DST_HAS_PROTOCOL(src, dst, NDPI_PROTOCOL_THUNDER)) { NDPI_LOG_DBG2(ndpi_struct, "HTTP packet detected\n"); -- cgit v1.2.3