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],
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}
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;
}
#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"
}
if (iface->fd_xdp > -1) {
+#ifdef ENABLE_XDP
knot_xsk_deinit();
+#endif
}
/* Free TCP handler. */
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
}
#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 {
};
#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];
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)
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;
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 = \
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
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
"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"