config: move LRU cache configurations to the new API

This commit is contained in:
Nardi Ivan
2024-01-18 10:21:24 +01:00
committed by Ivan Nardi
parent 3107a95881
commit f55358973f
8 changed files with 164 additions and 333 deletions
+2
View File
@@ -8,3 +8,5 @@ TODO
| NULL | "packets_limit_per_flow" | 32 | 0 | 255 | The upper limit on the number of packets per flow that will be subject to DPI, after which classification will be considered complete (0 = no limit) | | NULL | "packets_limit_per_flow" | 32 | 0 | 255 | The upper limit on the number of packets per flow that will be subject to DPI, after which classification will be considered complete (0 = no limit) |
| NULL | "filename.config" | NULL | NULL | NULL | Name of the file containing a list of configuration knobs itself (one per line)!. Useful to configure nDPI via text file instead of via API | | NULL | "filename.config" | NULL | NULL | NULL | Name of the file containing a list of configuration knobs itself (one per line)!. Useful to configure nDPI via text file instead of via API |
| "tls" | "metadata.sha1_fingerprint.enable" | 1 | NULL | NULL | Enable/disable computation and export of SHA1 fingerprint for TLS flows. Note that if it is disable, the flow risk `NDPI_MALICIOUS_SHA1_CERTIFICATE` is not checked | | "tls" | "metadata.sha1_fingerprint.enable" | 1 | NULL | NULL | Enable/disable computation and export of SHA1 fingerprint for TLS flows. Note that if it is disable, the flow risk `NDPI_MALICIOUS_SHA1_CERTIFICATE` is not checked |
| NULL | "lru.$CACHE_NAME.size" | See description | 0 | 16777215 | Set the size (in number of elements) of the specified LRU cache (0 = the cache is disabled). The keyword "$CACHE_NAME" is a placeholder for the cache name and the possible values are: ookla, bittorrent, zoom, stun, tls_cert, mining, msteams, stun_zoom. The default value is "32768" for the bittorrent cache, "512" for the zoom cache and "1024" for all the other caches |
| NULL | "lru.$CACHE_NAME.ttl" | See description | 0 | 16777215 | Set the TTL (in seconds) for the elements of the specified LRU cache (0 = the elements never explicitly expire). The keyword "$CACHE_NAME" is a placeholder for the cache name and the possible values are: ookla, bittorrent, zoom, stun, tls_cert, mining, msteams, stun_zoom. The default value is "120" for the ookla cache, "60" for the msteams and stun_zoom caches and "0" for all the other caches |
+2
View File
@@ -7,4 +7,6 @@
packets_limit_per_flow,32 packets_limit_per_flow,32
tls,metadata.sha1_fingerprint.enable,1 tls,metadata.sha1_fingerprint.enable,1
lru.bittorrent.ttl,0
-95
View File
@@ -143,9 +143,6 @@ int enable_malloc_bins = 0;
int max_malloc_bins = 14; int max_malloc_bins = 14;
int malloc_size_stats = 0; int malloc_size_stats = 0;
static int lru_cache_sizes[NDPI_LRUCACHE_MAX];
static int lru_cache_ttls[NDPI_LRUCACHE_MAX];
struct flow_info { struct flow_info {
struct ndpi_flow_info *flow; struct ndpi_flow_info *flow;
u_int16_t thread_id; u_int16_t thread_id;
@@ -607,16 +604,12 @@ static void help(u_int long_help) {
" -A | Dump internal statistics (LRU caches / Patricia trees / Ahocarasick automas / ...\n" " -A | Dump internal statistics (LRU caches / Patricia trees / Ahocarasick automas / ...\n"
" -M | Memory allocation stats on data-path (only by the library). It works only on single-thread configuration\n" " -M | Memory allocation stats on data-path (only by the library). It works only on single-thread configuration\n"
" -Z proto:value | Set this value of aggressiveness for this protocol (0 to disable it). This flag can be used multiple times\n" " -Z proto:value | Set this value of aggressiveness for this protocol (0 to disable it). This flag can be used multiple times\n"
" --lru-cache-size=NAME:size | Specify the size for this LRU cache (0 to disable it). This flag can be used multiple times\n"
" --lru-cache-ttl=NAME:size | Specify the TTL [in seconds] for this LRU cache (0 to disable it). This flag can be used multiple times\n"
" --cfg=proto,param,value | Configure the specific attribute of this protocol\n" " --cfg=proto,param,value | Configure the specific attribute of this protocol\n"
, ,
human_readeable_string_len, human_readeable_string_len,
min_pattern_len, max_pattern_len, max_num_packets_per_flow, max_packet_payload_dissection, min_pattern_len, max_pattern_len, max_num_packets_per_flow, max_packet_payload_dissection,
max_num_reported_top_payloads, max_num_tcp_dissected_pkts, max_num_udp_dissected_pkts); max_num_reported_top_payloads, max_num_tcp_dissected_pkts, max_num_udp_dissected_pkts);
printf("\nLRU Cache names: ookla, bittorrent, zoom, stun, tls_cert, mining, msteams, stun_zoom\n");
NDPI_PROTOCOL_BITMASK all; NDPI_PROTOCOL_BITMASK all;
struct ndpi_detection_module_struct *ndpi_info_mod = ndpi_init_detection_module(init_prefs); struct ndpi_detection_module_struct *ndpi_info_mod = ndpi_init_detection_module(init_prefs);
NDPI_BITMASK_SET_ALL(all); NDPI_BITMASK_SET_ALL(all);
@@ -663,9 +656,6 @@ static void help(u_int long_help) {
} }
#define OPTLONG_VALUE_LRU_CACHE_SIZE 1000
#define OPTLONG_VALUE_LRU_CACHE_TTL 1001
#define OPTLONG_VALUE_CFG 3000 #define OPTLONG_VALUE_CFG 3000
static struct option longopts[] = { static struct option longopts[] = {
@@ -709,9 +699,6 @@ static struct option longopts[] = {
{ "result-path", required_argument, NULL, 'w'}, { "result-path", required_argument, NULL, 'w'},
{ "quiet", no_argument, NULL, 'q'}, { "quiet", no_argument, NULL, 'q'},
{ "lru-cache-size", required_argument, NULL, OPTLONG_VALUE_LRU_CACHE_SIZE},
{ "lru-cache-ttl", required_argument, NULL, OPTLONG_VALUE_LRU_CACHE_TTL},
{ "cfg", required_argument, NULL, OPTLONG_VALUE_CFG}, { "cfg", required_argument, NULL, OPTLONG_VALUE_CFG},
{0, 0, 0, 0} {0, 0, 0, 0}
@@ -903,52 +890,6 @@ void printCSVHeader() {
fprintf(csv_fp, "\n"); fprintf(csv_fp, "\n");
} }
static int cache_idx_from_name(const char *name)
{
if(strcmp(name, "ookla") == 0)
return NDPI_LRUCACHE_OOKLA;
if(strcmp(name, "bittorrent") == 0)
return NDPI_LRUCACHE_BITTORRENT;
if(strcmp(name, "zoom") == 0)
return NDPI_LRUCACHE_ZOOM;
if(strcmp(name, "stun") == 0)
return NDPI_LRUCACHE_STUN;
if(strcmp(name, "tls_cert") == 0)
return NDPI_LRUCACHE_TLS_CERT;
if(strcmp(name, "mining") == 0)
return NDPI_LRUCACHE_MINING;
if(strcmp(name, "msteams") == 0)
return NDPI_LRUCACHE_MSTEAMS;
if(strcmp(name, "stun_zoom") == 0)
return NDPI_LRUCACHE_STUN_ZOOM;
return -1;
}
static int parse_cache_param(char *param, int *cache_idx, int *param_value)
{
char *saveptr, *tmp_str, *cache_str, *param_str;
int idx;
tmp_str = ndpi_strdup(param);
if(tmp_str) {
cache_str = strtok_r(tmp_str, ":", &saveptr);
if(cache_str) {
param_str = strtok_r(NULL, ":", &saveptr);
if(param_str) {
idx = cache_idx_from_name(cache_str);
if(idx >= 0) {
*cache_idx = idx;
*param_value = atoi(param_str);
ndpi_free(tmp_str);
return 0;
}
}
}
}
ndpi_free(tmp_str);
return -1;
}
static int parse_two_unsigned_integer(char *param, u_int32_t *num1, u_int32_t *num2) static int parse_two_unsigned_integer(char *param, u_int32_t *num1, u_int32_t *num2)
{ {
char *saveptr, *tmp_str, *num1_str, *num2_str; char *saveptr, *tmp_str, *num1_str, *num2_str;
@@ -1049,7 +990,6 @@ static void parseOptions(int argc, char **argv) {
u_int num_cores = sysconf(_SC_NPROCESSORS_ONLN); u_int num_cores = sysconf(_SC_NPROCESSORS_ONLN);
#endif #endif
#endif #endif
int cache_idx, cache_size, cache_ttl;
char *s1, *s2, *s3; char *s1, *s2, *s3;
#ifdef USE_DPDK #ifdef USE_DPDK
@@ -1066,11 +1006,6 @@ static void parseOptions(int argc, char **argv) {
for(i = 0; i < NDPI_MAX_SUPPORTED_PROTOCOLS; i++) for(i = 0; i < NDPI_MAX_SUPPORTED_PROTOCOLS; i++)
aggressiveness[i] = -1; /* Use the default value */ aggressiveness[i] = -1; /* Use the default value */
for(i = 0; i < NDPI_LRUCACHE_MAX; i++) {
lru_cache_sizes[i] = -1; /* Use the default value */
lru_cache_ttls[i] = -1; /* Use the default value */
}
while((opt = getopt_long(argc, argv, while((opt = getopt_long(argc, argv,
"a:Ab:B:e:Ec:C:dDFf:g:G:i:Ij:k:K:S:hHp:pP:l:r:Rs:tu:v:V:n:rp:x:X:w:Z:q0123:456:7:89:m:MT:U:", "a:Ab:B:e:Ec:C:dDFf:g:G:i:Ij:k:K:S:hHp:pP:l:r:Rs:tu:v:V:n:rp:x:X:w:Z:q0123:456:7:89:m:MT:U:",
longopts, &option_idx)) != EOF) { longopts, &option_idx)) != EOF) {
@@ -1378,22 +1313,6 @@ static void parseOptions(int argc, char **argv) {
max_num_udp_dissected_pkts = atoi(optarg); max_num_udp_dissected_pkts = atoi(optarg);
break; break;
case OPTLONG_VALUE_LRU_CACHE_SIZE:
if(parse_cache_param(optarg, &cache_idx, &cache_size) == -1) {
printf("Invalid parameter [%s]\n", optarg);
exit(1);
}
lru_cache_sizes[cache_idx] = cache_size;
break;
case OPTLONG_VALUE_LRU_CACHE_TTL:
if(parse_cache_param(optarg, &cache_idx, &cache_ttl) == -1) {
printf("Invalid parameter [%s]\n", optarg);
exit(1);
}
lru_cache_ttls[cache_idx] = cache_ttl;
break;
case OPTLONG_VALUE_CFG: case OPTLONG_VALUE_CFG:
if(parse_three_strings(optarg, &s1, &s2, &s3) == -1 || if(parse_three_strings(optarg, &s1, &s2, &s3) == -1 ||
reader_add_cfg(s1, s2, s3, 0) == -1) { reader_add_cfg(s1, s2, s3, 0) == -1) {
@@ -2903,20 +2822,6 @@ static void setupDetection(u_int16_t thread_id, pcap_t * pcap_handle) {
if(_protoFilePath != NULL) if(_protoFilePath != NULL)
ndpi_load_protocols_file(ndpi_thread_info[thread_id].workflow->ndpi_struct, _protoFilePath); ndpi_load_protocols_file(ndpi_thread_info[thread_id].workflow->ndpi_struct, _protoFilePath);
/* Enable/disable/configure LRU caches size here */
for(i = 0; i < NDPI_LRUCACHE_MAX; i++) {
if(lru_cache_sizes[i] != -1)
ndpi_set_lru_cache_size(ndpi_thread_info[thread_id].workflow->ndpi_struct,
i, lru_cache_sizes[i]);
}
/* Enable/disable LRU caches TTL here */
for(i = 0; i < NDPI_LRUCACHE_MAX; i++) {
if(lru_cache_ttls[i] != -1)
ndpi_set_lru_cache_ttl(ndpi_thread_info[thread_id].workflow->ndpi_struct,
i, lru_cache_ttls[i]);
}
/* Set aggressiveness here */ /* Set aggressiveness here */
for(i = 0; i < NDPI_MAX_SUPPORTED_PROTOCOLS; i++) { for(i = 0; i < NDPI_MAX_SUPPORTED_PROTOCOLS; i++) {
if(aggressiveness[i] != -1) if(aggressiveness[i] != -1)
+81 -11
View File
@@ -13,7 +13,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
struct ndpi_detection_module_struct *ndpi_info_mod; struct ndpi_detection_module_struct *ndpi_info_mod;
struct ndpi_flow_struct flow; struct ndpi_flow_struct flow;
u_int8_t protocol_was_guessed; u_int8_t protocol_was_guessed;
u_int32_t i, num; u_int32_t i;
u_int16_t random_proto, bool_value; u_int16_t random_proto, bool_value;
int random_value; int random_value;
NDPI_PROTOCOL_BITMASK enabled_bitmask; NDPI_PROTOCOL_BITMASK enabled_bitmask;
@@ -73,16 +73,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if(fuzzed_data.ConsumeBool()) if(fuzzed_data.ConsumeBool())
ndpi_load_ipv4_ptree(ndpi_info_mod, "ipv4_addresses.txt", NDPI_PROTOCOL_TLS); ndpi_load_ipv4_ptree(ndpi_info_mod, "ipv4_addresses.txt", NDPI_PROTOCOL_TLS);
for(i = 0; i < NDPI_LRUCACHE_MAX + 1; i++) { /* + 1 to test invalid type */
ndpi_set_lru_cache_size(ndpi_info_mod, static_cast<lru_cache_type>(i),
fuzzed_data.ConsumeIntegralInRange(0, (1 << 16) - 1));
ndpi_get_lru_cache_size(ndpi_info_mod, static_cast<lru_cache_type>(i), &num);
ndpi_set_lru_cache_ttl(ndpi_info_mod, static_cast<lru_cache_type>(i),
fuzzed_data.ConsumeIntegralInRange(0, (1 << 24) - 1));
ndpi_get_lru_cache_ttl(ndpi_info_mod, static_cast<lru_cache_type>(i), &num);
}
/* TODO: stub for geo stuff */ /* TODO: stub for geo stuff */
ndpi_load_geoip(ndpi_info_mod, NULL, NULL); ndpi_load_geoip(ndpi_info_mod, NULL, NULL);
@@ -124,6 +114,86 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
sprintf(cfg_value, "%d", value); sprintf(cfg_value, "%d", value);
ndpi_set_config(ndpi_info_mod, NULL, "packets_limit_per_flow", cfg_value); ndpi_set_config(ndpi_info_mod, NULL, "packets_limit_per_flow", cfg_value);
} }
if(fuzzed_data.ConsumeBool()) {
value = fuzzed_data.ConsumeIntegralInRange(0, 16777215 / 2); /* max / 2 instead of max + 1 to avoid oom on oss-fuzzer */
sprintf(cfg_value, "%d", value);
ndpi_set_config(ndpi_info_mod, NULL, "lru.ookla.size", cfg_value);
}
if(fuzzed_data.ConsumeBool()) {
value = fuzzed_data.ConsumeIntegralInRange(0, 16777215 + 1);
sprintf(cfg_value, "%d", value);
ndpi_set_config(ndpi_info_mod, NULL, "lru.ookla.ttl", cfg_value);
}
if(fuzzed_data.ConsumeBool()) {
value = fuzzed_data.ConsumeIntegralInRange(0, 16777215 / 2); /* max / 2 instead of max + 1 to avoid oom on oss-fuzzer */
sprintf(cfg_value, "%d", value);
ndpi_set_config(ndpi_info_mod, NULL, "lru.bittorrent.size", cfg_value);
}
if(fuzzed_data.ConsumeBool()) {
value = fuzzed_data.ConsumeIntegralInRange(0, 16777215 + 1);
sprintf(cfg_value, "%d", value);
ndpi_set_config(ndpi_info_mod, NULL, "lru.bittorrent.ttl", cfg_value);
}
if(fuzzed_data.ConsumeBool()) {
value = fuzzed_data.ConsumeIntegralInRange(0, 16777215 / 2); /* max / 2 instead of max + 1 to avoid oom on oss-fuzzer */
sprintf(cfg_value, "%d", value);
ndpi_set_config(ndpi_info_mod, NULL, "lru.zoom.size", cfg_value);
}
if(fuzzed_data.ConsumeBool()) {
value = fuzzed_data.ConsumeIntegralInRange(0, 16777215 + 1);
sprintf(cfg_value, "%d", value);
ndpi_set_config(ndpi_info_mod, NULL, "lru.zoom.ttl", cfg_value);
}
if(fuzzed_data.ConsumeBool()) {
value = fuzzed_data.ConsumeIntegralInRange(0, 16777215 / 2); /* max / 2 instead of max + 1 to avoid oom on oss-fuzzer */
sprintf(cfg_value, "%d", value);
ndpi_set_config(ndpi_info_mod, NULL, "lru.stun.size", cfg_value);
}
if(fuzzed_data.ConsumeBool()) {
value = fuzzed_data.ConsumeIntegralInRange(0, 16777215 + 1);
sprintf(cfg_value, "%d", value);
ndpi_set_config(ndpi_info_mod, NULL, "lru.stun.ttl", cfg_value);
}
if(fuzzed_data.ConsumeBool()) {
value = fuzzed_data.ConsumeIntegralInRange(0, 16777215 / 2); /* max / 2 instead of max + 1 to avoid oom on oss-fuzzer */
sprintf(cfg_value, "%d", value);
ndpi_set_config(ndpi_info_mod, NULL, "lru.tls_cert.size", cfg_value);
}
if(fuzzed_data.ConsumeBool()) {
value = fuzzed_data.ConsumeIntegralInRange(0, 16777215 + 1);
sprintf(cfg_value, "%d", value);
ndpi_set_config(ndpi_info_mod, NULL, "lru.tls_cert.ttl", cfg_value);
}
if(fuzzed_data.ConsumeBool()) {
value = fuzzed_data.ConsumeIntegralInRange(0, 16777215 / 2); /* max / 2 instead of max + 1 to avoid oom on oss-fuzzer */
sprintf(cfg_value, "%d", value);
ndpi_set_config(ndpi_info_mod, NULL, "lru.mining.size", cfg_value);
}
if(fuzzed_data.ConsumeBool()) {
value = fuzzed_data.ConsumeIntegralInRange(0, 16777215 + 1);
sprintf(cfg_value, "%d", value);
ndpi_set_config(ndpi_info_mod, NULL, "lru.mining.ttl", cfg_value);
}
if(fuzzed_data.ConsumeBool()) {
value = fuzzed_data.ConsumeIntegralInRange(0, 16777215 / 2); /* max / 2 instead of max + 1 to avoid oom on oss-fuzzer */
sprintf(cfg_value, "%d", value);
ndpi_set_config(ndpi_info_mod, NULL, "lru.msteams.size", cfg_value);
}
if(fuzzed_data.ConsumeBool()) {
value = fuzzed_data.ConsumeIntegralInRange(0, 16777215 + 1);
sprintf(cfg_value, "%d", value);
ndpi_set_config(ndpi_info_mod, NULL, "lru.msteams.ttl", cfg_value);
}
if(fuzzed_data.ConsumeBool()) {
value = fuzzed_data.ConsumeIntegralInRange(0, 16777215 / 2); /* max / 2 instead of max + 1 to avoid oom on oss-fuzzer */
sprintf(cfg_value, "%d", value);
ndpi_set_config(ndpi_info_mod, NULL, "lru.stun_zoom.size", cfg_value);
}
if(fuzzed_data.ConsumeBool()) {
value = fuzzed_data.ConsumeIntegralInRange(0, 16777215 + 1);
sprintf(cfg_value, "%d", value);
ndpi_set_config(ndpi_info_mod, NULL, "lru.stun_zoom.ttl", cfg_value);
}
ndpi_finalize_initialization(ndpi_info_mod); ndpi_finalize_initialization(ndpi_info_mod);
-14
View File
@@ -1074,20 +1074,6 @@ extern "C" {
lru_cache_type cache_type, lru_cache_type cache_type,
struct ndpi_lru_cache_stats *stats); struct ndpi_lru_cache_stats *stats);
int ndpi_get_lru_cache_size(struct ndpi_detection_module_struct *ndpi_struct,
lru_cache_type cache_type,
u_int32_t *num_entries);
int ndpi_set_lru_cache_size(struct ndpi_detection_module_struct *ndpi_struct,
lru_cache_type cache_type,
u_int32_t num_entries);
int ndpi_set_lru_cache_ttl(struct ndpi_detection_module_struct *ndpi_struct,
lru_cache_type cache_type,
u_int32_t ttl);
int ndpi_get_lru_cache_ttl(struct ndpi_detection_module_struct *ndpi_struct,
lru_cache_type cache_type,
u_int32_t *ttl);
int ndpi_set_opportunistic_tls(struct ndpi_detection_module_struct *ndpi_struct, int ndpi_set_opportunistic_tls(struct ndpi_detection_module_struct *ndpi_struct,
u_int16_t proto, int value); u_int16_t proto, int value);
int ndpi_get_opportunistic_tls(struct ndpi_detection_module_struct *ndpi_struct, int ndpi_get_opportunistic_tls(struct ndpi_detection_module_struct *ndpi_struct,
+19 -14
View File
@@ -151,6 +151,25 @@ struct ndpi_detection_module_config_struct {
char filename_config[CFG_MAX_LEN]; char filename_config[CFG_MAX_LEN];
/* LRU caches */
int ookla_cache_num_entries;
int ookla_cache_ttl;
int bittorrent_cache_num_entries;
int bittorrent_cache_ttl;
int zoom_cache_num_entries;
int zoom_cache_ttl;
int stun_cache_num_entries;
int stun_cache_ttl;
int tls_cert_cache_num_entries;
int tls_cert_cache_ttl;
int mining_cache_num_entries;
int mining_cache_ttl;
int msteams_cache_num_entries;
int msteams_cache_ttl;
int stun_zoom_cache_num_entries;
int stun_zoom_cache_ttl;
/* Protocols */ /* Protocols */
int tls_sha1_fingerprint_enabled; int tls_sha1_fingerprint_enabled;
@@ -244,13 +263,9 @@ struct ndpi_detection_module_struct {
/* NDPI_PROTOCOL_OOKLA */ /* NDPI_PROTOCOL_OOKLA */
struct ndpi_lru_cache *ookla_cache; struct ndpi_lru_cache *ookla_cache;
u_int32_t ookla_cache_num_entries;
u_int32_t ookla_cache_ttl;
/* NDPI_PROTOCOL_BITTORRENT */ /* NDPI_PROTOCOL_BITTORRENT */
struct ndpi_lru_cache *bittorrent_cache; struct ndpi_lru_cache *bittorrent_cache;
u_int32_t bittorrent_cache_num_entries;
u_int32_t bittorrent_cache_ttl;
/* NDPI_PROTOCOL_ZOOM */ /* NDPI_PROTOCOL_ZOOM */
struct ndpi_lru_cache *zoom_cache; struct ndpi_lru_cache *zoom_cache;
@@ -259,26 +274,16 @@ struct ndpi_detection_module_struct {
/* NDPI_PROTOCOL_STUN and subprotocols */ /* NDPI_PROTOCOL_STUN and subprotocols */
struct ndpi_lru_cache *stun_cache; struct ndpi_lru_cache *stun_cache;
u_int32_t stun_cache_num_entries;
u_int32_t stun_cache_ttl;
struct ndpi_lru_cache *stun_zoom_cache; struct ndpi_lru_cache *stun_zoom_cache;
u_int32_t stun_zoom_cache_num_entries;
u_int32_t stun_zoom_cache_ttl;
/* NDPI_PROTOCOL_TLS and subprotocols */ /* NDPI_PROTOCOL_TLS and subprotocols */
struct ndpi_lru_cache *tls_cert_cache; struct ndpi_lru_cache *tls_cert_cache;
u_int32_t tls_cert_cache_num_entries;
int32_t tls_cert_cache_ttl;
/* NDPI_PROTOCOL_MINING and subprotocols */ /* NDPI_PROTOCOL_MINING and subprotocols */
struct ndpi_lru_cache *mining_cache; struct ndpi_lru_cache *mining_cache;
u_int32_t mining_cache_num_entries;
u_int32_t mining_cache_ttl;
/* NDPI_PROTOCOL_MSTEAMS */ /* NDPI_PROTOCOL_MSTEAMS */
struct ndpi_lru_cache *msteams_cache; struct ndpi_lru_cache *msteams_cache;
u_int32_t msteams_cache_num_entries;
u_int32_t msteams_cache_ttl;
/* *** If you add a new LRU cache, please update lru_cache_type above! *** */ /* *** If you add a new LRU cache, please update lru_cache_type above! *** */
+59 -198
View File
@@ -3426,24 +3426,6 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(ndpi_init_prefs
return(NULL); 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_smtp_enabled = 1;
ndpi_str->opportunistic_tls_imap_enabled = 1; ndpi_str->opportunistic_tls_imap_enabled = 1;
ndpi_str->opportunistic_tls_pop_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); ndpi_add_domain_risk_exceptions(ndpi_str);
if(ndpi_str->ookla_cache_num_entries > 0) { if(ndpi_str->cfg.ookla_cache_num_entries > 0) {
ndpi_str->ookla_cache = ndpi_lru_cache_init(ndpi_str->ookla_cache_num_entries, ndpi_str->ookla_cache = ndpi_lru_cache_init(ndpi_str->cfg.ookla_cache_num_entries,
ndpi_str->ookla_cache_ttl); ndpi_str->cfg.ookla_cache_ttl);
if(!ndpi_str->ookla_cache) { if(!ndpi_str->ookla_cache) {
NDPI_LOG_ERR(ndpi_str, "Error allocating lru cache (num_entries %u)\n", 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) { if(ndpi_str->cfg.bittorrent_cache_num_entries > 0) {
ndpi_str->bittorrent_cache = ndpi_lru_cache_init(ndpi_str->bittorrent_cache_num_entries, ndpi_str->bittorrent_cache = ndpi_lru_cache_init(ndpi_str->cfg.bittorrent_cache_num_entries,
ndpi_str->bittorrent_cache_ttl); ndpi_str->cfg.bittorrent_cache_ttl);
if(!ndpi_str->bittorrent_cache) { if(!ndpi_str->bittorrent_cache) {
NDPI_LOG_ERR(ndpi_str, "Error allocating lru cache (num_entries %u)\n", 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) { if(ndpi_str->cfg.zoom_cache_num_entries > 0) {
ndpi_str->zoom_cache = ndpi_lru_cache_init(ndpi_str->zoom_cache_num_entries, ndpi_str->zoom_cache = ndpi_lru_cache_init(ndpi_str->cfg.zoom_cache_num_entries,
ndpi_str->zoom_cache_ttl); ndpi_str->cfg.zoom_cache_ttl);
if(!ndpi_str->zoom_cache) { if(!ndpi_str->zoom_cache) {
NDPI_LOG_ERR(ndpi_str, "Error allocating lru cache (num_entries %u)\n", 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) { if(ndpi_str->cfg.stun_cache_num_entries > 0) {
ndpi_str->stun_cache = ndpi_lru_cache_init(ndpi_str->stun_cache_num_entries, ndpi_str->stun_cache = ndpi_lru_cache_init(ndpi_str->cfg.stun_cache_num_entries,
ndpi_str->stun_cache_ttl); ndpi_str->cfg.stun_cache_ttl);
if(!ndpi_str->stun_cache) { if(!ndpi_str->stun_cache) {
NDPI_LOG_ERR(ndpi_str, "Error allocating lru cache (num_entries %u)\n", 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) { if(ndpi_str->cfg.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 = ndpi_lru_cache_init(ndpi_str->cfg.tls_cert_cache_num_entries,
ndpi_str->tls_cert_cache_ttl); ndpi_str->cfg.tls_cert_cache_ttl);
if(!ndpi_str->tls_cert_cache) { if(!ndpi_str->tls_cert_cache) {
NDPI_LOG_ERR(ndpi_str, "Error allocating lru cache (num_entries %u)\n", 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) { if(ndpi_str->cfg.mining_cache_num_entries > 0) {
ndpi_str->mining_cache = ndpi_lru_cache_init(ndpi_str->mining_cache_num_entries, ndpi_str->mining_cache = ndpi_lru_cache_init(ndpi_str->cfg.mining_cache_num_entries,
ndpi_str->mining_cache_ttl); ndpi_str->cfg.mining_cache_ttl);
if(!ndpi_str->mining_cache) { if(!ndpi_str->mining_cache) {
NDPI_LOG_ERR(ndpi_str, "Error allocating lru cache (num_entries %u)\n", 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) { if(ndpi_str->cfg.msteams_cache_num_entries > 0) {
ndpi_str->msteams_cache = ndpi_lru_cache_init(ndpi_str->msteams_cache_num_entries, ndpi_str->msteams_cache = ndpi_lru_cache_init(ndpi_str->cfg.msteams_cache_num_entries,
ndpi_str->msteams_cache_ttl); ndpi_str->cfg.msteams_cache_ttl);
if(!ndpi_str->msteams_cache) { if(!ndpi_str->msteams_cache) {
NDPI_LOG_ERR(ndpi_str, "Error allocating lru cache (num_entries %u)\n", 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) { if(ndpi_str->cfg.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 = ndpi_lru_cache_init(ndpi_str->cfg.stun_zoom_cache_num_entries,
ndpi_str->stun_zoom_cache_ttl); ndpi_str->cfg.stun_zoom_cache_ttl);
if(!ndpi_str->stun_zoom_cache) { if(!ndpi_str->stun_zoom_cache) {
NDPI_LOG_ERR(ndpi_str, "Error allocating lru cache (num_entries %u)\n", 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) }, { 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 }, { NULL, NULL, NULL, NULL, NULL, 0, -1 },
}; };
+1 -1
View File
@@ -1 +1 @@
--lru-cache-size=ookla:0 --lru-cache-ttl=msteams:1 --cfg=lru.ookla.size,0 --cfg=lru.msteams.ttl,1