]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
pcap: fix breakloop error handling 4067/head
authorVictor Julien <victor@inliniac.net>
Wed, 5 Jun 2019 20:06:08 +0000 (22:06 +0200)
committerVictor Julien <victor@inliniac.net>
Mon, 22 Jul 2019 11:46:03 +0000 (13:46 +0200)
Ticket #3004

src/source-pcap.c

index a947383f136f3af3f6b92ce55d60dbb937894ccc..0c078748a74a957d69399ab08df1c1143b7d9e1d 100644 (file)
@@ -233,6 +233,10 @@ static void PcapCallbackLoop(char *user, struct pcap_pkthdr *h, u_char *pkt)
     SCReturn;
 }
 
+#ifndef PCAP_ERROR_BREAK
+#define PCAP_ERROR_BREAK -2
+#endif
+
 /**
  *  \brief Main PCAP reading Loop function
  */
@@ -258,15 +262,15 @@ TmEcode ReceivePcapLoop(ThreadVars *tv, void *data, void *slot)
 
         int r = pcap_dispatch(ptv->pcap_handle, packet_q_len,
                           (pcap_handler)PcapCallbackLoop, (u_char *)ptv);
-        if (unlikely(r < 0)) {
+        if (unlikely(r == 0 || r == PCAP_ERROR_BREAK)) {
+            if (r == PCAP_ERROR_BREAK && ptv->cb_result == TM_ECODE_FAILED) {
+                SCReturnInt(TM_ECODE_FAILED);
+            }
+            TmThreadsCaptureHandleTimeout(tv, ptv->slot, NULL);
+        } else if (unlikely(r < 0)) {
             int dbreak = 0;
             SCLogError(SC_ERR_PCAP_DISPATCH, "error code %" PRId32 " %s",
                        r, pcap_geterr(ptv->pcap_handle));
-#ifdef PCAP_ERROR_BREAK
-            if (r == PCAP_ERROR_BREAK) {
-                SCReturnInt(ptv->cb_result);
-            }
-#endif
             do {
                 usleep(PCAP_RECONNECT_TIMEOUT);
                 if (suricata_ctl_flags != 0) {
@@ -281,8 +285,6 @@ TmEcode ReceivePcapLoop(ThreadVars *tv, void *data, void *slot)
         } else if (ptv->cb_result == TM_ECODE_FAILED) {
             SCLogError(SC_ERR_PCAP_DISPATCH, "Pcap callback PcapCallbackLoop failed");
             SCReturnInt(TM_ECODE_FAILED);
-        } else if (unlikely(r == 0)) {
-            TmThreadsCaptureHandleTimeout(tv, ptv->slot, NULL);
         }
 
         StatsSyncCountersIfSignalled(tv);