diff options
author | Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> | 2025-06-12 16:07:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-12 16:07:56 +0200 |
commit | 6da6991320168754eef57b2316574dd625938a65 (patch) | |
tree | 6ce61397216078807dcaa177cb6dc10bc1a3020a /src/lib/ndpi_main.c | |
parent | c4dabafb0e3fa19fe1d02158da4006a6f9ba901d (diff) |
Rework sanity checks and remove some functions from API (#2882)
Diffstat (limited to 'src/lib/ndpi_main.c')
-rw-r--r-- | src/lib/ndpi_main.c | 56 |
1 files changed, 22 insertions, 34 deletions
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index 3ecff0fb0..8b0c6f612 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -282,18 +282,6 @@ u_int32_t ndpi_detection_get_sizeof_ndpi_flow_struct(void) { /* *********************************************************************************** */ -u_int32_t ndpi_detection_get_sizeof_ndpi_flow_tcp_struct(void) { - return(sizeof(struct ndpi_flow_tcp_struct)); -} - -/* *********************************************************************************** */ - -u_int32_t ndpi_detection_get_sizeof_ndpi_flow_udp_struct(void) { - return(sizeof(struct ndpi_flow_udp_struct)); -} - -/* *********************************************************************************** */ - char *ndpi_get_proto_by_id(struct ndpi_detection_module_struct *ndpi_str, u_int id) { return(!ndpi_is_valid_protoId(ndpi_str, id) ? NULL : ndpi_str->proto_defaults[id].protoName); } @@ -1021,28 +1009,21 @@ void ndpi_init_protocol_match(struct ndpi_detection_module_struct *ndpi_str, /* ******************************************************************** */ /* Self check function to be called only for testing purposes */ -void ndpi_self_check_host_match(FILE *error_out) { +static void self_check_host_match(struct ndpi_detection_module_struct *ndpi_str, + ndpi_protocol_match *hosts) { u_int32_t i, j; - for(i = 0; host_match[i].string_to_match != NULL; i++) { - if(host_match[i].string_to_match[0] == '.') { - if (error_out != NULL) { - fprintf(error_out, - "[NDPI] INTERNAL ERROR Invalid string detected '%s'. It can not start with '.'\n", - host_match[i].string_to_match); - fprintf(error_out, "\nPlease fix host_match[] in ndpi_content_match.c.inc\n"); - } - abort(); + for(i = 0; hosts[i].string_to_match != NULL; i++) { + if(hosts[i].string_to_match[0] == '.') { + NDPI_LOG_ERR(ndpi_str, + "[NDPI] INTERNAL ERROR Invalid string detected '%s'. It can not start with '.'\n", + hosts[i].string_to_match); } - for(j = 0; host_match[j].string_to_match != NULL; j++) { - if((i != j) && (strcmp(host_match[i].string_to_match, host_match[j].string_to_match) == 0)) { - if (error_out != NULL) { - fprintf(error_out, - "[NDPI] INTERNAL ERROR duplicate string detected '%s' [id: %u, id %u]\n", - host_match[i].string_to_match, i, j); - fprintf(error_out, "\nPlease fix host_match[] in ndpi_content_match.c.inc\n"); - } - abort(); + for(j = 0; hosts[j].string_to_match != NULL; j++) { + if((i != j) && (strcmp(hosts[i].string_to_match, hosts[j].string_to_match) == 0)) { + NDPI_LOG_ERR(ndpi_str, + "[NDPI] INTERNAL ERROR duplicate string detected '%s' [id: %u, id %u]\n", + hosts[i].string_to_match, i, j); } } } @@ -1091,9 +1072,16 @@ static void ndpi_xgrams_init(struct ndpi_detection_module_struct *ndpi_str, static void init_string_based_protocols(struct ndpi_detection_module_struct *ndpi_str) { int i; + /* Sanity checks */ + self_check_host_match(ndpi_str, host_match); + self_check_host_match(ndpi_str, teams_host_match); + self_check_host_match(ndpi_str, outlook_host_match); + self_check_host_match(ndpi_str, ms_onedrive_host_match); + self_check_host_match(ndpi_str, microsoft365_host_match); + self_check_host_match(ndpi_str, azure_host_match); + for(i = 0; host_match[i].string_to_match != NULL; i++) ndpi_init_protocol_match(ndpi_str, &host_match[i]); - for(i = 0; teams_host_match[i].string_to_match != NULL; i++) ndpi_init_protocol_match(ndpi_str, &teams_host_match[i]); for(i = 0; outlook_host_match[i].string_to_match != NULL; i++) @@ -1138,7 +1126,7 @@ static void init_string_based_protocols(struct ndpi_detection_module_struct *ndp /* ******************************************************************** */ -static void ndpi_validate_protocol_initialization(struct ndpi_detection_module_struct *ndpi_str) { +static void validate_protocol_initialization(struct ndpi_detection_module_struct *ndpi_str) { u_int i; for(i = 0; i < ndpi_str->num_supported_protocols; i++) { @@ -4196,7 +4184,7 @@ int ndpi_finalize_initialization(struct ndpi_detection_module_struct *ndpi_str) if(!ndpi_str->custom_categories.categories_loaded) ndpi_enable_loaded_categories(ndpi_str); - ndpi_validate_protocol_initialization(ndpi_str); + validate_protocol_initialization(ndpi_str); if(ndpi_str->cfg.libgcrypt_init) { if(!gcry_control(GCRYCTL_INITIALIZATION_FINISHED_P)) { |