From c318e386d4d495e776eed6da69d600c2d3412d24 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Thu, 12 Nov 2020 14:13:49 +0100 Subject: [PATCH] xdp: warn when using XDP emulation 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 | 27 +++++++++++++++++++++++++++ meson.build | 3 ++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/daemon/io.c b/daemon/io.c index 28894da65..83263387d 100644 --- a/daemon/io.c +++ b/daemon/io.c @@ -13,6 +13,7 @@ #if ENABLE_XDP #include + #include #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) { diff --git a/meson.build b/meson.build index 62e03bca8..da5e34858 100644 --- a/meson.build +++ b/meson.build @@ -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') -- 2.47.2