diff options
author | Nardi Ivan <nardi.ivan@gmail.com> | 2024-01-09 11:12:27 +0100 |
---|---|---|
committer | Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> | 2024-01-18 10:21:24 +0100 |
commit | f55358973fae0264fcb580e9dbc0b69ab9999839 (patch) | |
tree | 1a4f101c38cc73c0cc8603ccd760f812b3ffab6a /src/lib/ndpi_main.c | |
parent | 3107a958816f3a09ce39a36b42d03a0b0046225f (diff) |
config: move LRU cache configurations to the new API
Diffstat (limited to 'src/lib/ndpi_main.c')
-rw-r--r-- | src/lib/ndpi_main.c | 257 |
1 files changed, 59 insertions, 198 deletions
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index 39a72267c..1bc4327d4 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -3426,24 +3426,6 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(ndpi_init_prefs return(NULL); } - ndpi_str->ookla_cache_num_entries = 1024; - ndpi_str->bittorrent_cache_num_entries = 32768; - ndpi_str->zoom_cache_num_entries = 512; - ndpi_str->stun_cache_num_entries = 1024; - ndpi_str->tls_cert_cache_num_entries = 1024; - ndpi_str->mining_cache_num_entries = 1024; - ndpi_str->msteams_cache_num_entries = 1024; - ndpi_str->stun_zoom_cache_num_entries = 1024; - - ndpi_str->ookla_cache_ttl = 120; /* sec */ - ndpi_str->bittorrent_cache_ttl = 0; - ndpi_str->zoom_cache_ttl = 0; - ndpi_str->stun_cache_ttl = 0; - ndpi_str->tls_cert_cache_ttl = 0; - ndpi_str->mining_cache_ttl = 0; - ndpi_str->msteams_cache_ttl = 60; /* sec */ - ndpi_str->stun_zoom_cache_ttl = 60; /* sec */ - ndpi_str->opportunistic_tls_smtp_enabled = 1; ndpi_str->opportunistic_tls_imap_enabled = 1; ndpi_str->opportunistic_tls_pop_enabled = 1; @@ -3524,68 +3506,68 @@ int ndpi_finalize_initialization(struct ndpi_detection_module_struct *ndpi_str) ndpi_add_domain_risk_exceptions(ndpi_str); - if(ndpi_str->ookla_cache_num_entries > 0) { - ndpi_str->ookla_cache = ndpi_lru_cache_init(ndpi_str->ookla_cache_num_entries, - ndpi_str->ookla_cache_ttl); + if(ndpi_str->cfg.ookla_cache_num_entries > 0) { + ndpi_str->ookla_cache = ndpi_lru_cache_init(ndpi_str->cfg.ookla_cache_num_entries, + ndpi_str->cfg.ookla_cache_ttl); if(!ndpi_str->ookla_cache) { NDPI_LOG_ERR(ndpi_str, "Error allocating lru cache (num_entries %u)\n", - ndpi_str->ookla_cache_num_entries); + ndpi_str->cfg.ookla_cache_num_entries); } } - if(ndpi_str->bittorrent_cache_num_entries > 0) { - ndpi_str->bittorrent_cache = ndpi_lru_cache_init(ndpi_str->bittorrent_cache_num_entries, - ndpi_str->bittorrent_cache_ttl); + if(ndpi_str->cfg.bittorrent_cache_num_entries > 0) { + ndpi_str->bittorrent_cache = ndpi_lru_cache_init(ndpi_str->cfg.bittorrent_cache_num_entries, + ndpi_str->cfg.bittorrent_cache_ttl); if(!ndpi_str->bittorrent_cache) { NDPI_LOG_ERR(ndpi_str, "Error allocating lru cache (num_entries %u)\n", - ndpi_str->bittorrent_cache_num_entries); + ndpi_str->cfg.bittorrent_cache_num_entries); } } - if(ndpi_str->zoom_cache_num_entries > 0) { - ndpi_str->zoom_cache = ndpi_lru_cache_init(ndpi_str->zoom_cache_num_entries, - ndpi_str->zoom_cache_ttl); + if(ndpi_str->cfg.zoom_cache_num_entries > 0) { + ndpi_str->zoom_cache = ndpi_lru_cache_init(ndpi_str->cfg.zoom_cache_num_entries, + ndpi_str->cfg.zoom_cache_ttl); if(!ndpi_str->zoom_cache) { NDPI_LOG_ERR(ndpi_str, "Error allocating lru cache (num_entries %u)\n", - ndpi_str->zoom_cache_num_entries); + ndpi_str->cfg.zoom_cache_num_entries); } } - if(ndpi_str->stun_cache_num_entries > 0) { - ndpi_str->stun_cache = ndpi_lru_cache_init(ndpi_str->stun_cache_num_entries, - ndpi_str->stun_cache_ttl); + if(ndpi_str->cfg.stun_cache_num_entries > 0) { + ndpi_str->stun_cache = ndpi_lru_cache_init(ndpi_str->cfg.stun_cache_num_entries, + ndpi_str->cfg.stun_cache_ttl); if(!ndpi_str->stun_cache) { NDPI_LOG_ERR(ndpi_str, "Error allocating lru cache (num_entries %u)\n", - ndpi_str->stun_cache_num_entries); + ndpi_str->cfg.stun_cache_num_entries); } } - if(ndpi_str->tls_cert_cache_num_entries > 0) { - ndpi_str->tls_cert_cache = ndpi_lru_cache_init(ndpi_str->tls_cert_cache_num_entries, - ndpi_str->tls_cert_cache_ttl); + if(ndpi_str->cfg.tls_cert_cache_num_entries > 0) { + ndpi_str->tls_cert_cache = ndpi_lru_cache_init(ndpi_str->cfg.tls_cert_cache_num_entries, + ndpi_str->cfg.tls_cert_cache_ttl); if(!ndpi_str->tls_cert_cache) { NDPI_LOG_ERR(ndpi_str, "Error allocating lru cache (num_entries %u)\n", - ndpi_str->tls_cert_cache_num_entries); + ndpi_str->cfg.tls_cert_cache_num_entries); } } - if(ndpi_str->mining_cache_num_entries > 0) { - ndpi_str->mining_cache = ndpi_lru_cache_init(ndpi_str->mining_cache_num_entries, - ndpi_str->mining_cache_ttl); + if(ndpi_str->cfg.mining_cache_num_entries > 0) { + ndpi_str->mining_cache = ndpi_lru_cache_init(ndpi_str->cfg.mining_cache_num_entries, + ndpi_str->cfg.mining_cache_ttl); if(!ndpi_str->mining_cache) { NDPI_LOG_ERR(ndpi_str, "Error allocating lru cache (num_entries %u)\n", - ndpi_str->mining_cache_num_entries); + ndpi_str->cfg.mining_cache_num_entries); } } - if(ndpi_str->msteams_cache_num_entries > 0) { - ndpi_str->msteams_cache = ndpi_lru_cache_init(ndpi_str->msteams_cache_num_entries, - ndpi_str->msteams_cache_ttl); + if(ndpi_str->cfg.msteams_cache_num_entries > 0) { + ndpi_str->msteams_cache = ndpi_lru_cache_init(ndpi_str->cfg.msteams_cache_num_entries, + ndpi_str->cfg.msteams_cache_ttl); if(!ndpi_str->msteams_cache) { NDPI_LOG_ERR(ndpi_str, "Error allocating lru cache (num_entries %u)\n", - ndpi_str->msteams_cache_num_entries); + ndpi_str->cfg.msteams_cache_num_entries); } } - if(ndpi_str->stun_zoom_cache_num_entries > 0) { - ndpi_str->stun_zoom_cache = ndpi_lru_cache_init(ndpi_str->stun_zoom_cache_num_entries, - ndpi_str->stun_zoom_cache_ttl); + if(ndpi_str->cfg.stun_zoom_cache_num_entries > 0) { + ndpi_str->stun_zoom_cache = ndpi_lru_cache_init(ndpi_str->cfg.stun_zoom_cache_num_entries, + ndpi_str->cfg.stun_zoom_cache_ttl); if(!ndpi_str->stun_zoom_cache) { NDPI_LOG_ERR(ndpi_str, "Error allocating lru cache (num_entries %u)\n", - ndpi_str->stun_zoom_cache_num_entries); + ndpi_str->cfg.stun_zoom_cache_num_entries); } } @@ -9887,154 +9869,6 @@ int ndpi_get_lru_cache_stats(struct ndpi_detection_module_struct *ndpi_struct, } } -int ndpi_set_lru_cache_size(struct ndpi_detection_module_struct *ndpi_struct, - lru_cache_type cache_type, - u_int32_t num_entries) -{ - if(!ndpi_struct) - return -1; - - switch(cache_type) { - case NDPI_LRUCACHE_OOKLA: - ndpi_struct->ookla_cache_num_entries = num_entries; - return 0; - case NDPI_LRUCACHE_BITTORRENT: - ndpi_struct->bittorrent_cache_num_entries = num_entries; - return 0; - case NDPI_LRUCACHE_ZOOM: - ndpi_struct->zoom_cache_num_entries = num_entries; - return 0; - case NDPI_LRUCACHE_STUN: - ndpi_struct->stun_cache_num_entries = num_entries; - return 0; - case NDPI_LRUCACHE_TLS_CERT: - ndpi_struct->tls_cert_cache_num_entries = num_entries; - return 0; - case NDPI_LRUCACHE_MINING: - ndpi_struct->mining_cache_num_entries = num_entries; - return 0; - case NDPI_LRUCACHE_MSTEAMS: - ndpi_struct->msteams_cache_num_entries = num_entries; - return 0; - case NDPI_LRUCACHE_STUN_ZOOM: - ndpi_struct->stun_zoom_cache_num_entries = num_entries; - return 0; - default: - return -1; - } -} - -int ndpi_get_lru_cache_size(struct ndpi_detection_module_struct *ndpi_struct, - lru_cache_type cache_type, - u_int32_t *num_entries) -{ - if(!ndpi_struct) - return -1; - - switch(cache_type) { - case NDPI_LRUCACHE_OOKLA: - *num_entries = ndpi_struct->ookla_cache_num_entries; - return 0; - case NDPI_LRUCACHE_BITTORRENT: - *num_entries = ndpi_struct->bittorrent_cache_num_entries; - return 0; - case NDPI_LRUCACHE_ZOOM: - *num_entries = ndpi_struct->zoom_cache_num_entries; - return 0; - case NDPI_LRUCACHE_STUN: - *num_entries = ndpi_struct->stun_cache_num_entries; - return 0; - case NDPI_LRUCACHE_TLS_CERT: - *num_entries = ndpi_struct->tls_cert_cache_num_entries; - return 0; - case NDPI_LRUCACHE_MINING: - *num_entries = ndpi_struct->mining_cache_num_entries; - return 0; - case NDPI_LRUCACHE_MSTEAMS: - *num_entries = ndpi_struct->msteams_cache_num_entries; - return 0; - case NDPI_LRUCACHE_STUN_ZOOM: - *num_entries = ndpi_struct->stun_zoom_cache_num_entries; - return 0; - default: - return -1; - } -} - -int ndpi_set_lru_cache_ttl(struct ndpi_detection_module_struct *ndpi_struct, - lru_cache_type cache_type, - u_int32_t ttl) -{ - if(!ndpi_struct) - return -1; - - switch(cache_type) { - case NDPI_LRUCACHE_OOKLA: - ndpi_struct->ookla_cache_ttl = ttl; - return 0; - case NDPI_LRUCACHE_BITTORRENT: - ndpi_struct->bittorrent_cache_ttl = ttl; - return 0; - case NDPI_LRUCACHE_ZOOM: - ndpi_struct->zoom_cache_ttl = ttl; - return 0; - case NDPI_LRUCACHE_STUN: - ndpi_struct->stun_cache_ttl = ttl; - return 0; - case NDPI_LRUCACHE_TLS_CERT: - ndpi_struct->tls_cert_cache_ttl = ttl; - return 0; - case NDPI_LRUCACHE_MINING: - ndpi_struct->mining_cache_ttl = ttl; - return 0; - case NDPI_LRUCACHE_MSTEAMS: - ndpi_struct->msteams_cache_ttl = ttl; - return 0; - case NDPI_LRUCACHE_STUN_ZOOM: - ndpi_struct->stun_zoom_cache_ttl = ttl; - return 0; - default: - return -1; - } -} - -int ndpi_get_lru_cache_ttl(struct ndpi_detection_module_struct *ndpi_struct, - lru_cache_type cache_type, - u_int32_t *ttl) -{ - if(!ndpi_struct || !ttl) - return -1; - - switch(cache_type) { - case NDPI_LRUCACHE_OOKLA: - *ttl = ndpi_struct->ookla_cache_ttl; - return 0; - case NDPI_LRUCACHE_BITTORRENT: - *ttl = ndpi_struct->bittorrent_cache_ttl; - return 0; - case NDPI_LRUCACHE_ZOOM: - *ttl = ndpi_struct->zoom_cache_ttl; - return 0; - case NDPI_LRUCACHE_STUN: - *ttl = ndpi_struct->stun_cache_ttl; - return 0; - case NDPI_LRUCACHE_TLS_CERT: - *ttl = ndpi_struct->tls_cert_cache_ttl; - return 0; - case NDPI_LRUCACHE_MINING: - *ttl = ndpi_struct->mining_cache_ttl; - return 0; - case NDPI_LRUCACHE_MSTEAMS: - *ttl = ndpi_struct->msteams_cache_ttl; - return 0; - case NDPI_LRUCACHE_STUN_ZOOM: - *ttl = ndpi_struct->stun_zoom_cache_ttl; - return 0; - default: - return -1; - } -} - /* ******************************************************************** */ /* @@ -11000,6 +10834,33 @@ static const struct cfg_param { { NULL, "filename.config", NULL, NULL, NULL, CFG_PARAM_FILENAME_CONFIG, __OFF(filename_config) }, + /* LRU caches */ + + { NULL, "lru.ookla.size", "1024", "0", "16777215", CFG_PARAM_INT, __OFF(ookla_cache_num_entries)}, + { NULL, "lru.ookla.ttl", "120", "0", "16777215", CFG_PARAM_INT, __OFF(ookla_cache_ttl)}, + + { NULL, "lru.bittorrent.size", "32768", "0", "16777215", CFG_PARAM_INT, __OFF(bittorrent_cache_num_entries)}, + { NULL, "lru.bittorrent.ttl", "0", "0", "16777215", CFG_PARAM_INT, __OFF(bittorrent_cache_ttl)}, + + { NULL, "lru.zoom.size", "512", "0", "16777215", CFG_PARAM_INT, __OFF(zoom_cache_num_entries)}, + { NULL, "lru.zoom.ttl", "0", "0", "16777215", CFG_PARAM_INT, __OFF(zoom_cache_ttl)}, + + { NULL, "lru.stun.size", "1024", "0", "16777215", CFG_PARAM_INT, __OFF(stun_cache_num_entries)}, + { NULL, "lru.stun.ttl", "0", "0", "16777215", CFG_PARAM_INT, __OFF(stun_cache_ttl)}, + + { NULL, "lru.tls_cert.size", "1024", "0", "16777215", CFG_PARAM_INT, __OFF(tls_cert_cache_num_entries)}, + { NULL, "lru.tls_cert.ttl", "0", "0", "16777215", CFG_PARAM_INT, __OFF(tls_cert_cache_ttl)}, + + { NULL, "lru.mining.size", "1024", "0", "16777215", CFG_PARAM_INT, __OFF(mining_cache_num_entries)}, + { NULL, "lru.mining.ttl", "0", "0", "16777215", CFG_PARAM_INT, __OFF(mining_cache_ttl)}, + + { NULL, "lru.msteams.size", "1024", "0", "16777215", CFG_PARAM_INT, __OFF(msteams_cache_num_entries)}, + { NULL, "lru.msteams.ttl", "60", "0", "16777215", CFG_PARAM_INT, __OFF(msteams_cache_ttl)}, + + { NULL, "lru.stun_zoom.size", "1024", "0", "16777215", CFG_PARAM_INT, __OFF(stun_zoom_cache_num_entries)}, + { NULL, "lru.stun_zoom.ttl", "60", "0", "16777215", CFG_PARAM_INT, __OFF(stun_zoom_cache_ttl)}, + + { NULL, NULL, NULL, NULL, NULL, 0, -1 }, }; |