selftests: netfilter: add nfqueue test case
Florian Westphal
maintainerPATCH v2 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.
--- tools/testing/selftests/netfilter/.gitignore | 1 + tools/testing/selftests/netfilter/Makefile | 5 +- tools/testing/selftests/netfilter/config | 6 + tools/testing/selftests/netfilter/nf-queue.c | 281 ++++++++++++++++++ .../testing/selftests/netfilter/nft_queue.sh | 274 +++++++++++++++++ 5 files changed, 566 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/netfilter/.gitignore create mode 100644 tools/testing/selftests/netfilter/nf-queue.c create mode 100755 tools/testing/selftests/netfilter/nft_queue.sh
tools/testing/selftests/netfilter/.gitignore new file +1 -0
@@ -0,0 +1 @@ +nf-queue
tools/testing/selftests/netfilter/Makefile +4 -1
@@ -2,6 +2,9 @@ # Makefile for netfilter selftests TEST_PROGS := nft_trans_stress.sh nft_nat.sh bridge_brouter.sh \ - conntrack_icmp_related.sh nft_flowtable.sh + conntrack_icmp_related.sh nft_flowtable.sh nft_queue.sh + +LDLIBS = -lmnl +TEST_GEN_FILES = nf-queue include ../lib.mk
tools/testing/selftests/netfilter/config +6 -0
@@ -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 +281 -0
281 lines not on this page · raw message
tools/testing/selftests/netfilter/nft_queue.sh new file +274 -0
274 lines not on this page · raw message
Signature · 1 line
2.21.0
Pablo Neira Ayuso
maintainertools/testing/selftests/netfilter/nf-queue.c
Quoted 5 lines · Florian Westphal
tools/testing/selftests/netfilter/nf-queue.c new file +0
-0
Oh well. Lots of copied and pasted code from the libraries.
We'll have to remind to take patches for the example in the library and the kernel.
Florian Westphal
maintainerQuoted 11 lines · Pablo Neira Ayuso
tools/testing/selftests/netfilter/nf-queue.c
Quoted 5 lines · Florian Westphal
tools/testing/selftests/netfilter/nf-queue.c new file +0
-0Oh well. Lots of copied and pasted code from the libraries.
We'll have to remind to take patches for the example in the library and the kernel.
Do you have an alternative proposal?
Pablo Neira Ayuso
maintainerQuoted 10 lines · Florian Westphal
Quoted 9 lines · Pablo Neira Ayuso
tools/testing/selftests/netfilter/nf-queue.c
Quoted 5 lines · Florian Westphal
tools/testing/selftests/netfilter/nf-queue.c new file +0
-0Oh well. Lots of copied and pasted code from the libraries.
Quoted 4 lines
Quoted 2 lines
We'll have to remind to take patches for the example in the library and the kernel.
Do you have an alternative proposal?
Probably install this nf-queue tool from libraries? Then, selftest use this binary? So we have a single copy of this code :-)
Pablo Neira Ayuso
maintainerQuoted 11 lines · Pablo Neira Ayuso
Quoted 10 lines · Florian Westphal
Quoted 9 lines · Pablo Neira Ayuso
tools/testing/selftests/netfilter/nf-queue.c
Quoted 5 lines · Florian Westphal
tools/testing/selftests/netfilter/nf-queue.c new file +0
-0Oh well. Lots of copied and pasted code from the libraries.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
We'll have to remind to take patches for the example in the library and the kernel.
Do you have an alternative proposal?
Probably install this nf-queue tool from libraries? Then, selftest use this binary? So we have a single copy of this code :-)
Or move this C code to a new git tree under netfilter, eg. netfilter-tests.git, you may need something similar for libnetfilter_log I suspect, and so on for other stuff.
Such new git tree would compile all testing tools for netfilter and install them.
kselftest depends on external tooling anyway, this should be fine.
Pablo Neira Ayuso
maintainerQuoted 20 lines · Pablo Neira Ayuso
Quoted 11 lines · Pablo Neira Ayuso
Quoted 10 lines · Florian Westphal
Quoted 9 lines · Pablo Neira Ayuso
tools/testing/selftests/netfilter/nf-queue.c
Quoted 5 lines · Florian Westphal
tools/testing/selftests/netfilter/nf-queue.c new file +0
-0Oh well. Lots of copied and pasted code from the libraries.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
We'll have to remind to take patches for the example in the library and the kernel.
Do you have an alternative proposal?
Probably install this nf-queue tool from libraries? Then, selftest use this binary? So we have a single copy of this code :-)
Quoted 8 lines
Or move this C code to a new git tree under netfilter, eg. netfilter-tests.git, you may need something similar for
libnetfilter_logI suspect, and so on for other stuff.Such new git tree would compile all testing tools for netfilter and install them.
kselftest depends on external tooling anyway, this should be fine.
You could also integrate the tcpdr tool that Mate was using to test tproxy, there will be a test for tproxy too at some point, right? And you don't want to push that into the kernel?
Having all this testing tools in the git repository somewhere where it can be collected could be useful. Users could invoke it from command line to collect packets and print them. I mean, add the nfqueue tool, then the nflog tool too, and so on.
It would be also a good way to keep the C code for these tooling in the netfilter tree, while keeping the shell scripts in the kernel tree.
Florian Westphal
maintainerQuoted 25 lines · Pablo Neira Ayuso
Quoted 24 lines · Pablo Neira Ayuso
Quoted 11 lines · Pablo Neira Ayuso
Quoted 10 lines · Florian Westphal
Quoted 9 lines · Pablo Neira Ayuso
tools/testing/selftests/netfilter/nf-queue.c
Quoted 5 lines · Florian Westphal
tools/testing/selftests/netfilter/nf-queue.c new file +0
-0Oh well. Lots of copied and pasted code from the libraries.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
We'll have to remind to take patches for the example in the library and the kernel.
Do you have an alternative proposal?
Probably install this nf-queue tool from libraries? Then, selftest use this binary? So we have a single copy of this code :-)
Or move this C code to a new git tree under netfilter, eg. netfilter-tests.git, you may need something similar for
libnetfilter_logI suspect, and so on for other stuff.
Quoted 8 lines
Quoted 4 lines
Such new git tree would compile all testing tools for netfilter and install them.
kselftest depends on external tooling anyway, this should be fine.
You could also integrate the tcpdr tool that Mate was using to test tproxy, there will be a test for tproxy too at some point, right? And you don't want to push that into the kernel?
Actually ... yes :/
I had hoped that we could maximize coverage of netfilter core infra this way.
We have an embarassing number of regressions and really stupid bugs. Largely because we don't have tests at all, or because they live outside of kernel/are not run with a certain config.
Quoted 4 lines
Having all this testing tools in the git repository somewhere where it can be collected could be useful. Users could invoke it from command line to collect packets and print them. I mean, add the nfqueue tool, then the nflog tool too, and so on.
Yes, but that means that anyone running make run_tests will get a 'SKIP' for these tests UNLESS they also installed the netfilter-test.git tools.
If you think thats fine, I can start accumulating tools in a new repo.
Pablo Neira Ayuso
maintainerQuoted 35 lines · Florian Westphal
Quoted 25 lines · Pablo Neira Ayuso
Quoted 24 lines · Pablo Neira Ayuso
Quoted 11 lines · Pablo Neira Ayuso
Quoted 10 lines · Florian Westphal
Quoted 9 lines · Pablo Neira Ayuso
tools/testing/selftests/netfilter/nf-queue.c
Quoted 5 lines · Florian Westphal
tools/testing/selftests/netfilter/nf-queue.c new file +0
-0Oh well. Lots of copied and pasted code from the libraries.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
We'll have to remind to take patches for the example in the library and the kernel.
Do you have an alternative proposal?
Probably install this nf-queue tool from libraries? Then, selftest use this binary? So we have a single copy of this code :-)
Or move this C code to a new git tree under netfilter, eg. netfilter-tests.git, you may need something similar for
libnetfilter_logI suspect, and so on for other stuff.Quoted 8 lines
Quoted 4 lines
Such new git tree would compile all testing tools for netfilter and install them.
kselftest depends on external tooling anyway, this should be fine.
You could also integrate the tcpdr tool that Mate was using to test tproxy, there will be a test for tproxy too at some point, right? And you don't want to push that into the kernel?
Quoted 8 lines
Actually ... yes :/
I had hoped that we could maximize coverage of netfilter core infra this way.
We have an embarassing number of regressions and really stupid bugs. Largely because we don't have tests at all, or because they live outside of kernel/are not run with a certain config.
I think they cover different aspects, so far we have good coverage for the control plane, which are the tests you are refering to.
Quoted 8 lines
Quoted 4 lines
Having all this testing tools in the git repository somewhere where it can be collected could be useful. Users could invoke it from command line to collect packets and print them. I mean, add the nfqueue tool, then the nflog tool too, and so on.
Yes, but that means that anyone running make
run_testswill get a 'SKIP' for these tests UNLESS they also installed the netfilter-test.git tools.
Is there any script that pulls dependencies and install them to run this kselftests?
Quoted 1 line
If you think thats fine, I can start accumulating tools in a new repo.
I'm just brainstorming where to go, and see if you think it can be useful to start collecting testing/debugging tools that might be not only useful for this test infrastructure, but for general troubleshooting.
My only concern is that we might end up with a bit of C code spread over the test tree for all these tooling. Probably these tooling could reside in the kernel tree if you prefer.