]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
netmap: use custom BPF compile function
authorEric Leblond <eric@regit.org>
Wed, 10 Oct 2018 22:17:59 +0000 (00:17 +0200)
committerEric Leblond <eric@regit.org>
Mon, 3 Dec 2018 16:46:33 +0000 (17:46 +0100)
src/source-netmap.c

index 9521e7bedeaab6b0ba99e8935dcbf944c2900c2d..d0340b7b9d26695f5311e315a00a7248d598c4b1 100644 (file)
@@ -30,6 +30,7 @@
 *
 */
 
+
 #include "suricata-common.h"
 #include "config.h"
 #include "suricata.h"
@@ -42,6 +43,7 @@
 #include "tm-threads.h"
 #include "tm-threads-common.h"
 #include "conf.h"
+#include "util-bpf.h"
 #include "util-debug.h"
 #include "util-device.h"
 #include "util-error.h"
@@ -616,15 +618,19 @@ static TmEcode ReceiveNetmapThreadInit(ThreadVars *tv, const void *initdata, voi
     if (aconf->in.bpf_filter) {
         SCLogConfig("Using BPF '%s' on iface '%s'",
                   aconf->in.bpf_filter, ntv->ifsrc->ifname);
-        if (pcap_compile_nopcap(default_packet_size,  /* snaplen_arg */
+        char errbuf[PCAP_ERRBUF_SIZE];
+        if (SCBPFCompile(default_packet_size,  /* snaplen_arg */
                     LINKTYPE_ETHERNET,    /* linktype_arg */
                     &ntv->bpf_prog,       /* program */
                     aconf->in.bpf_filter, /* const char *buf */
                     1,                    /* optimize */
-                    PCAP_NETMASK_UNKNOWN  /* mask */
-                    ) == -1)
+                    PCAP_NETMASK_UNKNOWN,  /* mask */
+                    errbuf,
+                    sizeof(errbuf)) == -1)
         {
-            SCLogError(SC_ERR_NETMAP_CREATE, "Filter compilation failed.");
+            SCLogError(SC_ERR_NETMAP_CREATE, "Failed to compile BPF \"%s\": %s",
+                   aconf->in.bpf_filter,
+                   errbuf);
             goto error_dst;
         }
     }
@@ -952,7 +958,7 @@ static TmEcode ReceiveNetmapThreadDeinit(ThreadVars *tv, void *data)
         ntv->ifdst = NULL;
     }
     if (ntv->bpf_prog.bf_insns) {
-        pcap_freecode(&ntv->bpf_prog);
+        SCBPFFree(&ntv->bpf_prog);
     }
 
     SCReturnInt(TM_ECODE_OK);