]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
xdp: conditional compilation of xdp support
authorLibor Peltan <libor.peltan@nic.cz>
Tue, 17 Dec 2019 16:02:57 +0000 (17:02 +0100)
committerDaniel Salzman <daniel.salzman@nic.cz>
Tue, 21 Apr 2020 16:43:10 +0000 (18:43 +0200)
configure.ac
src/knot/conf/tools.c
src/knot/server/server.c
src/knot/server/udp-handler.c
src/libknot/Makefile.inc
src/utils/Makefile.inc
tests/knot/test_confio.c

index aa5f6c5419c3ae500b64ee21f1ca9362f076d80c..ccaa7ce0bdb2412ad27de63b77bde35f25b8408e 100644 (file)
@@ -196,6 +196,34 @@ AS_CASE([$enable_recvmmsg],
 AS_IF([test "$enable_recvmmsg" = yes],[
    AC_DEFINE([ENABLE_RECVMMSG], [1], [Use recvmmsg().])])
 
+AC_ARG_ENABLE([xdp],
+   AS_HELP_STRING([--enable-xdp=auto|yes|no], [enable eXpress Data Path, requires libBPF [default=auto]]),
+   [], [enable_xdp=auto])
+
+AS_CASE([$enable_xdp],
+   [auto],[PKG_CHECK_MODULES([libbpf],[libbpf >= 0.0.2],[enable_xdp=yes],[enable_xdp=no])],
+   [yes],[PKG_CHECK_MODULES([libbpf],[libbpf >= 0.0.2],[enable_xdp=yes])],
+   [no],[],
+   [*],[AC_MSG_ERROR([Invalid value of --enable-xdp.])]
+)
+
+AS_IF([test "$enable_xdp" = "yes"],[
+   save_CFLAGS=$CFLAGS
+   save_LIBS=$LIBS
+   CFLAGS="$CFLAGS $libbpf_CFLAGS"
+   LIBS="$LIBS $libbpf_LIBS"
+
+   AC_CHECK_FUNC([bpf_prog_load],[],[AC_MSG_ERROR([bpf_prog_load not available])])
+   AC_CHECK_FUNC([bpf_set_link_xdp_fd],[],[AC_MSG_ERROR([bpf_set_link_xdp_fd not available])])
+
+   CFLAGS=$save_CFLAGS
+   LIBS=$save_LIBS
+
+   AC_DEFINE([ENABLE_XDP], [1], [Use eXpress Data Path.])
+])
+
+AM_CONDITIONAL([ENABLE_XDP], [test "$enable_xdp" = "yes"])
+
 # Reuseport support
 AS_CASE([$host_os],
   [freebsd*], [reuseport_opt=SO_REUSEPORT_LB],
@@ -713,6 +741,7 @@ result_msg_base="  Knot DNS $VERSION
 
     Use recvmmsg:           ${enable_recvmmsg}
     Use SO_REUSEPORT(_LB):  ${enable_reuseport}
+    Use XDP:                ${enable_xdp}
     Memory allocator:       ${with_memory_allocator}
     Fast zone parser:       ${enable_fastparser}
     Utilities with IDN:     ${with_libidn}
index 833ccc99596889ae7fcfaf32d54b11e66096e5ad..276987c94e9f68c8e5a0eb6a8549d8f9c786fbf9 100644 (file)
@@ -312,6 +312,13 @@ int check_server(
        CHECK_LEGACY_NAME(C_SRV, C_MAX_IPV4_UDP_PAYLOAD, C_UDP_MAX_PAYLOAD_IPV4);
        CHECK_LEGACY_NAME(C_SRV, C_MAX_IPV6_UDP_PAYLOAD, C_UDP_MAX_PAYLOAD_IPV6);
 
+#ifndef ENABLE_XDP
+       if (conf_xdp_threads_txn(args->extra->conf, args->extra->txn) > 0) {
+               args->err_str = "not compiled with XDP support";
+               return KNOT_EINVAL;
+       }
+#endif
+
        return KNOT_EOK;
 }
 
index 3c2b66a448bcdf2d64ce30c4b124a5a29e481e6a..a039c6f87f511e534dc51b6dd9792fd93922452f 100644 (file)
@@ -22,7 +22,9 @@
 #include <sys/resource.h>
 
 #include "libknot/errcode.h"
+#ifdef ENABLE_XDP
 #include "libknot/xdp/af_xdp.h"
+#endif
 #include "libknot/yparser/ypschema.h"
 #include "knot/common/log.h"
 #include "knot/common/stats.h"
@@ -65,7 +67,9 @@ static void server_deinit_iface(iface_t *iface)
        }
 
        if (iface->fd_xdp > -1) {
+#ifdef ENABLE_XDP
                knot_xsk_deinit();
+#endif
        }
 
        /* Free TCP handler. */
@@ -294,12 +298,16 @@ static iface_t *server_init_iface(struct sockaddr_storage *addr,
 
        new_if->fd_xdp = -1;
        if (use_xdp) {
-               int ret = knot_xsk_init("enp0s8", "/bpf-kernel.o", NULL); // FIXME
+#ifndef ENABLE_XDP
+               assert(0);
+#else
+               int ret = knot_xsk_init("enp1s0f1", "/bpf-kernel.o", NULL); // FIXME
                if (ret != KNOT_EOK) {
                        log_warning("failed to init XDP (%s)", knot_strerror(ret));
                } else {
                        new_if->fd_xdp = knot_xsk_get_poll_fd();
                }
+#endif
        }
 
 
index a0a205ce2f239477e43df98746d94e68e1450734..d83f480fd8b2846db0522e5e923986dbdc623495 100644 (file)
@@ -38,8 +38,9 @@
 #include "knot/query/layer.h"
 #include "knot/server/server.h"
 #include "knot/server/udp-handler.h"
-
+#ifdef ENABLE_XDP
 #include "libknot/xdp/af_xdp.h"
+#endif /* ENABLE_XDP */
 
 /* Buffer identifiers. */
 enum {
@@ -358,6 +359,8 @@ static udp_api_t udp_recvmmsg_api = {
 };
 #endif /* ENABLE_RECVMMSG */
 
+#ifdef ENABLE_XDP
+
 struct xdp_recvmmsg {
        knot_xsk_msg_t msgs_rx[XDP_BATCHLEN];
        knot_xsk_msg_t msgs_tx[XDP_BATCHLEN];
@@ -444,6 +447,7 @@ static udp_api_t xdp_recvmmsg_api = {
        xdp_recvmmsg_handle,
        xdp_recvmmsg_send
 };
+#endif /* ENABLE_XDP */
 
 /*! \brief Get interface UDP descriptor for a given thread. */
 static int iface_udp_fd(const iface_t *iface, int thread_id, bool use_xdp)
@@ -515,7 +519,11 @@ int udp_master(dthread_t *thread)
        iohandler_t *handler = (iohandler_t *)thread->data;
        udp_api_t *api = NULL;
        if (handler->use_xdp) {
+#ifndef ENABLE_XDP
+               assert(0);
+#else
                api = &xdp_recvmmsg_api;
+#endif
        } else {
 #ifdef ENABLE_RECVMMSG
                api = &udp_recvmmsg_api;
index 8fe9cf4280bae403272f62427aac85131fa1ab72..827ed92b176bc0a6a2c3b85238fd66a6db9a39dc 100644 (file)
@@ -1,9 +1,9 @@
 lib_LTLIBRARIES += libknot.la
 pkgconfig_DATA  += libknot.pc
 
-libknot_la_CPPFLAGS = $(AM_CPPFLAGS) $(CFLAG_VISIBILITY) $(lmdb_CFLAGS)
+libknot_la_CPPFLAGS = $(AM_CPPFLAGS) $(CFLAG_VISIBILITY) $(lmdb_CFLAGS) $(libbpf_CFLAGS)
 libknot_la_LDFLAGS  = $(AM_LDFLAGS) $(libknot_VERSION_INFO) $(LDFLAG_EXCLUDE_LIBS)
-libknot_la_LIBADD   = libcontrib.la libdnssec.la $(math_LIBS) $(lmdb_LIBS)
+libknot_la_LIBADD   = libcontrib.la libdnssec.la $(math_LIBS) $(lmdb_LIBS) $(libbpf_LIBS)
 
 include_libknotdir = $(includedir)
 nobase_include_libknot_HEADERS = \
@@ -72,11 +72,15 @@ libknot_la_SOURCES = \
        libknot/rrtype/tsig.c                   \
        libknot/tsig-op.c                       \
        libknot/tsig.c                          \
-       libknot/xdp/af_xdp.c                    \
-       libknot/xdp/bpf-kernel.c                \
-       libknot/xdp/bpf-user.c                  \
        libknot/yparser/yparser.c               \
        libknot/yparser/ypbody.c                \
        libknot/yparser/ypformat.c              \
        libknot/yparser/ypschema.c              \
        libknot/yparser/yptrafo.c
+
+if ENABLE_XDP
+libknot_la_SOURCES += \
+       libknot/xdp/af_xdp.c                    \
+        libknot/xdp/bpf-kernel.c                \
+        libknot/xdp/bpf-user.c
+endif ENABLE_XDP
index e6765d91df3dc50e189ab438dc9c7aa6ff43907c..8c1424ddcac261edd71552410f96b0e0ad4b6c42 100644 (file)
@@ -66,7 +66,7 @@ kdig_LDADD             = libknotus.la
 khost_CPPFLAGS         = $(AM_CPPFLAGS) $(gnutls_CFLAGS)
 khost_LDADD            = libknotus.la
 knsec3hash_CPPFLAGS    = $(AM_CPPFLAGS)
-knsec3hash_LDADD       = libcontrib.la libdnssec.la libknot.la
+knsec3hash_LDADD       = libcontrib.la libdnssec.la libknot.la $(libbpf_LIBS)
 knsupdate_CPPFLAGS     = $(AM_CPPFLAGS) $(gnutls_CFLAGS)
 knsupdate_LDADD        = libknotus.la libzscanner.la
 
index 8e2c06c0abd9a791ed2e8e6230687bdf028d0e68..aec2ae12f549f8a27eb76dbdfef3573943ad8eda 100644 (file)
@@ -909,6 +909,7 @@ static void test_conf_io_list(void)
              "server.tcp-max-clients\n"
              "server.tcp-reuseport\n"
              "server.udp-workers\n"
+             "server.xdp-workers\n"
              "server.tcp-workers\n"
              "server.background-workers\n"
              "server.udp-max-payload\n"