From: Victor Julien Date: Wed, 5 Jun 2019 20:06:08 +0000 (+0200) Subject: pcap: fix breakloop error handling X-Git-Tag: suricata-5.0.0-rc1~168 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F4067%2Fhead;p=thirdparty%2Fsuricata.git pcap: fix breakloop error handling Ticket #3004 --- diff --git a/src/source-pcap.c b/src/source-pcap.c index a947383f13..0c078748a7 100644 --- a/src/source-pcap.c +++ b/src/source-pcap.c @@ -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);