diff options
author | Luca Deri <deri@ntop.org> | 2025-05-20 23:14:59 +0200 |
---|---|---|
committer | Luca Deri <deri@ntop.org> | 2025-05-20 23:14:59 +0200 |
commit | c590dc49551b32f12ebb4850e13a99cacbf90366 (patch) | |
tree | 00267be44fc76d2f5745d3e4a7575e82965fb814 /src/lib/ndpi_utils.c | |
parent | 34ee4d0b1d2ed080a85a93780a0eaf68136c109f (diff) |
Added new APi calls
- ndpi_is_master_only_protocol()
- ndpi_normalize_protocol()
These two APi calls are used to normalize mater/app nDPI protocols
Diffstat (limited to 'src/lib/ndpi_utils.c')
-rw-r--r-- | src/lib/ndpi_utils.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/lib/ndpi_utils.c b/src/lib/ndpi_utils.c index 490519582..e7163c2ca 100644 --- a/src/lib/ndpi_utils.c +++ b/src/lib/ndpi_utils.c @@ -4389,3 +4389,54 @@ u_char* ndpi_str_to_utf8(u_char *in, u_int in_len, u_char *out, u_int out_len) { return(out); } + +/* ************************************************************** */ + +/* + The function below checks whether the specified protocol is a + "real" master protocol or not, meaning that the protocol cannot + be encapsulated on another nDPI protocol. +*/ +bool ndpi_is_master_only_protocol(struct ndpi_detection_module_struct *ndpi_str, + u_int16_t proto_id) { + if(!ndpi_is_valid_protoId(proto_id)) + return(false); + else + return(ndpi_str->proto_defaults[proto_id].isAppProtocol ? false : true); +} + +/* ************************************************************** */ + +bool ndpi_normalize_protocol(struct ndpi_detection_module_struct *ndpi_str, + ndpi_master_app_protocol *proto) { + /* Move app to master when not an application protocol */ + if((proto->master_protocol == NDPI_PROTOCOL_UNKNOWN) + && (proto->app_protocol != NDPI_PROTOCOL_UNKNOWN)) { + if(ndpi_is_master_only_protocol(ndpi_str, proto->app_protocol)) { + proto->master_protocol = proto->app_protocol; + proto->app_protocol = NDPI_PROTOCOL_UNKNOWN; + return(true); + } else { + #ifdef DEBUG + NDPI_LOG_ERR(ndpi_str, "INTERNAL ERROR: unexpected protocol combination %u.%u/%s", + proto->master_protocol, proto->app_protocol, + ndpi_get_proto_name(ndpi_str, proto)); + #endif + } + } + + /* Remove duplicate protocols */ + if((proto->master_protocol != NDPI_PROTOCOL_UNKNOWN) + && (proto->master_protocol == proto->app_protocol)) { + if(ndpi_is_master_only_protocol(ndpi_str, proto->app_protocol)) { + proto->master_protocol = proto->app_protocol; + proto->app_protocol = NDPI_PROTOCOL_UNKNOWN; + return(true); + } else { + proto->master_protocol = NDPI_PROTOCOL_UNKNOWN; + return(true); + } + } + + return(false); +} |