Skip to content

Commit 452a53a

Browse files
authored
Introduce XDP device (seladb#1228)
1 parent a0ecc6d commit 452a53a

File tree

13 files changed

+1377
-1
lines changed

13 files changed

+1377
-1
lines changed

.github/workflows/build_and_test.yml

+36
Original file line numberDiff line numberDiff line change
@@ -532,3 +532,39 @@ jobs:
532532
sed -i.bak "s|abiFilters.*$|abiFilters '${{ matrix.target }}'|g" app/build.gradle
533533
chmod +x gradlew
534534
./gradlew assembleDebug
535+
536+
xdp:
537+
runs-on: ubuntu-latest
538+
539+
steps:
540+
- name: Checkout code
541+
uses: actions/checkout@v3
542+
543+
- name: Install dependencies
544+
run: |
545+
sudo apt update && sudo apt -y install libpcap-dev libbpf-dev tcpreplay
546+
547+
- name: Configure PcapPlusPlus
548+
run: cmake -DPCAPPP_USE_XDP=ON -S . -B $BUILD_DIR
549+
550+
- name: Build PcapPlusPlus
551+
run: cmake --build $BUILD_DIR -j
552+
553+
- name: Test PcapPlusPlus
554+
run: |
555+
python -m pip install -U pip
556+
python -m pip install -r ci/run_tests/requirements.txt
557+
python ci/run_tests/run_tests.py --interface eth0 --use-sudo --pcap-test-args="-t xdp"
558+
559+
- name: Create Cobertura Report
560+
run: |
561+
python -m pip install gcovr
562+
gcovr -v -r . $GCOVR_FLAGS -o coverage.xml
563+
564+
- name: Upload Coverage Results
565+
uses: codecov/codecov-action@v3
566+
with:
567+
files: ./coverage.xml
568+
flags: xdp,unittest
569+
fail_ci_if_error: false
570+
verbose: true

CMakeLists.txt

+9
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ cmake_dependent_option(
102102
"PCAPPP_USE_DPDK"
103103
OFF)
104104
option(PCAPPP_USE_PF_RING "Setup PcapPlusPlus with PF_RING. In this case you must also set PF_RING_ROOT")
105+
option(PCAPPP_USE_XDP "Setup PcapPlusPlus with XDP")
105106
option(PCAPPP_INSTALL "Install Pcap++" ${PCAPPP_MAIN_PROJECT})
106107
option(PCAPPP_PACKAGE "Package Pcap++ could require a recent version of CMake" OFF)
107108

@@ -213,6 +214,14 @@ if(PCAPPP_USE_PF_RING)
213214
add_definitions(-DUSE_PF_RING)
214215
endif()
215216

217+
if(PCAPPP_USE_XDP)
218+
find_package(BPF)
219+
if(NOT BPF_FOUND)
220+
message(FATAL_ERROR "libbpf not found!")
221+
endif()
222+
add_definitions(-DUSE_XDP)
223+
endif()
224+
216225
if(NOT CMAKE_BUILD_TYPE)
217226
set(CMAKE_BUILD_TYPE
218227
"Release"

Common++/header/Logger.h

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ namespace pcpp
8181
PcapLogModuleMBufRawPacket, ///< MBufRawPacket module (Pcap++)
8282
PcapLogModuleDpdkDevice, ///< DpdkDevice module (Pcap++)
8383
PcapLogModuleKniDevice, ///< KniDevice module (Pcap++)
84+
PcapLogModuleXdpDevice, ///< XdpDevice module (Pcap++)
8485
NetworkUtils, ///< NetworkUtils module (Pcap++)
8586
NumOfLogModules
8687
};

Packet++/header/RawPacket.h

+12
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,18 @@ namespace pcpp
348348
*/
349349
virtual bool setRawData(const uint8_t* pRawData, int rawDataLen, timespec timestamp, LinkLayerType layerType = LINKTYPE_ETHERNET, int frameLength = -1);
350350

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

Packet++/src/RawPacket.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ bool RawPacket::setRawData(const uint8_t* pRawData, int rawDataLen, timespec tim
112112
return true;
113113
}
114114

115+
bool RawPacket::initWithRawData(const uint8_t* pRawData, int rawDataLen, timespec timestamp, LinkLayerType layerType)
116+
{
117+
init(false);
118+
return setRawData(pRawData, rawDataLen, timestamp, layerType);
119+
}
120+
115121
void RawPacket::clear()
116122
{
117123
if (m_RawData != nullptr)

Pcap++/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ add_library(
1616
$<$<BOOL:${WIN32}>:src/PcapRemoteDeviceList.cpp>
1717
$<$<BOOL:${PCAPPP_USE_PF_RING}>:src/PfRingDevice.cpp>
1818
$<$<BOOL:${PCAPPP_USE_PF_RING}>:src/PfRingDeviceList.cpp>
19+
$<$<BOOL:${PCAPPP_USE_XDP}>:src/XdpDevice.cpp>
1920
src/RawSocketDevice.cpp
2021
$<$<BOOL:${WIN32}>:src/WinPcapLiveDevice.cpp>
2122
# Force light pcapng to be link fully static
@@ -56,6 +57,10 @@ if(PCAPPP_USE_PF_RING)
5657
header/PfRingDeviceList.h)
5758
endif()
5859

60+
if(PCAPPP_USE_XDP)
61+
list(APPEND public_headers header/XdpDevice.h)
62+
endif()
63+
5964
if(LINUX)
6065
list(APPEND public_headers header/LinuxNicInformationSocket.h)
6166
endif()
@@ -93,6 +98,7 @@ target_link_libraries(
9398
Packet++
9499
$<$<BOOL:${PCAPPP_USE_PF_RING}>:PF_RING::PF_RING>
95100
$<$<BOOL:${PCAPPP_USE_DPDK}>:DPDK::DPDK>
101+
$<$<BOOL:${PCAPPP_USE_XDP}>:BPF::BPF>
96102
PCAP::PCAP
97103
Threads::Threads)
98104

0 commit comments

Comments
 (0)