summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/vlib/main.c2
-rw-r--r--src/vnet/interface_cli.c2
-rw-r--r--src/vnet/interface_output.c2
-rw-r--r--src/vnet/pg/output.c5
-rw-r--r--src/vppinfra/pcap.c3
-rw-r--r--src/vppinfra/pcap_funcs.h3
6 files changed, 13 insertions, 4 deletions
diff --git a/src/vlib/main.c b/src/vlib/main.c
index 0786465e0e4..66c0023cc94 100644
--- a/src/vlib/main.c
+++ b/src/vlib/main.c
@@ -2204,6 +2204,8 @@ pcap_dispatch_trace_command_internal (vlib_main_t * vm,
{
pm->n_packets_to_capture = pm->n_packets_captured;
error = pcap_write (pm);
+ if (pm->file_descriptor >= 0)
+ pcap_close (pm);
if (error)
clib_error_report (error);
else
diff --git a/src/vnet/interface_cli.c b/src/vnet/interface_cli.c
index 437854476b4..8db26391573 100644
--- a/src/vnet/interface_cli.c
+++ b/src/vnet/interface_cli.c
@@ -1743,6 +1743,8 @@ pcap_trace_command_internal (vlib_main_t * vm,
vm->pcap[rx_tx].pcap_main.n_packets_to_capture =
vm->pcap[rx_tx].pcap_main.n_packets_captured;
error = pcap_write (&vm->pcap[rx_tx].pcap_main);
+ if (vm->pcap[rx_tx].pcap_main.file_descriptor >= 0)
+ pcap_close (&vm->pcap[rx_tx].pcap_main);
if (error)
clib_error_report (error);
else
diff --git a/src/vnet/interface_output.c b/src/vnet/interface_output.c
index 60953b0f35a..c863d444f5a 100644
--- a/src/vnet/interface_output.c
+++ b/src/vnet/interface_output.c
@@ -1439,6 +1439,8 @@ pcap_drop_trace_command_fn (vlib_main_t * vm,
im->pcap_main.n_packets_to_capture =
im->pcap_main.n_packets_captured;
error = pcap_write (&im->pcap_main);
+ if (im->pcap_main.file_descriptor >= 0)
+ pcap_close (&im->pcap_main);
if (error)
clib_error_report (error);
else
diff --git a/src/vnet/pg/output.c b/src/vnet/pg/output.c
index a84f30301dc..b5ee157b4c6 100644
--- a/src/vnet/pg/output.c
+++ b/src/vnet/pg/output.c
@@ -79,7 +79,10 @@ pg_output (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
}
if (pif->pcap_file_name != 0)
pcap_write (&pif->pcap_main);
-
+ if (pif->pcap_main.file_descriptor >= 0
+ && pif->pcap_main.n_packets_captured >=
+ pif->pcap_main.n_packets_to_capture)
+ pcap_close (&pif->pcap_main);
vlib_buffer_free (vm, vlib_frame_vector_args (frame), n_buffers);
if (PREDICT_FALSE (pif->lockp != 0))
diff --git a/src/vppinfra/pcap.c b/src/vppinfra/pcap.c
index 8f644e30f1d..0ca923e81cf 100644
--- a/src/vppinfra/pcap.c
+++ b/src/vppinfra/pcap.c
@@ -157,9 +157,6 @@ pcap_write (pcap_main_t * pm)
pm->n_pcap_data_written = 0;
}
- if (pm->n_packets_captured >= pm->n_packets_to_capture)
- pcap_close (pm);
-
done:
if (error)
{
diff --git a/src/vppinfra/pcap_funcs.h b/src/vppinfra/pcap_funcs.h
index 364f4be2333..a3a3072f955 100644
--- a/src/vppinfra/pcap_funcs.h
+++ b/src/vppinfra/pcap_funcs.h
@@ -22,6 +22,9 @@ clib_error_t *pcap_write (pcap_main_t * pm);
/** Read data from file. */
clib_error_t *pcap_read (pcap_main_t * pm);
+/** Close the file created by pcap_write function. */
+clib_error_t *pcap_close (pcap_main_t * pm);
+
/**
* @brief Add packet
*