]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
xdp: warn when using XDP emulation
authorVladimír Čunát <vladimir.cunat@nic.cz>
Thu, 12 Nov 2020 13:13:49 +0000 (14:13 +0100)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Wed, 25 Nov 2020 11:25:31 +0000 (12:25 +0100)
For simplicity we bump Knot version that's required for using XDP.
Syntax: I found no better way to split the line;
alternative: backslash in meson >= 0.50.

daemon/io.c
meson.build

index 28894da6579638b16e996b7341ab85ee3b330c36..83263387d1690aa67f04b1f3fe8cb302ba1e7964 100644 (file)
@@ -13,6 +13,7 @@
 
 #if ENABLE_XDP
        #include <libknot/xdp/xdp.h>
+       #include <net/if.h>
 #endif
 
 #include "daemon/network.h"
@@ -842,6 +843,31 @@ static void xdp_rx(uv_poll_t* handle, int status, int events)
        }
        knot_xdp_recv_finish(xhd->socket, msgs, rcvd);
 }
+/// Warn if the XDP program is running in emulated mode (XDP_SKB)
+static void xdp_warn_mode(const char *ifname)
+{
+       assert(ifname);
+       const unsigned if_index = if_nametoindex(ifname);
+       if (!if_index) {
+               kr_log_info("[xdp] warning: interface %s, unexpected error when converting its name: %s\n",
+                               ifname, strerror(errno));
+               return;
+       }
+
+       const knot_xdp_mode_t mode = knot_eth_xdp_mode(if_index);
+       switch (mode) {
+       case KNOT_XDP_MODE_FULL:
+               return;
+       case KNOT_XDP_MODE_EMUL:
+               kr_log_info("[xdp] warning: interface %s running only with XDP emulation\n",
+                               ifname);
+               return;
+       case KNOT_XDP_MODE_NONE: // enum warnings from compiler
+               break;
+       }
+       kr_log_info("[xdp] warning: interface %s running in unexpected XDP mode %d\n",
+                       ifname, (int)mode);
+}
 int io_listen_xdp(uv_loop_t *loop, struct endpoint *ep, const char *ifname)
 {
        if (!ep || !ep->handle) {
@@ -864,6 +890,7 @@ int io_listen_xdp(uv_loop_t *loop, struct endpoint *ep, const char *ifname)
        xhd->socket = NULL; // needed for some reason
        int ret = knot_xdp_init(&xhd->socket, ifname, ep->nic_queue, port,
                                KNOT_XDP_LOAD_BPF_MAYBE);
+       if (!ret) xdp_warn_mode(ifname);
 
        if (!ret) ret = uv_idle_init(loop, &xhd->tx_waker);
        if (ret) {
index 62e03bca88161e579231333fe0d694238db3fd7c..da5e34858defa6615f69dddda29b52892560a530 100644 (file)
@@ -111,7 +111,8 @@ else
 endif
 
 ### XDP: not configurable - we just check if libknot supports it
-xdp = meson.get_compiler('c').has_header('libknot/xdp/xdp.h')
+xdp = meson.get_compiler('c').has_header('libknot/xdp/xdp.h'
+    ) and libknot.version().version_compare('>= 3.0.2')
 
 ### Systemd
 systemd_files = get_option('systemd_files')