aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorLuca <deri@ntop.org>2024-01-15 19:03:46 +0100
committerLuca <deri@ntop.org>2024-01-15 19:03:46 +0100
commit162c38f18f81a4e069db5f957c13f68c2cdc9b89 (patch)
tree33555b3e246c83832c0e3a99fda75912ba686461 /src/include
parent61a18623e71626b4c9197f171ca219fae6f5792b (diff)
Added new API calls
- ndpi_load_domain_suffixes() - ndpi_get_host_domain_suffix() whose goal is to find the domain name of a hostname. Example: www.bbc.co.uk -> co.uk mail.apple.com -> com
Diffstat (limited to 'src/include')
-rw-r--r--src/include/ndpi_api.h35
-rw-r--r--src/include/ndpi_private.h12
2 files changed, 42 insertions, 5 deletions
diff --git a/src/include/ndpi_api.h b/src/include/ndpi_api.h
index b20305e33..f4c2f6114 100644
--- a/src/include/ndpi_api.h
+++ b/src/include/ndpi_api.h
@@ -2147,6 +2147,9 @@ extern "C" {
u_int8_t class_id,
char *file_path);
bool ndpi_domain_classify_finalize(ndpi_domain_classify *s);
+ const char* ndpi_domain_classify_longest_prefix(ndpi_domain_classify *s,
+ u_int8_t *class_id /* out */,
+ const char *hostnname);
bool ndpi_domain_classify_contains(ndpi_domain_classify *s,
u_int8_t *class_id /* out */,
const char *domain);
@@ -2188,6 +2191,8 @@ extern "C" {
/**
* Get user data which was previously set with `ndpi_set_user_data()`.
*
+ * @par ndpi_str = the struct created for the protocol detection
+ *
* @return the user data pointer
*
*/
@@ -2195,6 +2200,36 @@ extern "C" {
/* ******************************* */
+ /**
+ * Loads the domain suffixes from the specified path. You need to
+ * perform this action once
+ *
+ * @par ndpi_str = the struct created for the protocol detection
+ * @par public_suffix_list_path = path of the public_suffix_list path
+ *
+ * @return 0 = no error, -1 otherwise
+ *
+ */
+ int ndpi_load_domain_suffixes(struct ndpi_detection_module_struct *ndpi_str,
+ char *public_suffix_list_path);
+
+ /**
+ * Returns the domain suffix out of the specified hostname.
+ * The returned pointer is an offset of the original hostname.
+ * Note that you need to call ndpi_load_domain_suffixes() before
+ * calling this function.
+ *
+ * @par ndpi_str = the struct created for the protocol detection
+ * @par hostname = the hostname from which the domain name has to be extracted
+ *
+ * @return The host domain name or the hostitself if not found.
+ *
+ */
+ const char* ndpi_get_host_domain_suffix(struct ndpi_detection_module_struct *ndpi_str,
+ const char *hostname);
+
+ /* ******************************* */
+
/* Can't call libc functions from kernel space, define some stub instead */
#define ndpi_isalpha(ch) (((ch) >= 'a' && (ch) <= 'z') || ((ch) >= 'A' && (ch) <= 'Z'))
diff --git a/src/include/ndpi_private.h b/src/include/ndpi_private.h
index d0adfa362..df3bfaf2c 100644
--- a/src/include/ndpi_private.h
+++ b/src/include/ndpi_private.h
@@ -152,7 +152,7 @@ struct ndpi_detection_module_struct {
u_int16_t num_tls_blocks_to_follow;
u_int8_t skip_tls_blocks_until_change_cipher:1, _notused:7;
u_int8_t tls_certificate_expire_in_x_days;
-
+
void *user_data;
char custom_category_labels[NUM_CUSTOM_CATEGORIES][CUSTOM_CATEGORY_LABEL_LEN];
@@ -206,11 +206,11 @@ struct ndpi_detection_module_struct {
/* Patricia trees */
ndpi_patricia_tree_t *ip_risk_mask_ptree;
ndpi_patricia_tree_t *ip_risk_mask_ptree6;
- ndpi_patricia_tree_t *ip_risk_ptree;
+ ndpi_patricia_tree_t *ip_risk_ptree;
ndpi_patricia_tree_t *ip_risk_ptree6;
ndpi_patricia_tree_t *protocols_ptree; /* IP-based protocol detection */
ndpi_patricia_tree_t *protocols_ptree6;
-
+
/* *** If you add a new Patricia tree, please update ptree_type above! *** */
struct {
@@ -256,7 +256,7 @@ struct ndpi_detection_module_struct {
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 */
struct ndpi_lru_cache *mining_cache;
u_int32_t mining_cache_num_entries;
@@ -302,7 +302,9 @@ struct ndpi_detection_module_struct {
nbpf_filter nbpf_custom_proto[MAX_NBPF_CUSTOM_PROTO];
#endif
- u_int16_t max_payload_track_len;
+ u_int16_t max_payload_track_len;
+
+ ndpi_domain_classify *public_domain_suffixes;
};