mirror of
				https://github.com/optim-enterprises-bv/nDPId.git
				synced 2025-10-31 18:27:47 +00:00 
			
		
		
		
	Fixed clang-tidy warnings.
* fixed/improved c-captured logging Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
This commit is contained in:
		| @@ -952,7 +952,7 @@ static enum nDPIsrvd_callback_return captured_json_callback(struct nDPIsrvd_sock | |||||||
|  |  | ||||||
|             if (flow_user->packets == NULL || flow_user->flow_max_packets == 0 || utarray_len(flow_user->packets) == 0) |             if (flow_user->packets == NULL || flow_user->flow_max_packets == 0 || utarray_len(flow_user->packets) == 0) | ||||||
|             { |             { | ||||||
|                 if (logging_mode != 0) |                 if (capture_mode != 0) | ||||||
|                 { |                 { | ||||||
|                     logger(0, "Flow %llu: No packets captured.", flow->id_as_ull); |                     logger(0, "Flow %llu: No packets captured.", flow->id_as_ull); | ||||||
|                 } |                 } | ||||||
| @@ -1335,8 +1335,8 @@ int main(int argc, char ** argv) | |||||||
|         return 1; |         return 1; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     logger(0, "Recv buffer size: %u\n", NETWORK_BUFFER_MAX_SIZE); |     logger(0, "Recv buffer size: %u", NETWORK_BUFFER_MAX_SIZE); | ||||||
|     logger(0, "Connecting to `%s'..\n", serv_optarg); |     logger(0, "Connecting to `%s'..", serv_optarg); | ||||||
|  |  | ||||||
|     if (nDPIsrvd_connect(sock) != CONNECT_OK) |     if (nDPIsrvd_connect(sock) != CONNECT_OK) | ||||||
|     { |     { | ||||||
|   | |||||||
| @@ -90,8 +90,7 @@ int main(void) | |||||||
|                 break; |                 break; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (buf[json_bytes - 2] != '}' || |             if (buf[json_bytes - 2] != '}' || buf[json_bytes - 1] != '\n') | ||||||
|                 buf[json_bytes - 1] != '\n') |  | ||||||
|             { |             { | ||||||
|                 fprintf(stderr, "BUG: Invalid JSON string: \"%.*s\"\n", (int)json_bytes, buf); |                 fprintf(stderr, "BUG: Invalid JSON string: \"%.*s\"\n", (int)json_bytes, buf); | ||||||
|                 exit(1); |                 exit(1); | ||||||
| @@ -129,8 +128,6 @@ int main(void) | |||||||
|  |  | ||||||
|             memmove(buf, buf + json_bytes, buf_used - json_bytes); |             memmove(buf, buf + json_bytes, buf_used - json_bytes); | ||||||
|             buf_used -= json_bytes; |             buf_used -= json_bytes; | ||||||
|             json_bytes = 0; |  | ||||||
|             json_start = 0; |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -58,7 +58,7 @@ static void nDPIsrvd_write_flow_info_cb(struct nDPIsrvd_socket const * sock, | |||||||
| #endif | #endif | ||||||
|             flow->last_seen, |             flow->last_seen, | ||||||
|             flow->idle_time, |             flow->idle_time, | ||||||
|             (flow->last_seen + flow->idle_time >= thread_data->most_recent_flow_time |             (thread_data != NULL && flow->last_seen + flow->idle_time >= thread_data->most_recent_flow_time | ||||||
|                  ? flow->last_seen + flow->idle_time - thread_data->most_recent_flow_time |                  ? flow->last_seen + flow->idle_time - thread_data->most_recent_flow_time | ||||||
|                  : 0)); |                  : 0)); | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										12
									
								
								nDPId-test.c
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								nDPId-test.c
									
									
									
									
									
								
							| @@ -479,7 +479,7 @@ static enum nDPIsrvd_callback_return update_flow_packets_processed(struct nDPIsr | |||||||
|         return CALLBACK_ERROR; |         return CALLBACK_ERROR; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     if (sock->flow_user_data_size > 0) |     if (flow_stats != NULL && sock->flow_user_data_size > 0) | ||||||
|     { |     { | ||||||
|         flow_stats->total_packets_processed = 0; |         flow_stats->total_packets_processed = 0; | ||||||
|     } |     } | ||||||
| @@ -513,7 +513,7 @@ static enum nDPIsrvd_callback_return update_flow_l4_payload_len(struct nDPIsrvd_ | |||||||
|     struct nDPIsrvd_json_token const * const flow_total_l4_payload_len[FD_COUNT] = { |     struct nDPIsrvd_json_token const * const flow_total_l4_payload_len[FD_COUNT] = { | ||||||
|         TOKEN_GET_SZ(sock, "flow_src_tot_l4_payload_len"), TOKEN_GET_SZ(sock, "flow_dst_tot_l4_payload_len")}; |         TOKEN_GET_SZ(sock, "flow_src_tot_l4_payload_len"), TOKEN_GET_SZ(sock, "flow_dst_tot_l4_payload_len")}; | ||||||
|  |  | ||||||
|     if (sock->flow_user_data_size > 0) |     if (flow_stats != NULL && sock->flow_user_data_size > 0) | ||||||
|     { |     { | ||||||
|         flow_stats->flow_total_l4_data_len = 0; |         flow_stats->flow_total_l4_data_len = 0; | ||||||
|     } |     } | ||||||
| @@ -586,7 +586,7 @@ static enum nDPIsrvd_callback_return distributor_json_callback(struct nDPIsrvd_s | |||||||
|             { |             { | ||||||
|                 instance_stats->daemon_event_count++; |                 instance_stats->daemon_event_count++; | ||||||
|             } |             } | ||||||
|             if (sock->thread_user_data_size > 0) |             if (thread_stats != NULL && sock->thread_user_data_size > 0) | ||||||
|             { |             { | ||||||
|                 thread_stats->daemon_event_count++; |                 thread_stats->daemon_event_count++; | ||||||
|             } |             } | ||||||
| @@ -687,7 +687,7 @@ static enum nDPIsrvd_callback_return distributor_json_callback(struct nDPIsrvd_s | |||||||
|             { |             { | ||||||
|                 global_stats->cur_active_flows++; |                 global_stats->cur_active_flows++; | ||||||
|                 global_stats->flow_new_count++; |                 global_stats->flow_new_count++; | ||||||
|                 if (sock->thread_user_data_size > 0) |                 if (thread_stats != NULL && sock->thread_user_data_size > 0) | ||||||
|                 { |                 { | ||||||
|                     thread_stats->flow_new_count++; |                     thread_stats->flow_new_count++; | ||||||
|                 } |                 } | ||||||
| @@ -707,7 +707,7 @@ static enum nDPIsrvd_callback_return distributor_json_callback(struct nDPIsrvd_s | |||||||
|                 global_stats->cur_active_flows--; |                 global_stats->cur_active_flows--; | ||||||
|                 global_stats->cur_idle_flows++; |                 global_stats->cur_idle_flows++; | ||||||
|                 global_stats->flow_end_count++; |                 global_stats->flow_end_count++; | ||||||
|                 if (sock->thread_user_data_size > 0) |                 if (thread_stats != NULL && sock->thread_user_data_size > 0) | ||||||
|                 { |                 { | ||||||
|                     thread_stats->flow_end_count++; |                     thread_stats->flow_end_count++; | ||||||
|                 } |                 } | ||||||
| @@ -723,7 +723,7 @@ static enum nDPIsrvd_callback_return distributor_json_callback(struct nDPIsrvd_s | |||||||
|                 global_stats->cur_active_flows--; |                 global_stats->cur_active_flows--; | ||||||
|                 global_stats->cur_idle_flows++; |                 global_stats->cur_idle_flows++; | ||||||
|                 global_stats->flow_idle_count++; |                 global_stats->flow_idle_count++; | ||||||
|                 if (sock->thread_user_data_size > 0) |                 if (thread_stats != NULL && sock->thread_user_data_size > 0) | ||||||
|                 { |                 { | ||||||
|                     thread_stats->flow_idle_count++; |                     thread_stats->flow_idle_count++; | ||||||
|                 } |                 } | ||||||
|   | |||||||
							
								
								
									
										10
									
								
								nDPId.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								nDPId.c
									
									
									
									
									
								
							| @@ -361,7 +361,7 @@ enum error_event | |||||||
|     IP4_PACKET_TOO_SHORT, |     IP4_PACKET_TOO_SHORT, | ||||||
|     IP4_SIZE_SMALLER_THAN_HEADER, |     IP4_SIZE_SMALLER_THAN_HEADER, | ||||||
|     IP4_L4_PAYLOAD_DETECTION_FAILED, |     IP4_L4_PAYLOAD_DETECTION_FAILED, | ||||||
|     IP6_PACKET_TOO_SHORT, |     IP6_PACKET_TOO_SHORT, // 10 | ||||||
|     IP6_SIZE_SMALLER_THAN_HEADER, |     IP6_SIZE_SMALLER_THAN_HEADER, | ||||||
|     IP6_L4_PAYLOAD_DETECTION_FAILED, |     IP6_L4_PAYLOAD_DETECTION_FAILED, | ||||||
|     TCP_PACKET_TOO_SHORT, |     TCP_PACKET_TOO_SHORT, | ||||||
| @@ -370,7 +370,7 @@ enum error_event | |||||||
|     MAX_FLOW_TO_TRACK, |     MAX_FLOW_TO_TRACK, | ||||||
|     FLOW_MEMORY_ALLOCATION_FAILED, |     FLOW_MEMORY_ALLOCATION_FAILED, | ||||||
|  |  | ||||||
|     ERROR_EVENT_COUNT |     ERROR_EVENT_COUNT // 17 | ||||||
| }; | }; | ||||||
|  |  | ||||||
| enum daemon_event | enum daemon_event | ||||||
| @@ -1510,9 +1510,12 @@ static void free_workflow(struct nDPId_workflow ** const workflow) | |||||||
|         ndpi_exit_detection_module(w->ndpi_struct); |         ndpi_exit_detection_module(w->ndpi_struct); | ||||||
|     } |     } | ||||||
|     for (size_t i = 0; i < w->max_active_flows; i++) |     for (size_t i = 0; i < w->max_active_flows; i++) | ||||||
|  |     { | ||||||
|  |         if (w->ndpi_flows_active != NULL) | ||||||
|         { |         { | ||||||
|             ndpi_tdestroy(w->ndpi_flows_active[i], ndpi_flow_info_free); |             ndpi_tdestroy(w->ndpi_flows_active[i], ndpi_flow_info_free); | ||||||
|         } |         } | ||||||
|  |     } | ||||||
|     ndpi_free(w->ndpi_flows_active); |     ndpi_free(w->ndpi_flows_active); | ||||||
|     ndpi_free(w->ndpi_flows_idle); |     ndpi_free(w->ndpi_flows_idle); | ||||||
|     ndpi_term_serializer(&w->ndpi_serializer); |     ndpi_term_serializer(&w->ndpi_serializer); | ||||||
| @@ -4826,7 +4829,8 @@ static int stop_reader_threads(void) | |||||||
|             reader_threads[i].workflow->total_flow_updates); |             reader_threads[i].workflow->total_flow_updates); | ||||||
|     } |     } | ||||||
|     /* total packets captured: same value for all threads as packet2thread distribution happens later */ |     /* total packets captured: same value for all threads as packet2thread distribution happens later */ | ||||||
|     printf("Total packets captured.......: %llu\n", reader_threads[0].workflow->packets_captured); |     printf("Total packets captured.......: %llu\n", | ||||||
|  |            (reader_threads[0].workflow != NULL ? reader_threads[0].workflow->packets_captured : 0)); | ||||||
|     printf("Total packets processed......: %llu\n", total_packets_processed); |     printf("Total packets processed......: %llu\n", total_packets_processed); | ||||||
|     printf("Total layer4 payload size....: %llu\n", total_l4_payload_len); |     printf("Total layer4 payload size....: %llu\n", total_l4_payload_len); | ||||||
|     printf("Total flows ignopred.........: %llu\n", total_flows_skipped); |     printf("Total flows ignopred.........: %llu\n", total_flows_skipped); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Toni Uhlig
					Toni Uhlig