interface: use the correct condition for checking if the pcap fd is open 93/21993/4
authorAndrew Yourtchenko <ayourtch@gmail.com>
Wed, 11 Sep 2019 14:14:43 +0000 (14:14 +0000)
committerDamjan Marion <dmarion@me.com>
Mon, 23 Sep 2019 12:42:38 +0000 (12:42 +0000)
The 9af7e2e87e used a comparison that fd is >= 0 to check that
the pcap needs closing. While the pcap_close() function does
reset the file descriptor to -1, the freshly initialized structure
has it equal to 0.

This causes the VPP to close stdin if the packets are being seen
on pg interface without the capture file being opened.
This triggers the vpp attempting to read from STDIN
(another bug), which results in running out of memory.

Change-Id: I11d61422701500a9b3e0dd52d59383f297d57f54
Type: fix
Fixes: 9af7e2e87e
Signed-off-by: Andrew Yourtchenko <ayourtch@gmail.com>
src/vlib/main.c
src/vnet/interface_cli.c
src/vnet/interface_output.c
src/vnet/pg/output.c

index 2df935a..f49790d 100644 (file)
@@ -2254,7 +2254,7 @@ vlib_pcap_dispatch_trace_configure (vlib_pcap_dispatch_trace_args_t * a)
          vlib_cli_output (vm, "Write %d packets to %s, and stop capture...",
                           pm->n_packets_captured, pm->file_name);
          error = pcap_write (pm);
-         if (pm->file_descriptor >= 0)
+         if (pm->flags & PCAP_MAIN_INIT_DONE)
            pcap_close (pm);
          /* Report I/O errors... */
          if (error)
index 8f1fde7..3164f7a 100644 (file)
@@ -1776,7 +1776,7 @@ vnet_pcap_dispatch_trace_configure (vnet_pcap_dispatch_trace_args_t * a)
          vlib_cli_output (vm, "Write %d packets to %s, and stop capture...",
                           pm->n_packets_captured, pm->file_name);
          error = pcap_write (pm);
-         if (pm->file_descriptor >= 0)
+         if (pm->flags & PCAP_MAIN_INIT_DONE)
            pcap_close (pm);
          /* Report I/O errors... */
          if (error)
index 1506db9..721236a 100644 (file)
@@ -1467,7 +1467,7 @@ 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)
+                 if (im->pcap_main.flags & PCAP_MAIN_INIT_DONE)
                    pcap_close (&im->pcap_main);
                  if (error)
                    clib_error_report (error);
index b5ee157..d8059fa 100644 (file)
@@ -79,7 +79,7 @@ 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
+  if ((pif->pcap_main.flags & PCAP_MAIN_INIT_DONE)
       && pif->pcap_main.n_packets_captured >=
       pif->pcap_main.n_packets_to_capture)
     pcap_close (&pif->pcap_main);