]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
source-xdp: only allow busy poll if headers support it
authorJason Ish <jason.ish@oisf.net>
Thu, 9 Feb 2023 17:16:18 +0000 (11:16 -0600)
committerVictor Julien <vjulien@oisf.net>
Fri, 17 Mar 2023 10:15:22 +0000 (11:15 +0100)
Wrap the enabling of busy poll in a compile time conditional checking
for the required defines to be set. While we have runtime support for
kernels less than 5.11, we also need a compile time check as the headers
may be old as well.

Issue: 5855

src/source-af-xdp.c

index 108cfba7917d8e45fcc53a6b025a46d7fb64cacd..287a15a9974e4d126c61924e14b1808c9dd46dfe 100644 (file)
@@ -379,9 +379,6 @@ static TmEcode WriteLinuxTunables(AFXDPThreadVars *ptv)
 
 static TmEcode ConfigureBusyPolling(AFXDPThreadVars *ptv)
 {
-    const int fd = xsk_socket__fd(ptv->xsk.xsk);
-    int sock_opt = 1;
-
     if (!ptv->xsk.enable_busy_poll) {
         SCReturnInt(TM_ECODE_OK);
     }
@@ -395,6 +392,10 @@ static TmEcode ConfigureBusyPolling(AFXDPThreadVars *ptv)
         SCReturnInt(TM_ECODE_FAILED);
     }
 
+#if defined SO_PREFER_BUSY_POLL && defined SO_BUSY_POLL && defined SO_BUSY_POLL_BUDGET
+    const int fd = xsk_socket__fd(ptv->xsk.xsk);
+    int sock_opt = 1;
+
     if (WriteLinuxTunables(ptv) != TM_ECODE_OK) {
         SCReturnInt(TM_ECODE_FAILED);
     }
@@ -414,6 +415,11 @@ static TmEcode ConfigureBusyPolling(AFXDPThreadVars *ptv)
     }
 
     SCReturnInt(TM_ECODE_OK);
+#else
+    SCLogWarning(
+            "Kernel does not support busy poll, upgrade kernel or disable \"enable-busy-poll\".");
+    SCReturnInt(TM_ECODE_FAILED);
+#endif
 }
 
 static void AFXDPSwitchState(AFXDPThreadVars *ptv, int state)