diff options
author | Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> | 2021-12-22 19:54:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-22 19:54:06 +0100 |
commit | 91bb77a8806ee2987e856f66674cf3aa8b1d60db (patch) | |
tree | 0f2a06cc9b64a8af221552e87ae771ac882ab4b5 /src/lib/ndpi_main.c | |
parent | 02da143e4567cbfe32b139561ec3a702ce380fc7 (diff) |
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.
Diffstat (limited to 'src/lib/ndpi_main.c')
-rw-r--r-- | src/lib/ndpi_main.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index ad70e59c6..7e1829b22 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -2377,8 +2377,6 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(ndpi_init_prefs ndpi_str->irc_timeout = NDPI_IRC_CONNECTION_TIMEOUT * ndpi_str->ticks_per_second; ndpi_str->gnutella_timeout = NDPI_GNUTELLA_CONNECTION_TIMEOUT * ndpi_str->ticks_per_second; - ndpi_str->thunder_timeout = NDPI_THUNDER_CONNECTION_TIMEOUT * ndpi_str->ticks_per_second; - ndpi_str->zattoo_connection_timeout = NDPI_ZATTOO_CONNECTION_TIMEOUT * ndpi_str->ticks_per_second; ndpi_str->jabber_stun_timeout = NDPI_JABBER_STUN_TIMEOUT * ndpi_str->ticks_per_second; ndpi_str->jabber_file_transfer_timeout = NDPI_JABBER_FT_TIMEOUT * ndpi_str->ticks_per_second; @@ -4322,6 +4320,12 @@ void ndpi_free_flow_data(struct ndpi_flow_struct* flow) { if(flow->http.user_agent) ndpi_free(flow->http.user_agent); + if(flow->http.nat_ip) + ndpi_free(flow->http.nat_ip); + + if(flow->http.detected_os) + ndpi_free(flow->http.detected_os); + if(flow->kerberos_buf.pktbuf) ndpi_free(flow->kerberos_buf.pktbuf); @@ -4918,12 +4922,12 @@ int ndpi_search_into_bittorrent_cache(struct ndpi_detection_module_struct *ndpi_ struct ndpi_flow_struct *flow, /* Parameters below need to be in network byte order */ u_int32_t saddr, u_int16_t sport, u_int32_t daddr, u_int16_t dport) { - if((!flow->bittorrent.bt_check_performed /* Do the check once */) && ndpi_struct->bittorrent_cache) { + if((!flow->bt_check_performed /* Do the check once */) && ndpi_struct->bittorrent_cache) { u_int16_t cached_proto; u_int8_t found = 0; u_int32_t key1, key2; - flow->bittorrent.bt_check_performed = 1; + flow->bt_check_performed = 1; /* Check cached communications */ key1 = ndpi_bittorrent_hash_funct(saddr, sport), key2 = ndpi_bittorrent_hash_funct(daddr, dport); @@ -7286,9 +7290,9 @@ u_int8_t ndpi_extra_dissection_possible(struct ndpi_detection_module_struct *ndp case NDPI_PROTOCOL_MAIL_POP: case NDPI_PROTOCOL_MAIL_IMAP: case NDPI_PROTOCOL_MAIL_SMTP: - if(flow->ftp_imap_pop_smtp.password[0] == '\0' && - flow->ftp_imap_pop_smtp.auth_tls == 0 && - flow->ftp_imap_pop_smtp.auth_done == 0) + if(flow->l4.tcp.ftp_imap_pop_smtp.password[0] == '\0' && + flow->l4.tcp.ftp_imap_pop_smtp.auth_tls == 0 && + flow->l4.tcp.ftp_imap_pop_smtp.auth_done == 0) return(1); break; |