fix pcap_write function

when use pcap cli to capture pcakets into two files rx01.pcap && rx02.pcap,
the first time:
1)pcap rx trace on max 100 intfc any file rx01.pcap
2)......the process of capture data to buffer......
3)pcap rx trace off

the second time:
4)pcap rx trace on max 100 intfc any file rx02.pcap
5)......the process of capture data to buffer......
6)pcap rx trace off

the pcap_write function bug in this two lines
pm->n_packets_captured = 0;
if (pm->n_packets_captured >= pm->n_packets_to_capture) referring to calling pcap_close()
will result in that the twice pcap cli both writes the packets
into rx01.pcap, but nothing into rx02.pcap. Beside, the rx02.pcap
file will not be created.

solution: separate the pcap_close() out of pcap_write()

Change-Id: Iedeb46f9cf0a4cb12449fd75a4014f95f3bb3fa8
Signed-off-by: Jack Xu <jack.c.xu@ericsson.com>
This commit is contained in:
Jack Xu
2019-03-27 11:51:32 -04:00
committed by Damjan Marion
parent 053204ab03
commit 9af7e2e87e
6 changed files with 13 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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))

View File

@ -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)
{

View File

@ -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
*