]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
af-packet: correctly set up hardware offload
authorEric Leblond <eric@regit.org>
Sun, 24 Feb 2019 22:57:04 +0000 (23:57 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 18 Jun 2019 05:07:02 +0000 (07:07 +0200)
src/runmode-af-packet.c
src/util-ebpf.c
src/util-ebpf.h

index 40b8d8fd5917c57caf128b19a9fc71de957cad62..836792816730957fe601ae2ff9fcba85b150da31 100644 (file)
@@ -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);
index 28e9da158dedbaa8aa0b723fc1a5915d1e1fcd6a..2ae5cbaeb7d073e109e6a23fe56791f1e7c6fc3e 100644 (file)
@@ -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);
index 5adf75e2c233d4db3371088b1a13aa89528deaae..53ca562ac911034b2cf7fc18670fe817a84c4429 100644 (file)
@@ -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,