]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
ebpf: update deprecated API calls
authorSascha Steinbiss <satta@debian.org>
Thu, 15 Sep 2022 13:57:13 +0000 (13:57 +0000)
committerVictor Julien <vjulien@oisf.net>
Tue, 20 Sep 2022 12:55:24 +0000 (14:55 +0200)
This fixes build errors when libbpf 1.0 is used. It removes previously
deprecated API functions that were still in use in Suricata's eBPF
code.

configure.ac
src/util-ebpf.c

index 05a18ee92af61f413f304d52e6256a77e046cefe..6a28ea10b9ab1a6e0514cd10e0723a6707ffb440 100644 (file)
             AC_DEFINE([HAVE_PACKET_EBPF],[1],[Recent ebpf fanout support is available]),
             [],
             [[#include <linux/if_packet.h>]])
-        AC_CHECK_LIB(bpf, bpf_set_link_xdp_fd,have_xdp="yes")
+        # Check for XDP specific function.
+        AC_CHECK_LIB(bpf,bpf_xdp_attach,have_xdp="yes")
         if test "$have_xdp" = "yes"; then
             AC_DEFINE([HAVE_PACKET_XDP],[1],[XDP support is available])
+        else
+            # Check for legacy XDP function.
+            AC_CHECK_LIB(bpf,bpf_set_link_xdp_fd,have_xdp="yes")
+            if test "$have_xdp" = "yes"; then
+                AC_DEFINE([HAVE_PACKET_XDP],[1],[XDP support is available])
+            fi
         fi
-        AC_CHECK_FUNCS(bpf_program__section_name)
+        AC_CHECK_FUNCS([bpf_program__section_name bpf_xdp_attach bpf_program__set_type])
     fi;
 
   # Check for DAG support.
index 407a436013dc7b151a1b8261eb3606fe6af75ab7..2d7b0ad22093bd8d20470de50a34714a7f0fa281 100644 (file)
@@ -373,9 +373,19 @@ int EBPFLoadFile(const char *iface, const char *path, const char * section,
 #endif
         if (!strcmp(title, section)) {
             if (config->flags & EBPF_SOCKET_FILTER) {
+#ifdef HAVE_BPF_PROGRAM__SET_TYPE
+                bpf_program__set_type(bpfprog, BPF_PROG_TYPE_SOCKET_FILTER);
+#else
+                /* Fall back to legacy API */
                 bpf_program__set_socket_filter(bpfprog);
+#endif
             } else {
+#ifdef HAVE_BPF_PROGRAM__SET_TYPE
+                bpf_program__set_type(bpfprog, BPF_PROG_TYPE_XDP);
+#else
+                /* Fall back to legacy API */
                 bpf_program__set_xdp(bpfprog);
+#endif
             }
             found = true;
             break;
@@ -489,7 +499,12 @@ int EBPFSetupXDP(const char *iface, int fd, uint8_t flags)
                 "Unknown interface '%s'", iface);
         return -1;
     }
+#ifdef HAVE_BPF_XDP_ATTACH
+    int err = bpf_xdp_attach(ifindex, fd, flags, NULL);
+#else
+    /* Fall back to legacy API */
     int err = bpf_set_link_xdp_fd(ifindex, fd, flags);
+#endif
     if (err != 0) {
         char buf[129];
         libbpf_strerror(err, buf, sizeof(buf));