]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
pcap: improve pcap_breakloop support 8706/head
authorVictor Julien <vjulien@oisf.net>
Tue, 11 Apr 2023 09:40:35 +0000 (11:40 +0200)
committerVictor Julien <vjulien@oisf.net>
Tue, 11 Apr 2023 15:21:27 +0000 (17:21 +0200)
When pcap_breakloop has been issued on a handle, the current pcap_dispatch
call may return -2 (PCAP_ERROR_BREAK), but it can also return the number
of processed packets if lower than the desired number. So add this condition
as a check.

src/source-pcap.c

index c21f6d63641a1f140e7f9778a190b4396c08aff2..afcc70c4483252fa64c5a24c293451dbeac16b27 100644 (file)
@@ -323,7 +323,7 @@ static 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 || r == PCAP_ERROR_BREAK)) {
+        if (unlikely(r == 0 || r == PCAP_ERROR_BREAK || r < packet_q_len)) {
             if (r == PCAP_ERROR_BREAK && ptv->cb_result == TM_ECODE_FAILED) {
                 SCReturnInt(TM_ECODE_FAILED);
             }