Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2898,6 +2898,79 @@ jobs:
# DPDK configuration checks
- run: ./qa/live/dpdk/dpdk-testsuite.sh

ubuntu-xdp:
name: Ubuntu (xdp)
runs-on: ubuntu-latest
needs: [prepare-deps]
steps:
# Cache Rust stuff.
- name: Cache cargo registry
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57
with:
path: ~/.cargo/registry
key: cargo-registry

- name: Determine number of CPUs
run: echo CPUS=$(nproc --all) >> $GITHUB_ENV

- run: sudo apt update
- run: |
sudo apt -y install \
autoconf \
automake \
build-essential \
cmake \
curl \
git \
hwloc \
libhwloc-dev \
jq \
make \
libpcre3 \
libpcre3-dbg \
libpcre3-dev \
libpcre2-dev \
libtool \
libpcap-dev \
libnet1-dev \
libyaml-0-2 \
libyaml-dev \
libcap-ng-dev \
libcap-ng0 \
libjansson-dev \
libjansson4 \
libnuma-dev \
liblz4-dev \
libssl-dev \
pkg-config \
python3 \
python3-yaml \
tcpreplay \
zlib1g \
zlib1g-dev \
clang \
libxdp-dev
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
- run: git config --global --add safe.directory /__w/suricata/suricata
- uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53
with:
name: prep
path: prep
- name: Install Rust
run: curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain $(grep rust-version rust/Cargo.toml.in|sed 's/\"//g'|awk '{print $3}') -y
- run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH
- uses: ./.github/actions/install-cbindgen
- run: tar xf prep/suricata-verify.tar.gz
- run: ./autogen.sh
- run: CFLAGS="${DEFAULT_CFLAGS} -DAFPACKET_TEST_REPLAY" ./configure --enable-warnings --enable-unittests --enable-ebpf --enable-ebpf-build
- run: make -j ${{ env.CPUS }}
- run: make check
- name: Running suricata-verify
run: python3 ./suricata-verify/run.py -q --debug-failed
- run: ulimit -a
- name: Running suricata-verify live tests
run: sudo python3 ./suricata-verify/run.py --live --debug-failed

debian-12:
name: Debian 12 (xdp)
runs-on: ubuntu-latest
Expand Down
8 changes: 7 additions & 1 deletion src/runmode-af-packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,13 @@ static void *ParseAFPConfig(const char *iface)
SCLogError("%s: XDP support is not built-in", iface);
#endif
}

#ifdef AFPACKET_TEST_REPLAY
if ((SCConfGetChildValueIntWithDefault(if_root, if_default, "max-packets", &value)) == 1) {
aconf->max_packets = (uint32_t)value;
} else {
aconf->max_packets = 0;
}
#endif
if ((SCConfGetChildValueIntWithDefault(if_root, if_default, "buffer-size", &value)) == 1) {
aconf->buffer_size = (int)value;
} else {
Expand Down
44 changes: 27 additions & 17 deletions src/source-af-packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,9 @@ typedef struct AFPThreadVars_
int ebpf_filter_fd;
struct ebpf_timeout_config ebpf_t_config;
#endif

#ifdef AFPACKET_TEST_REPLAY
uint32_t max_packets;
#endif
} AFPThreadVars;

