Fixed clang-tidy warnings.

* fixed/improved c-captured logging

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
This commit is contained in:
Toni Uhlig
2023-11-13 13:52:42 +01:00
parent 4920b2a4be
commit 82934b7271
5 changed files with 19 additions and 18 deletions

View File

@@ -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 (logging_mode != 0)
if (capture_mode != 0)
{
logger(0, "Flow %llu: No packets captured.", flow->id_as_ull);
}
@@ -1335,8 +1335,8 @@ int main(int argc, char ** argv)
return 1;
}
logger(0, "Recv buffer size: %u\n", NETWORK_BUFFER_MAX_SIZE);
logger(0, "Connecting to `%s'..\n", serv_optarg);
logger(0, "Recv buffer size: %u", NETWORK_BUFFER_MAX_SIZE);
logger(0, "Connecting to `%s'..", serv_optarg);
if (nDPIsrvd_connect(sock) != CONNECT_OK)
{

View File

@@ -90,8 +90,7 @@ int main(void)
break;
}
if (buf[json_bytes - 2] != '}' ||
buf[json_bytes - 1] != '\n')
if (buf[json_bytes - 2] != '}' || buf[json_bytes - 1] != '\n')
{
fprintf(stderr, "BUG: Invalid JSON string: \"%.*s\"\n", (int)json_bytes, buf);
exit(1);
@@ -129,8 +128,6 @@ int main(void)
memmove(buf, buf + json_bytes, buf_used - json_bytes);
buf_used -= json_bytes;
json_bytes = 0;
json_start = 0;
}
}

View File

@@ -58,7 +58,7 @@ static void nDPIsrvd_write_flow_info_cb(struct nDPIsrvd_socket const * sock,
#endif
flow->last_seen,
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
: 0));
}

View File

@@ -479,7 +479,7 @@ static enum nDPIsrvd_callback_return update_flow_packets_processed(struct nDPIsr
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;
}
@@ -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] = {
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;
}
@@ -586,7 +586,7 @@ static enum nDPIsrvd_callback_return distributor_json_callback(struct nDPIsrvd_s
{
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++;
}
@@ -687,7 +687,7 @@ static enum nDPIsrvd_callback_return distributor_json_callback(struct nDPIsrvd_s
{
global_stats->cur_active_flows++;
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++;
}
@@ -707,7 +707,7 @@ static enum nDPIsrvd_callback_return distributor_json_callback(struct nDPIsrvd_s
global_stats->cur_active_flows--;
global_stats->cur_idle_flows++;
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++;
}
@@ -723,7 +723,7 @@ static enum nDPIsrvd_callback_return distributor_json_callback(struct nDPIsrvd_s
global_stats->cur_active_flows--;
global_stats->cur_idle_flows++;
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++;
}

12
nDPId.c
View File

@@ -361,7 +361,7 @@ enum error_event
IP4_PACKET_TOO_SHORT,
IP4_SIZE_SMALLER_THAN_HEADER,
IP4_L4_PAYLOAD_DETECTION_FAILED,
IP6_PACKET_TOO_SHORT,
IP6_PACKET_TOO_SHORT, // 10
IP6_SIZE_SMALLER_THAN_HEADER,
IP6_L4_PAYLOAD_DETECTION_FAILED,
TCP_PACKET_TOO_SHORT,
@@ -370,7 +370,7 @@ enum error_event
MAX_FLOW_TO_TRACK,
FLOW_MEMORY_ALLOCATION_FAILED,
ERROR_EVENT_COUNT
ERROR_EVENT_COUNT // 17
};
enum daemon_event
@@ -1511,7 +1511,10 @@ static void free_workflow(struct nDPId_workflow ** const workflow)
}
for (size_t i = 0; i < w->max_active_flows; i++)
{
ndpi_tdestroy(w->ndpi_flows_active[i], ndpi_flow_info_free);
if (w->ndpi_flows_active != NULL)
{
ndpi_tdestroy(w->ndpi_flows_active[i], ndpi_flow_info_free);
}
}
ndpi_free(w->ndpi_flows_active);
ndpi_free(w->ndpi_flows_idle);
@@ -4826,7 +4829,8 @@ static int stop_reader_threads(void)
reader_threads[i].workflow->total_flow_updates);
}
/* 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 layer4 payload size....: %llu\n", total_l4_payload_len);
printf("Total flows ignopred.........: %llu\n", total_flows_skipped);