util-ebpf: add call to remove memlock limit

Without that, user has to use ulimit to be able to load the eBPF
file.
pull/3221/head
Eric Leblond 7 years ago
parent a229635792
commit 43ecf0d78d

@ -37,6 +37,9 @@
#ifdef HAVE_PACKET_EBPF
#include <sys/time.h>
#include <sys/resource.h>
#include "util-ebpf.h"
#include "util-cpu.h"
@ -100,6 +103,15 @@ int EBPFLoadFile(const char *path, const char * section, int *val, uint8_t flags
return -1;
}
/* Sending the eBPF code to the kernel requires a large amount of
* locked memory so we set it to unlimited to avoid a ENOPERM error */
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
if (setrlimit(RLIMIT_MEMLOCK, &r) != 0) {
SCLogError(SC_ERR_MEM_ALLOC, "Unable to lock memory: %s (%d)",
strerror(errno), errno);
return -1;
}
bpfobj = bpf_object__open(path);
if (libbpf_get_error(bpfobj)) {
@ -137,8 +149,8 @@ int EBPFLoadFile(const char *path, const char * section, int *val, uint8_t flags
if (err < 0) {
if (err == -EPERM) {
SCLogError(SC_ERR_MEM_ALLOC,
"Permission issue when loading eBPF object try to "
"increase memlock limit: %s (%d)",
"Permission issue when loading eBPF object: "
"%s (%d)",
strerror(err),
err);
} else {

Loading…
Cancel
Save