static TmEcode ReceiveAFPThreadInit(ThreadVars *, const void *, void **);
Expand Down Expand Up @@ -1429,6 +1431,11 @@ TmEcode ReceiveAFPLoop(ThreadVars *tv, void *data, void *slot)
} else if (r > 0) {
StatsCounterIncr(&ptv->tv->stats, ptv->capture_afp_poll_data);
r = AFPReadFunc(ptv);
#ifdef AFPACKET_TEST_REPLAY
if (ptv->max_packets > 0 && ptv->pkts >= ptv->max_packets) {
suricata_ctl_flags |= SURICATA_STOP;
}
#endif
switch (r) {
case AFP_READ_OK:
/* Trigger one dump of stats every second */
Expand Down Expand Up @@ -2297,8 +2304,8 @@ static int AFPBypassCallback(Packet *p)
keys[0]->dst = htonl(GET_IPV4_DST_ADDR_U32(p));
keys[0]->port16[0] = p->sp;
keys[0]->port16[1] = p->dp;
keys[0]->vlan0 = p->vlan_id[0];
keys[0]->vlan1 = p->vlan_id[1];
keys[0]->vlan0 = p->vlan_id[0] & g_vlan_mask;
keys[0]->vlan1 = p->vlan_id[1] & g_vlan_mask;

if (p->proto == IPPROTO_TCP) {
keys[0]->ip_proto = 1;
Expand All @@ -2322,8 +2329,8 @@ static int AFPBypassCallback(Packet *p)
keys[1]->dst = htonl(GET_IPV4_SRC_ADDR_U32(p));
keys[1]->port16[0] = p->dp;
keys[1]->port16[1] = p->sp;
keys[1]->vlan0 = p->vlan_id[0];
keys[1]->vlan1 = p->vlan_id[1];
keys[1]->vlan0 = p->vlan_id[0] & g_vlan_mask;
keys[1]->vlan1 = p->vlan_id[1] & g_vlan_mask;

keys[1]->ip_proto = keys[0]->ip_proto;
if (AFPInsertHalfFlow(p->afp_v.v4_map_fd, keys[1],
Expand Down Expand Up @@ -2356,8 +2363,8 @@ static int AFPBypassCallback(Packet *p)
}
keys[0]->port16[0] = p->sp;
keys[0]->port16[1] = p->dp;
keys[0]->vlan0 = p->vlan_id[0];
keys[0]->vlan1 = p->vlan_id[1];
keys[0]->vlan0 = p->vlan_id[0] & g_vlan_mask;
keys[0]->vlan1 = p->vlan_id[1] & g_vlan_mask;

if (p->proto == IPPROTO_TCP) {
keys[0]->ip_proto = 1;
Expand All @@ -2383,8 +2390,8 @@ static int AFPBypassCallback(Packet *p)
}
keys[1]->port16[0] = p->dp;
keys[1]->port16[1] = p->sp;
keys[1]->vlan0 = p->vlan_id[0];
keys[1]->vlan1 = p->vlan_id[1];
keys[1]->vlan0 = p->vlan_id[0] & g_vlan_mask;
keys[1]->vlan1 = p->vlan_id[1] & g_vlan_mask;

keys[1]->ip_proto = keys[0]->ip_proto;
if (AFPInsertHalfFlow(p->afp_v.v6_map_fd, keys[1],
Expand Down Expand Up @@ -2451,8 +2458,8 @@ static int AFPXDPBypassCallback(Packet *p)
* (as in eBPF filter) so we need to pass from host to network order */
keys[0]->port16[0] = htons(p->sp);
keys[0]->port16[1] = htons(p->dp);
keys[0]->vlan0 = p->vlan_id[0];
keys[0]->vlan1 = p->vlan_id[1];
keys[0]->vlan0 = p->vlan_id[0] & g_vlan_mask;
keys[0]->vlan1 = p->vlan_id[1] & g_vlan_mask;
if (p->proto == IPPROTO_TCP) {
keys[0]->ip_proto = 1;
} else {
Expand All @@ -2475,8 +2482,8 @@ static int AFPXDPBypassCallback(Packet *p)
keys[1]->dst = p->src.addr_data32[0];
keys[1]->port16[0] = htons(p->dp);
keys[1]->port16[1] = htons(p->sp);
keys[1]->vlan0 = p->vlan_id[0];
keys[1]->vlan1 = p->vlan_id[1];
keys[1]->vlan0 = p->vlan_id[0] & g_vlan_mask;
keys[1]->vlan1 = p->vlan_id[1] & g_vlan_mask;
keys[1]->ip_proto = keys[0]->ip_proto;
if (AFPInsertHalfFlow(p->afp_v.v4_map_fd, keys[1],
p->afp_v.nr_cpus) == 0) {
Expand Down Expand Up @@ -2507,8 +2514,8 @@ static int AFPXDPBypassCallback(Packet *p)
}
keys[0]->port16[0] = htons(p->sp);
keys[0]->port16[1] = htons(p->dp);
keys[0]->vlan0 = p->vlan_id[0];
keys[0]->vlan1 = p->vlan_id[1];
keys[0]->vlan0 = p->vlan_id[0] & g_vlan_mask;
keys[0]->vlan1 = p->vlan_id[1] & g_vlan_mask;
if (p->proto == IPPROTO_TCP) {
keys[0]->ip_proto = 1;
} else {
Expand All @@ -2533,8 +2540,8 @@ static int AFPXDPBypassCallback(Packet *p)
}
keys[1]->port16[0] = htons(p->dp);
keys[1]->port16[1] = htons(p->sp);
keys[1]->vlan0 = p->vlan_id[0];
keys[1]->vlan1 = p->vlan_id[1];
keys[1]->vlan0 = p->vlan_id[0] & g_vlan_mask;
keys[1]->vlan1 = p->vlan_id[1] & g_vlan_mask;
keys[1]->ip_proto = keys[0]->ip_proto;
if (AFPInsertHalfFlow(p->afp_v.v6_map_fd, keys[1],
p->afp_v.nr_cpus) == 0) {
Expand Down Expand Up @@ -2600,6 +2607,9 @@ TmEcode ReceiveAFPThreadInit(ThreadVars *tv, const void *initdata, void **data)
ptv->promisc = afpconfig->promisc;
ptv->checksum_mode = afpconfig->checksum_mode;
ptv->bpf_filter = NULL;
#ifdef AFPACKET_TEST_REPLAY
ptv->max_packets = afpconfig->max_packets;
#endif

ptv->threads = 1;
#ifdef HAVE_PACKET_FANOUT
Expand Down
3 changes: 3 additions & 0 deletions src/source-af-packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ typedef struct AFPIfaceConfig_
const char *out_iface;
#ifdef HAVE_PACKET_EBPF
struct ebpf_timeout_config ebpf_t_config;
#endif
#ifdef AFPACKET_TEST_REPLAY
uint32_t max_packets;
#endif
SC_ATOMIC_DECLARE(unsigned int, ref);
void (*DerefFunc)(void *);
Expand Down
6 changes: 6 additions & 0 deletions src/suricata.c
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,12 @@ static void PrintBuildInfo(void)
#ifdef PROFILING
strlcat(features, "PROFILING ", sizeof(features));
#endif
#ifdef HAVE_PACKET_EBPF
strlcat(features, "EBPF ", sizeof(features));
#endif
#ifdef AFPACKET_TEST_REPLAY
strlcat(features, "AFPACKET_TEST_REPLAY ", sizeof(features));
#endif
#ifdef PROFILE_LOCKING
strlcat(features, "PROFILE_LOCKING ", sizeof(features));
#endif
Expand Down