]> git.ipfire.org Git - people/ms/suricata.git/commitdiff
Handle failing thread modules that are called by the Pcap file callback.
authorVictor Julien <victor@inliniac.net>
Wed, 26 Oct 2011 13:30:21 +0000 (15:30 +0200)
committerVictor Julien <victor@inliniac.net>
Wed, 26 Oct 2011 13:30:21 +0000 (15:30 +0200)
src/source-pcap-file.c

index fa9dc05830a6b6ff02153c7cdadbde84e79e40cf..8dc0e06931e12b1c69bbeef369be7c528f7e04f4 100644 (file)
@@ -71,6 +71,9 @@ typedef struct PcapFileThreadVars_
     ThreadVars *tv;
     TmSlot *slot;
 
+    /** callback result -- set if one of the thread module failed. */
+    int cb_result;
+
     uint8_t done;
     uint32_t errs;
 } PcapFileThreadVars;
@@ -134,7 +137,10 @@ void PcapFileCallbackLoop(char *user, struct pcap_pkthdr *h, u_char *pkt) {
         SCReturn;
     }
 
-    TmThreadsSlotProcessPkt(ptv->tv, ptv->slot, p);
+    if (TmThreadsSlotProcessPkt(ptv->tv, ptv->slot, p) != TM_ECODE_OK) {
+        pcap_breakloop(pcap_g.pcap_handle);
+        ptv->cb_result = TM_ECODE_FAILED;
+    }
 
     SCReturn;
 }
@@ -147,6 +153,7 @@ TmEcode ReceivePcapFileLoop(ThreadVars *tv, void *data, void *slot) {
     PcapFileThreadVars *ptv = (PcapFileThreadVars *)data;
     TmSlot *s = (TmSlot *)slot;
     ptv->slot = s->slot_next;
+    ptv->cb_result = TM_ECODE_OK;
     int r;
 
     SCEnter();
@@ -170,7 +177,7 @@ TmEcode ReceivePcapFileLoop(ThreadVars *tv, void *data, void *slot) {
         /* Right now we just support reading packets one at a time. */
         r = pcap_dispatch(pcap_g.pcap_handle, (int)packet_q_len,
                 (pcap_handler)PcapFileCallbackLoop, (u_char *)ptv);
-        if (unlikely(r < 0)) {
+        if (unlikely(r == -1)) {
             SCLogError(SC_ERR_PCAP_DISPATCH, "error code %" PRId32 " %s",
                     r, pcap_geterr(pcap_g.pcap_handle));
 
@@ -182,6 +189,10 @@ TmEcode ReceivePcapFileLoop(ThreadVars *tv, void *data, void *slot) {
 
             EngineStop();
             break;
+        } else if (ptv->cb_result == TM_ECODE_FAILED) {
+            SCLogError(SC_ERR_PCAP_DISPATCH, "Pcap callback PcapFileCallbackLoop failed");
+            EngineKill();
+            SCReturnInt(TM_ECODE_FAILED);
         }
         SCPerfSyncCountersIfSignalled(tv, 0);
     }