netmap: use custom BPF compile function

pull/3567/head
Eric Leblond 7 years ago
parent 28e9e4c85c
commit 017acaa465

@ -30,6 +30,7 @@
* *
*/ */
#include "suricata-common.h" #include "suricata-common.h"
#include "config.h" #include "config.h"
#include "suricata.h" #include "suricata.h"
@ -42,6 +43,7 @@
#include "tm-threads.h" #include "tm-threads.h"
#include "tm-threads-common.h" #include "tm-threads-common.h"
#include "conf.h" #include "conf.h"
#include "util-bpf.h"
#include "util-debug.h" #include "util-debug.h"
#include "util-device.h" #include "util-device.h"
#include "util-error.h" #include "util-error.h"
@ -616,15 +618,19 @@ static TmEcode ReceiveNetmapThreadInit(ThreadVars *tv, const void *initdata, voi
if (aconf->in.bpf_filter) { if (aconf->in.bpf_filter) {
SCLogConfig("Using BPF '%s' on iface '%s'", SCLogConfig("Using BPF '%s' on iface '%s'",
aconf->in.bpf_filter, ntv->ifsrc->ifname); 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 */ LINKTYPE_ETHERNET, /* linktype_arg */
&ntv->bpf_prog, /* program */ &ntv->bpf_prog, /* program */
aconf->in.bpf_filter, /* const char *buf */ aconf->in.bpf_filter, /* const char *buf */
1, /* optimize */ 1, /* optimize */
PCAP_NETMASK_UNKNOWN /* mask */ PCAP_NETMASK_UNKNOWN, /* mask */
) == -1) 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; goto error_dst;
} }
} }
@ -952,7 +958,7 @@ static TmEcode ReceiveNetmapThreadDeinit(ThreadVars *tv, void *data)
ntv->ifdst = NULL; ntv->ifdst = NULL;
} }
if (ntv->bpf_prog.bf_insns) { if (ntv->bpf_prog.bf_insns) {
pcap_freecode(&ntv->bpf_prog); SCBPFFree(&ntv->bpf_prog);
} }
SCReturnInt(TM_ECODE_OK); SCReturnInt(TM_ECODE_OK);

Loading…
Cancel
Save