Minor cleanup

This commit is contained in:
Luca Deri
2023-03-13 20:52:08 +01:00
parent d398f232be
commit ebfc1fe827
2 changed files with 14 additions and 8 deletions
+4 -2
View File
@@ -64,13 +64,15 @@
#ifndef _NDPI_PATRICIA_TYPEDEF_H_
#define _NDPI_PATRICIA_TYPEDEF_H_
/* pointer to usr data (ex. route flap info) */
#define UV16_MAX_USER_VALUES 2
/* pointer to user data (ex. route flap info) */
union ndpi_patricia_node_value_t {
/* User-defined values */
union {
struct {
u_int16_t user_value, additional_user_value;
} uv16[2];
} uv16[UV16_MAX_USER_VALUES];
struct {
u_int32_t user_value, additional_user_value;
+10 -6
View File
@@ -2173,12 +2173,15 @@ int ndpi_get_patricia_stats(struct ndpi_detection_module_struct *ndpi_struct,
case NDPI_PTREE_RISK_MASK:
ndpi_patricia_get_stats((ndpi_patricia_tree_t *)ndpi_struct->ip_risk_mask_ptree, stats);
return 0;
case NDPI_PTREE_RISK:
ndpi_patricia_get_stats((ndpi_patricia_tree_t *)ndpi_struct->ip_risk_ptree, stats);
return 0;
case NDPI_PTREE_PROTOCOLS:
ndpi_patricia_get_stats((ndpi_patricia_tree_t *)ndpi_struct->protocols_ptree, stats);
return 0;
default:
return -1;
}
@@ -2334,7 +2337,7 @@ u_int16_t ndpi_network_port_ptree_match(struct ndpi_detection_module_struct *ndp
if(node) {
int i;
for(i=0; i<2; i++) {
for(i=0; i<UV16_MAX_USER_VALUES; i++) {
if((node->value.u.uv16[i].additional_user_value == 0)
|| (node->value.u.uv16[i].additional_user_value == port))
return(node->value.u.uv16[i].user_value);
@@ -2423,7 +2426,7 @@ int ndpi_load_ipv4_ptree(struct ndpi_detection_module_struct *ndpi_str,
if((node = add_to_ptree(ndpi_str->protocols_ptree, AF_INET, &pin, cidr ? atoi(cidr) : 32 /* bits */)) != NULL) {
u_int i, found = 0;
for(i=0; i<2; i++) {
for(i=0; i<UV16_MAX_USER_VALUES; i++) {
if(node->value.u.uv16[i].user_value == 0) {
node->value.u.uv16[i].user_value = protocol_id, node->value.u.uv16[i].additional_user_value = 0 /* port */;
found = 1;
@@ -2453,9 +2456,10 @@ 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) {
/* Two main cases:
1) ip -> protocol: uv16[0].user_value = protocol; uv16[0].additional_user_value = 0;
2) ip -> risk: uv16[0].user_value = risk; uv16[0].additional_user_value = 0;
/*
Two main cases:
1) ip -> protocol: uv16[0].user_value = protocol; uv16[0].additional_user_value = 0;
2) ip -> risk: uv16[0].user_value = risk; uv16[0].additional_user_value = 0;
*/
node->value.u.uv16[0].user_value = host_list[i].value, node->value.u.uv16[0].additional_user_value = 0;
}
@@ -2502,7 +2506,7 @@ static int ndpi_add_host_ip_subprotocol(struct ndpi_detection_module_struct *ndp
if((node = add_to_ptree(ndpi_str->protocols_ptree, AF_INET, &pin, bits)) != NULL) {
int i;
for(i=0; i<2; i++) {
for(i=0; i<UV16_MAX_USER_VALUES; i++) {
if(node->value.u.uv16[i].user_value == 0) {
node->value.u.uv16[i].user_value = protocol_id, node->value.u.uv16[i].additional_user_value = htons(port);
return(0);