From 017acaa4654abbf69abafd5a0170fee69ff1d530 Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Thu, 11 Oct 2018 00:17:59 +0200 Subject: [PATCH] netmap: use custom BPF compile function --- src/source-netmap.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/source-netmap.c b/src/source-netmap.c index 9521e7bede..d0340b7b9d 100644 --- a/src/source-netmap.c +++ b/src/source-netmap.c @@ -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);