diff options
author | Luca Deri <deri@ntop.org> | 2020-12-30 12:08:34 +0100 |
---|---|---|
committer | Luca Deri <deri@ntop.org> | 2020-12-30 12:12:33 +0100 |
commit | dc401f8a74811b947e0f7e3aee6c7b1c8724a6d0 (patch) | |
tree | a77537f25214f4d042fc81a5e4eb14887e503086 | |
parent | ab037e2c828db757811b2f91f45b7b64dfb934a1 (diff) |
Split ptree user data in 32 and 64 bit entries
-rw-r--r-- | src/include/ndpi_api.h.in | 2 | ||||
-rw-r--r-- | src/lib/ndpi_main.c | 26 | ||||
-rw-r--r-- | src/lib/third_party/include/ndpi_patricia.h | 10 |
3 files changed, 21 insertions, 17 deletions
diff --git a/src/include/ndpi_api.h.in b/src/include/ndpi_api.h.in index 6e09619e3..f307af9f1 100644 --- a/src/include/ndpi_api.h.in +++ b/src/include/ndpi_api.h.in @@ -936,7 +936,7 @@ extern "C" { /* ptree (trie) API */ ndpi_ptree_t* ndpi_ptree_create(void); - int ndpi_ptree_insert(ndpi_ptree_t *tree, const ndpi_ip_addr_t *addr, u_int8_t bits, u_int32_t user_data); + int ndpi_ptree_insert(ndpi_ptree_t *tree, const ndpi_ip_addr_t *addr, u_int8_t bits, u_int64_t user_data); int ndpi_ptree_match_addr(ndpi_ptree_t *tree, const ndpi_ip_addr_t *addr, u_int32_t *user_data); void ndpi_ptree_destroy(ndpi_ptree_t *tree); diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index a2fe4c3c8..3088f7432 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -1642,7 +1642,7 @@ u_int16_t ndpi_network_ptree_match(struct ndpi_detection_module_struct *ndpi_str fill_prefix_v4(&prefix, pin, 32, ((patricia_tree_t *) ndpi_str->protocols_ptree)->maxbits); node = ndpi_patricia_search_best(ndpi_str->protocols_ptree, &prefix); - return(node ? node->value.uv.user_value : NDPI_PROTOCOL_UNKNOWN); + return(node ? node->value.u.uv32.user_value : NDPI_PROTOCOL_UNKNOWN); } /* ******************************************* */ @@ -1658,9 +1658,9 @@ u_int16_t ndpi_network_port_ptree_match(struct ndpi_detection_module_struct *ndp node = ndpi_patricia_search_best(ndpi_str->protocols_ptree, &prefix); if(node) { - if((node->value.uv.additional_user_value == 0) - || (node->value.uv.additional_user_value == port)) - return(node->value.uv.user_value); + if((node->value.u.uv32.additional_user_value == 0) + || (node->value.u.uv32.additional_user_value == port)) + return(node->value.u.uv32.user_value); } return(NDPI_PROTOCOL_UNKNOWN); @@ -1746,7 +1746,7 @@ int ndpi_load_ipv4_ptree(struct ndpi_detection_module_struct *ndpi_str, pin.s_addr = inet_addr(addr); if((node = add_to_ptree(ndpi_str->protocols_ptree, AF_INET, &pin, cidr ? atoi(cidr) : 32 /* bits */)) != NULL) { - node->value.uv.user_value = protocol_id, node->value.uv.additional_user_value = 0 /* port */; + node->value.u.uv32.user_value = protocol_id, node->value.u.uv32.additional_user_value = 0 /* port */; num_loaded++; } } @@ -1772,7 +1772,7 @@ static void ndpi_init_ptree_ipv4(struct ndpi_detection_module_struct *ndpi_str, pin.s_addr = htonl(host_list[i].network); if((node = add_to_ptree(ptree, AF_INET, &pin, host_list[i].cidr /* bits */)) != NULL) { - node->value.uv.user_value = host_list[i].value, node->value.uv.additional_user_value = 0; + node->value.u.uv32.user_value = host_list[i].value, node->value.u.uv32.additional_user_value = 0; } } } @@ -1815,7 +1815,7 @@ static int ndpi_add_host_ip_subprotocol(struct ndpi_detection_module_struct *ndp inet_pton(AF_INET, value, &pin); if((node = add_to_ptree(ndpi_str->protocols_ptree, AF_INET, &pin, bits)) != NULL) { - node->value.uv.user_value = protocol_id, node->value.uv.additional_user_value = htons(port); + node->value.u.uv32.user_value = protocol_id, node->value.u.uv32.additional_user_value = htons(port); } return(0); @@ -2302,7 +2302,7 @@ int ndpi_get_custom_category_match(struct ndpi_detection_module_struct *ndpi_str node = ndpi_patricia_search_best(ndpi_str->custom_categories.ipAddresses, &prefix); if(node) { - *id = node->value.uv.user_value; + *id = node->value.u.uv32.user_value; return(0); } @@ -4293,7 +4293,7 @@ int ndpi_load_ip_category(struct ndpi_detection_module_struct *ndpi_str, const c } if((node = add_to_ptree(ndpi_str->custom_categories.ipAddresses_shadow, AF_INET, &pin, bits)) != NULL) { - node->value.uv.user_value = (u_int16_t)category, node->value.uv.additional_user_value = 0; + node->value.u.uv32.user_value = (u_int16_t)category, node->value.u.uv32.additional_user_value = 0; } return(0); @@ -4420,7 +4420,7 @@ int ndpi_fill_ip_protocol_category(struct ndpi_detection_module_struct *ndpi_str } if(node) { - ret->category = (ndpi_protocol_category_t) node->value.uv.user_value; + ret->category = (ndpi_protocol_category_t) node->value.u.uv32.user_value; return(1); } @@ -6649,7 +6649,7 @@ void ndpi_ptree_destroy(ndpi_ptree_t *tree) { /* ******************************************************************** */ int ndpi_ptree_insert(ndpi_ptree_t *tree, const ndpi_ip_addr_t *addr, - u_int8_t bits, uint user_data) { + u_int8_t bits, u_int64_t user_data) { u_int8_t is_v6 = ndpi_is_ipv6(addr); patricia_tree_t *ptree = is_v6 ? tree->v6 : tree->v4; prefix_t prefix; @@ -6672,7 +6672,7 @@ int ndpi_ptree_insert(ndpi_ptree_t *tree, const ndpi_ip_addr_t *addr, node = ndpi_patricia_lookup(ptree, &prefix); if(node != NULL) { - node->value.uv.user_value = user_data, node->value.uv.additional_user_value = 0; + node->value.u.uv64 = user_data; return(0); } @@ -6698,7 +6698,7 @@ int ndpi_ptree_match_addr(ndpi_ptree_t *tree, node = ndpi_patricia_search_best(ptree, &prefix); if(node) { - *user_data = node->value.uv.user_value; + *user_data = node->value.u.uv32.user_value; return(0); } diff --git a/src/lib/third_party/include/ndpi_patricia.h b/src/lib/third_party/include/ndpi_patricia.h index b53253d95..4e9bbe483 100644 --- a/src/lib/third_party/include/ndpi_patricia.h +++ b/src/lib/third_party/include/ndpi_patricia.h @@ -106,9 +106,13 @@ union patricia_node_value_t { void *user_data; /* User-defined values */ - struct { - u_int32_t user_value, additional_user_value; - } uv; + union { + struct { + u_int32_t user_value, additional_user_value; + } uv32; + + u_int64_t uv64; + } u; }; typedef struct _patricia_node_t { |