Skip to contentSkip to conversation

selftests: netfilter: add nfqueue test case

PATCH Applied Florian Westphal 2 participants 2 messages Mar 23, 2020 – Mar 24, 2020

Subsystems (2)
lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH v3 1/1 selftests: netfilter: add nfqueue test case

Add a test case to check nf queue infrastructure. Could be extended in the future to also cover serialization of conntrack, uid and secctx attributes in nfqueue.

For now, this checks that 'queue bypass' works, that a queue rule with no bypass option blocks traffic and that userspace receives the expected number of packets.
For this we add two queues and hook all of prerouting/input/forward/output/postrouting.

Packets get queued twice with a dummy base chain in between:
This passes with current nf tree, but reverting
commit 946c0d8e6ed4 ("netfilter: nf_queue: fix reinject verdict handling") makes this trip (it processes 30 instead of expected 20 packets).

v2: update config file with queue and other options missing/needed for other tests.
v3: also test with tcp, this reveals problem with commit 28f8bfd1ac94 ("netfilter: Support iif matches in POSTROUTING"), due to skb->dev pointing at another skb in the retransmit rbtree (skb->dev aliases to rbnode child).

---
 tools/testing/selftests/netfilter/Makefile    |   6 +-
 tools/testing/selftests/netfilter/config      |   6 +
 tools/testing/selftests/netfilter/nf-queue.c  | 352 ++++++++++++++++++
 .../testing/selftests/netfilter/nft_queue.sh  | 332 +++++++++++++++++
 4 files changed, 695 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/netfilter/nf-queue.c
 create mode 100755 tools/testing/selftests/netfilter/nft_queue.sh
tools/testing/selftests/netfilter/Makefile +5 -1
index 08194aa44006..9c0f758310fe 100644
@@ -3,6 +3,10 @@
 
 TEST_PROGS := nft_trans_stress.sh nft_nat.sh bridge_brouter.sh \
 	conntrack_icmp_related.sh nft_flowtable.sh ipvs.sh \
-	nft_concat_range.sh
+	nft_concat_range.sh \
+	nft_queue.sh
+
+LDLIBS = -lmnl
+TEST_GEN_FILES =  nf-queue
 
 include ../lib.mk
tools/testing/selftests/netfilter/config +6 -0
index 59caa8f71cd8..4faf2ce021d9 100644
@@ -1,2 +1,8 @@
 CONFIG_NET_NS=y
 CONFIG_NF_TABLES_INET=y
+CONFIG_NFT_QUEUE=m
+CONFIG_NFT_NAT=m
+CONFIG_NFT_REDIR=m
+CONFIG_NFT_MASQ=m
+CONFIG_NFT_FLOW_OFFLOAD=m
+CONFIG_NF_CT_NETLINK=m
tools/testing/selftests/netfilter/nf-queue.c new file +352 -0

352 lines not on this page · raw message

tools/testing/selftests/netfilter/nft_queue.sh new file +332 -0

332 lines not on this page · raw message

Signature · 1 line
2.24.1
maintainer Applied
#1 lore raw
Quoted 10 lines · Florian Westphal

Add a test case to check nf queue infrastructure. Could be extended in the future to also cover serialization of conntrack, uid and secctx attributes in nfqueue.

For now, this checks that 'queue bypass' works, that a queue rule with no bypass option blocks traffic and that userspace receives the expected number of packets.
For this we add two queues and hook all of prerouting/input/forward/output/postrouting.

Quoted 4 lines

Packets get queued twice with a dummy base chain in between:
This passes with current nf tree, but reverting
commit 946c0d8e6ed4 ("netfilter: nf_queue: fix reinject verdict handling") makes this trip (it processes 30 instead of expected 20 packets).

Applied, thanks.