interface: 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()

The automatic cherrypick did not work, so
the manual cherrypick of commit 9af7e2e87e6a11fb69309fc9ce4432acbc4e3
was performed as follows:

0) git checkout stable/1908
1) git checkout -b stable-1908-history-rewrite
2) git rebase -i d1e17d00bb81659bf9e45caa62482bf7029d98f7~1
3) in the editor, mark the second commit as "edit", search for the following commits
   and edit as in the snippet below:

  edit 30d28bdfd api: enforce vla is last and fixed string type
  drop 4c19bfd93 vlib: clean up the "pcap dispatch trace" debug CLI
  pick 4aef0dd82 dpdk: fix extended stats
  edit 1dafb7fd8 dpdk: initialize rte_mbuf during mempool dequeue
  drop 4b943d632 misc: clean up "pcap [rx|tx] trace" debug CLI

4) close the editor
5) git cherry-pick 9af7e2e87e
   (it applies cleanly)
6) git rebase --continue
   (rebase of a 1000+ patches)
7) at prompt - git cherry-pick -x e5948fb49a
8) git rebase --continue
9) at prompt - git cherry-pick -x b97641c79f
10) git rebase --continue
11) the rebase finished.
12) git checkout stable/1908
13) git diff stable/1908..stable-1908-history-rewrite | patch -p1
14) discard the whitespace-only hunk
15) git commit -a -s; edit this commit message

Type: fix
Change-Id: Iedeb46f9cf0a4cb12449fd75a4014f95f3bb3fa8
Signed-off-by: Jack Xu <jack.c.xu@ericsson.com>
Signed-off-by: Andrew Yourtchenko <ayourtch@gmail.com>
This commit is contained in:
Andrew Yourtchenko
2019-09-24 22:54:02 +00:00
committed by Damjan Marion
parent 662aa2f853
commit cbc5e50caf
3 changed files with 6 additions and 4 deletions

View File

@@ -1441,6 +1441,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)
{