Skip to content

Commit

Permalink
Fixed seladb#1635 xsk.h should be taken from libxdp
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxnox committed Feb 1, 2025
1 parent 3af7383 commit c654d4d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
1 change: 1 addition & 0 deletions Pcap++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ target_link_libraries(
$<$<BOOL:${PCAPPP_USE_PF_RING}>:PF_RING::PF_RING>
$<$<BOOL:${PCAPPP_USE_DPDK}>:DPDK::DPDK>
$<$<BOOL:${PCAPPP_USE_XDP}>:BPF::BPF>
$<$<BOOL:${PCAPPP_USE_XDP}>:XDP::XDP>
PCAP::PCAP
Threads::Threads
)
Expand Down
2 changes: 1 addition & 1 deletion Pcap++/src/XdpDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "Logger.h"
#include "Packet.h"
#include <bpf/libbpf.h>
#include <bpf/xsk.h>
#include <xdp/xsk.h>
#include <linux/if_link.h>
#include <net/if.h>
#include <sys/mman.h>
Expand Down
34 changes: 34 additions & 0 deletions cmake/modules/FindXDP.cmake
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit c654d4d

Please sign in to comment.