From: Eric Leblond Date: Sun, 24 Feb 2019 22:57:04 +0000 (+0100) Subject: af-packet: correctly set up hardware offload X-Git-Tag: suricata-5.0.0-rc1~371 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0c3e1e85799232251fc262c3c68756dd3694cd8a;p=thirdparty%2Fsuricata.git af-packet: correctly set up hardware offload --- diff --git a/src/runmode-af-packet.c b/src/runmode-af-packet.c index 40b8d8fd59..8367928167 100644 --- a/src/runmode-af-packet.c +++ b/src/runmode-af-packet.c @@ -494,6 +494,7 @@ static void *ParseAFPConfig(const char *iface) aconf->xdp_mode = XDP_FLAGS_DRV_MODE; } else if (!strcmp(xdp_mode, "hw")) { aconf->xdp_mode = XDP_FLAGS_HW_MODE; + aconf->ebpf_t_config.flags |= EBPF_XDP_HW_MODE; } else { SCLogWarning(SC_ERR_INVALID_VALUE, "Invalid xdp-mode value: '%s'", xdp_mode); diff --git a/src/util-ebpf.c b/src/util-ebpf.c index 28e9da158d..2ae5cbaeb7 100644 --- a/src/util-ebpf.c +++ b/src/util-ebpf.c @@ -310,6 +310,16 @@ int EBPFLoadFile(const char *iface, const char *path, const char * section, return -1; } + if (config->flags & EBPF_XDP_HW_MODE) { + unsigned int ifindex = if_nametoindex(iface); + bpf_object__for_each_program(bpfprog, bpfobj) { + bpf_program__set_ifindex(bpfprog, ifindex); + } + bpf_map__for_each(map, bpfobj) { + bpf_map__set_ifindex(map, ifindex); + } + } + /* Let's check that our section is here */ bpf_object__for_each_program(bpfprog, bpfobj) { const char *title = bpf_program__title(bpfprog, 0); diff --git a/src/util-ebpf.h b/src/util-ebpf.h index 5adf75e2c2..53ca562ac9 100644 --- a/src/util-ebpf.h +++ b/src/util-ebpf.h @@ -64,6 +64,7 @@ struct pair { #define EBPF_SOCKET_FILTER (1<<0) #define EBPF_XDP_CODE (1<<1) #define EBPF_PINNED_MAPS (1<<2) +#define EBPF_XDP_HW_MODE (1<<3) int EBPFGetMapFDByName(const char *iface, const char *name); int EBPFLoadFile(const char *iface, const char *path, const char * section,