diff --git a/CMakeLists.txt b/CMakeLists.txt index 78e03653ca..d0d4424fd8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -235,6 +235,10 @@ if(PCAPPP_USE_XDP) if(NOT BPF_FOUND) message(FATAL_ERROR "libbpf not found!") endif() + find_package(XDP) + if(NOT XDP_FOUND) + message(FATAL_ERROR "libxdp not found!") + endif() add_definitions(-DUSE_XDP) endif() diff --git a/Pcap++/CMakeLists.txt b/Pcap++/CMakeLists.txt index 7eb772b142..5ac41f223c 100644 --- a/Pcap++/CMakeLists.txt +++ b/Pcap++/CMakeLists.txt @@ -89,6 +89,7 @@ target_link_libraries( $<$:PF_RING::PF_RING> $<$:DPDK::DPDK> $<$:BPF::BPF> + $<$:XDP::XDP> PCAP::PCAP Threads::Threads ) diff --git a/Pcap++/src/XdpDevice.cpp b/Pcap++/src/XdpDevice.cpp index 04378bcbf2..2ebe26e12a 100644 --- a/Pcap++/src/XdpDevice.cpp +++ b/Pcap++/src/XdpDevice.cpp @@ -5,7 +5,7 @@ #include "Logger.h" #include "Packet.h" #include -#include +#include #include #include #include diff --git a/cmake/modules/FindXDP.cmake b/cmake/modules/FindXDP.cmake new file mode 100644 index 0000000000..98a2b4af20 --- /dev/null +++ b/cmake/modules/FindXDP.cmake @@ -0,0 +1,34 @@ +# ~~~ +# - Try to find libxdp +# +# Once done this will define +# +# XDP_FOUND - System has libxdp +# XDP_INCLUDE_DIRS - The libxdp include directories +# XDP_LIBRARIES - The libraries needed to use libxdp +# ~~~ + +find_package(PkgConfig QUIET) +pkg_check_modules(PC_LIBBPF libxdp) + +find_path( + XDP_INCLUDE_DIRS + NAMES xdp/xsk.h + HINTS ${PC_LIBXDP_INCLUDE_DIRS}) + +find_library( + XDP + NAMES xdp + HINTS ${PC_LIBXDP_LIBRARY_DIRS}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + XDP + REQUIRED_VARS XDP XDP_INCLUDE_DIRS + VERSION_VAR XDP_VERSION + FAIL_MESSAGE "libxdp not found!") + +if(XDP_FOUND AND NOT TARGET XDP::XDP) + add_library(XDP::XDP INTERFACE IMPORTED) + set_target_properties(XDP::XDP PROPERTIES INTERFACE_LINK_LIBRARIES "${XDP_LIBRARIES}" INTERFACE_INCLUDE_DIRECTORIES "${XDP_INCLUDE_DIRS}") +endif()