diff options
author | Luca Deri <deri@ntop.org> | 2024-10-07 20:06:45 +0200 |
---|---|---|
committer | Luca Deri <deri@ntop.org> | 2024-10-07 20:08:53 +0200 |
commit | 55fa92490af593358a0b13ad1708ee9b14eec128 (patch) | |
tree | 519b80f2f48583efbd8090ca9ad7e48ae347f99c /src/include | |
parent | 5475625c463a0c9066986db3263fba4f076ea69c (diff) |
Implemented (disabled by default) DNS host cache. You can set the cache size as follows:
ndpiReader --cfg=dpi.address_cache_size,1000 -i <pcap>.pcap
In the above example the cache has up to 1000 entries.
In jcase ndpiReader exports data in JSON, the cache hostname (if found) is exported in the field server_hostname
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/ndpi_api.h | 13 | ||||
-rw-r--r-- | src/include/ndpi_private.h | 11 | ||||
-rw-r--r-- | src/include/ndpi_typedefs.h | 15 |
3 files changed, 34 insertions, 5 deletions
diff --git a/src/include/ndpi_api.h b/src/include/ndpi_api.h index edfb497d4..b08b6e69f 100644 --- a/src/include/ndpi_api.h +++ b/src/include/ndpi_api.h @@ -2334,6 +2334,19 @@ extern "C" { /* ******************************* */ + /* Address cache API */ + struct ndpi_address_cache* ndpi_init_address_cache(u_int32_t max_num_entries); + void ndpi_term_address_cache(struct ndpi_address_cache *cache); + u_int ndpi_address_cache_flush_expired(struct ndpi_address_cache *cache, u_int32_t epoch_now); + struct ndpi_address_cache_item* ndpi_address_cache_find(struct ndpi_address_cache *cache, ndpi_ip_addr_t ip_addr, u_int32_t epoch_now); + bool ndpi_address_cache_insert(struct ndpi_address_cache *cache, ndpi_ip_addr_t ip_addr, char *hostname, + u_int32_t epoch_now, u_int32_t ttl); + + struct ndpi_address_cache_item* ndpi_cache_address_find(struct ndpi_detection_module_struct *ndpi_struct, + ndpi_ip_addr_t ip_addr); + + /* ******************************* */ + const char *ndpi_lru_cache_idx_to_name(lru_cache_type idx); /** diff --git a/src/include/ndpi_private.h b/src/include/ndpi_private.h index ccc198cf1..54f59f652 100644 --- a/src/include/ndpi_private.h +++ b/src/include/ndpi_private.h @@ -199,6 +199,7 @@ struct ndpi_detection_module_config_struct { int libgcrypt_init; int guess_on_giveup; int compute_entropy; + int address_cache_size; int fpc_enabled; int guess_ip_before_port; int use_client_ip_in_guess; @@ -414,6 +415,7 @@ struct ndpi_detection_module_struct { u_int16_t max_payload_track_len; ndpi_str_hash *public_domain_suffixes; + struct ndpi_address_cache *address_cache; }; @@ -560,10 +562,6 @@ struct ndpi_detection_module_struct { #define NDPI_SELECTION_BITMASK_PROTOCOL_V6_TCP_OR_UDP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION (NDPI_SELECTION_BITMASK_PROTOCOL_V6_TCP_OR_UDP | NDPI_SELECTION_BITMASK_PROTOCOL_NO_TCP_RETRANSMISSION | NDPI_SELECTION_BITMASK_PROTOCOL_HAS_PAYLOAD) #define NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION (NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP | NDPI_SELECTION_BITMASK_PROTOCOL_NO_TCP_RETRANSMISSION | NDPI_SELECTION_BITMASK_PROTOCOL_HAS_PAYLOAD) - - - - /* Generic */ char *strptime(const char *s, const char *format, struct tm *tm); @@ -635,8 +633,11 @@ int load_category_file_fd(struct ndpi_detection_module_struct *ndpi_str, u_int64_t fpc_dns_cache_key_from_dns_info(struct ndpi_flow_struct *flow); +bool ndpi_cache_address(struct ndpi_detection_module_struct *ndpi_struct, + ndpi_ip_addr_t ip_addr, char *hostname, + u_int32_t epoch_now, u_int32_t ttl); -/* TLS */ + /* TLS */ int processClientServerHello(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow, uint32_t quic_version); void processCertificateElements(struct ndpi_detection_module_struct *ndpi_struct, diff --git a/src/include/ndpi_typedefs.h b/src/include/ndpi_typedefs.h index 6116bc453..b401aad11 100644 --- a/src/include/ndpi_typedefs.h +++ b/src/include/ndpi_typedefs.h @@ -1862,6 +1862,21 @@ struct ndpi_des_struct { /* **************************************** */ +struct ndpi_address_cache_item { + ndpi_ip_addr_t addr; /* key */ + char *hostname; /* value */ + u_int32_t expire_epoch; + struct ndpi_address_cache_item *next; /* Linked list */ +}; + +struct ndpi_address_cache { + u_int32_t num_cached_addresses, num_root_nodes; + u_int32_t num_entries, max_num_entries; + struct ndpi_address_cache_item **address_cache_root; +}; + +/* **************************************** */ + /* Prototype used to define custom DGA detection function */ typedef int (*ndpi_custom_dga_predict_fctn)(const char* domain, int domain_length); |