Skip to content

Commit

Permalink
Introduce XDP device (#1228)
Browse files Browse the repository at this point in the history
  • Loading branch information
seladb authored Nov 14, 2023
1 parent a0ecc6d commit 452a53a
Show file tree
Hide file tree
Showing 13 changed files with 1,377 additions and 1 deletion.
36 changes: 36 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -532,3 +532,39 @@ jobs:
sed -i.bak "s|abiFilters.*$|abiFilters '${{ matrix.target }}'|g" app/build.gradle
chmod +x gradlew
./gradlew assembleDebug
xdp:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install dependencies
run: |
sudo apt update && sudo apt -y install libpcap-dev libbpf-dev tcpreplay
- name: Configure PcapPlusPlus
run: cmake -DPCAPPP_USE_XDP=ON -S . -B $BUILD_DIR

- name: Build PcapPlusPlus
run: cmake --build $BUILD_DIR -j

- name: Test PcapPlusPlus
run: |
python -m pip install -U pip
python -m pip install -r ci/run_tests/requirements.txt
python ci/run_tests/run_tests.py --interface eth0 --use-sudo --pcap-test-args="-t xdp"
- name: Create Cobertura Report
run: |
python -m pip install gcovr
gcovr -v -r . $GCOVR_FLAGS -o coverage.xml
- name: Upload Coverage Results
uses: codecov/codecov-action@v3
with:
files: ./coverage.xml
flags: xdp,unittest
fail_ci_if_error: false
verbose: true
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ cmake_dependent_option(
"PCAPPP_USE_DPDK"
OFF)
option(PCAPPP_USE_PF_RING "Setup PcapPlusPlus with PF_RING. In this case you must also set PF_RING_ROOT")
option(PCAPPP_USE_XDP "Setup PcapPlusPlus with XDP")
option(PCAPPP_INSTALL "Install Pcap++" ${PCAPPP_MAIN_PROJECT})
option(PCAPPP_PACKAGE "Package Pcap++ could require a recent version of CMake" OFF)

Expand Down Expand Up @@ -213,6 +214,14 @@ if(PCAPPP_USE_PF_RING)
add_definitions(-DUSE_PF_RING)
endif()

if(PCAPPP_USE_XDP)
find_package(BPF)
if(NOT BPF_FOUND)
message(FATAL_ERROR "libbpf not found!")
endif()
add_definitions(-DUSE_XDP)
endif()

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE
"Release"
Expand Down
1 change: 1 addition & 0 deletions Common++/header/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ namespace pcpp
PcapLogModuleMBufRawPacket, ///< MBufRawPacket module (Pcap++)
PcapLogModuleDpdkDevice, ///< DpdkDevice module (Pcap++)
PcapLogModuleKniDevice, ///< KniDevice module (Pcap++)
PcapLogModuleXdpDevice, ///< XdpDevice module (Pcap++)
NetworkUtils, ///< NetworkUtils module (Pcap++)
NumOfLogModules
};
Expand Down
12 changes: 12 additions & 0 deletions Packet++/header/RawPacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,18 @@ namespace pcpp
*/
virtual bool setRawData(const uint8_t* pRawData, int rawDataLen, timespec timestamp, LinkLayerType layerType = LINKTYPE_ETHERNET, int frameLength = -1);

/**
* Initialize a raw packet with data. The main difference between this method and setRawData() is that setRawData()
* is meant for replacing the data in an existing raw packet, whereas this method is meant to be used right after
* constructing a raw packet using the default c'tor, before setting any data
* @param pRawData A pointer to the new raw data
* @param rawDataLen The new raw data length in bytes
* @param timestamp The timestamp packet was received by the NIC (in nsec precision)
* @param layerType The link layer type for this raw data
* @return True if raw data was set successfully, false otherwise
*/
bool initWithRawData(const uint8_t* pRawData, int rawDataLen, timespec timestamp, LinkLayerType layerType = LINKTYPE_ETHERNET);

/**
* Get raw data pointer
* @return A read-only pointer to the raw data
Expand Down
6 changes: 6 additions & 0 deletions Packet++/src/RawPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ bool RawPacket::setRawData(const uint8_t* pRawData, int rawDataLen, timespec tim
return true;
}

bool RawPacket::initWithRawData(const uint8_t* pRawData, int rawDataLen, timespec timestamp, LinkLayerType layerType)
{
init(false);
return setRawData(pRawData, rawDataLen, timestamp, layerType);
}

void RawPacket::clear()
{
if (m_RawData != nullptr)
Expand Down
6 changes: 6 additions & 0 deletions Pcap++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ add_library(
$<$<BOOL:${WIN32}>:src/PcapRemoteDeviceList.cpp>
$<$<BOOL:${PCAPPP_USE_PF_RING}>:src/PfRingDevice.cpp>
$<$<BOOL:${PCAPPP_USE_PF_RING}>:src/PfRingDeviceList.cpp>
$<$<BOOL:${PCAPPP_USE_XDP}>:src/XdpDevice.cpp>
src/RawSocketDevice.cpp
$<$<BOOL:${WIN32}>:src/WinPcapLiveDevice.cpp>
# Force light pcapng to be link fully static
Expand Down Expand Up @@ -56,6 +57,10 @@ if(PCAPPP_USE_PF_RING)
header/PfRingDeviceList.h)
endif()

if(PCAPPP_USE_XDP)
list(APPEND public_headers header/XdpDevice.h)
endif()

if(LINUX)
list(APPEND public_headers header/LinuxNicInformationSocket.h)
endif()
Expand Down Expand Up @@ -93,6 +98,7 @@ target_link_libraries(
Packet++
$<$<BOOL:${PCAPPP_USE_PF_RING}>:PF_RING::PF_RING>
$<$<BOOL:${PCAPPP_USE_DPDK}>:DPDK::DPDK>
$<$<BOOL:${PCAPPP_USE_XDP}>:BPF::BPF>
PCAP::PCAP
Threads::Threads)

Expand Down
Loading

0 comments on commit 452a53a

Please sign in to comment.