Skip to content

Commit 6ec593f

Browse files
committed
test: new afpacket max-packets feature
Ticket: 7674 Allows a compile-time option AFPACKET_TEST_REPLAY, that allows to set a configuration max-packets per afpacket interface, after which the PktAcqLoop stops. This allows suricata-verify tests to run with tcpreplay, and know when to stop
1 parent abc5b23 commit 6ec593f

5 files changed

Lines changed: 25 additions & 3 deletions

File tree

.github/workflows/builds.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2959,7 +2959,7 @@ jobs:
29592959
- uses: ./.github/actions/install-cbindgen
29602960
- run: tar xf prep/suricata-verify.tar.gz
29612961
- run: ./autogen.sh
2962-
- run: CFLAGS="${DEFAULT_CFLAGS}" ./configure --enable-warnings --enable-unittests --enable-ebpf --enable-ebpf-build
2962+
- run: CFLAGS="${DEFAULT_CFLAGS} -DAFPACKET_TEST_REPLAY" ./configure --enable-warnings --enable-unittests --enable-ebpf --enable-ebpf-build
29632963
- run: make -j ${{ env.CPUS }}
29642964
- run: make check
29652965
- name: Running suricata-verify

src/runmode-af-packet.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,13 @@ static void *ParseAFPConfig(const char *iface)
595595
SCLogError("%s: XDP support is not built-in", iface);
596596
#endif
597597
}
598-
598+
#ifdef AFPACKET_TEST_REPLAY
599+
if ((SCConfGetChildValueIntWithDefault(if_root, if_default, "max-packets", &value)) == 1) {
600+
aconf->max_packets = (uint32_t)value;
601+
} else {
602+
aconf->max_packets = 0;
603+
}
604+
#endif
599605
if ((SCConfGetChildValueIntWithDefault(if_root, if_default, "buffer-size", &value)) == 1) {
600606
aconf->buffer_size = (int)value;
601607
} else {

src/source-af-packet.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,9 @@ typedef struct AFPThreadVars_
356356
int ebpf_filter_fd;
357357
struct ebpf_timeout_config ebpf_t_config;
358358
#endif
359-
359+
#ifdef AFPACKET_TEST_REPLAY
360+
uint32_t max_packets;
361+
#endif
360362
} AFPThreadVars;
361363

362364
static TmEcode ReceiveAFPThreadInit(ThreadVars *, const void *, void **);
@@ -1440,6 +1442,11 @@ TmEcode ReceiveAFPLoop(ThreadVars *tv, void *data, void *slot)
14401442
} else if (r > 0) {
14411443
StatsCounterIncr(&ptv->tv->stats, ptv->capture_afp_poll_data);
14421444
r = AFPReadFunc(ptv);
1445+
#ifdef AFPACKET_TEST_REPLAY
1446+
if (ptv->max_packets > 0 && ptv->pkts >= ptv->max_packets) {
1447+
suricata_ctl_flags |= SURICATA_STOP;
1448+
}
1449+
#endif
14431450
switch (r) {
14441451
case AFP_READ_OK:
14451452
/* Trigger one dump of stats every second */
@@ -2589,6 +2596,9 @@ TmEcode ReceiveAFPThreadInit(ThreadVars *tv, const void *initdata, void **data)
25892596
ptv->promisc = afpconfig->promisc;
25902597
ptv->checksum_mode = afpconfig->checksum_mode;
25912598
ptv->bpf_filter = NULL;
2599+
#ifdef AFPACKET_TEST_REPLAY
2600+
ptv->max_packets = afpconfig->max_packets;
2601+
#endif
25922602

25932603
ptv->threads = 1;
25942604
#ifdef HAVE_PACKET_FANOUT

src/source-af-packet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ typedef struct AFPIfaceConfig_
120120
const char *out_iface;
121121
#ifdef HAVE_PACKET_EBPF
122122
struct ebpf_timeout_config ebpf_t_config;
123+
#endif
124+
#ifdef AFPACKET_TEST_REPLAY
125+
uint32_t max_packets;
123126
#endif
124127
SC_ATOMIC_DECLARE(unsigned int, ref);
125128
void (*DerefFunc)(void *);

src/suricata.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,9 @@ static void PrintBuildInfo(void)
844844
#ifdef HAVE_PACKET_EBPF
845845
strlcat(features, "EBPF ", sizeof(features));
846846
#endif
847+
#ifdef AFPACKET_TEST_REPLAY
848+
strlcat(features, "AFPACKET_TEST_REPLAY ", sizeof(features));
849+
#endif
847850
#ifdef PROFILE_LOCKING
848851
strlcat(features, "PROFILE_LOCKING ", sizeof(features));
849852
#endif

0 commit comments

Comments
 (0)