New example program nfq6
v3 cover New example program nfq6
Hi Pablo,
I've been using nfq6 as a patch testbed for some time.
Now that nfq6 has matured to only use functions from the code base(*), I offer it as a second example for libnetfilter_queue.
(*)This iteration uses nfq_nlmsg_put2() which is not in the codebase yet.
Cheers ... Duncan.
Duncan Roe (1):
examples: add an example which uses more functions
.gitignore | 1 + examples/Makefile.am | 6 +- examples/nfq6.c | 782 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 788 insertions(+), 1 deletion(-) create mode 100644 examples/nfq6.c
Signature · 1 line
2.35.8
PATCH v3 1/1 examples: add an example which uses more functions
Add nfq6 which started out as a copy of nf-queue and can still print packet frameworks (that is test 16).
Usage: nfq6 [-a <alt q #>] [-q <queue length>] [-t <test #>]... queue_number
nfq6 -h
-a <n>: Alternate queue for test 4
-h: give this Help and exit
-q <n>: Set queue length to <n>
-t <n>: do Test <n>. Tests are:
0: If packet mark is zero, set it to 0xbeef and give verdict NF_REPEAT 1: If packet mark is not 0xfaceb00c,
set packet mark to 0xfaceb00c and give verdict NF_REPEAT. If packet mark *is* 0xfaceb00c, accept the packet
2: Allow ENOBUFS to happen; treat as harmless when it does 3: Configure NFQA_CFG_F_FAIL_OPEN
4: Send packets to alternate -a queue
5: Force on test 4 and specify BYPASS
6: Exit nfq6 if incoming packet starts "q[:space:]" (e.g. q\n) 7: Use pktb_setup_raw
8: Use sendmsg to avoid memcpy after mangling
9: Replace 1st ASD by F
10: Replace 1st QWE by RTYUIOP (UDP packets only)
11: Replace 2nd ASD by G
12: Replace 2nd QWE by MNBVCXZ (UDP packets only)
13: Set 16MB kernel socket buffer
14: Report EINTR if we get it
15: Log netlink packets with no checksum
16: Log all netlink packets
17: Replace 1st ZXC by VBN
18: Replace 2nd ZXC by VBN
19: Enable tests 10 & 12 for TCP (not recommended)
20: Don't configure NFQA_CFG_F_GSO
21: Send a nested connmark
22: Turn on NFQA_CFG_F_CONNTRACK
23: Turn on NFQA_CFG_F_SECCTX
nfq6 can process any combination of IPv4, IPv6, TCP & UDP packets. Users can find examples of setting and testing packet marks, mangling packets and sending packets to another queue. Also the code suggests a method to deal with multiple protocols, as someone asked about on the netfilter list recently.
v3: - If test 3 is absent and test 20 is present then don't send config message
- Test 7 breaks from main read loop rather than exit from send_verdict
- Test 21 sends a nested connmark (like utils/nfqnl_test)
- Test 22 tries to turn on NFQA_CFG_F_CONNTRACK, using nfq_nlmsg_put2 and NLM_F_ACK
- Test 23 tries to turn on NFQA_CFG_F_SECCTX (like utils/nfqnl_test) using nfq_nlmsg_put2 and NLM_F_ACK
- If sending to alternate Q via test 4, test 6 forwards the first "q[:space:]" (so the nfq6 -t6 on the second queue will terminate)
- Use floating point to display read buffer size.
With integer arithmetic, absent test 13, buffer size showed as 0MB
- -q option sets queue length (as advised in Main page). Response is checked but have not yet seen failure
v2: 2 code changes:
1. Add test of no GSO
2. Accept packets we can't handle (we used to drop them)
4 cosmetic changes
1. Explain why 'bool' is an enum
2. Rename mangler function pointer to follow same convention as others.
3. Separate function pointers from function prototypes.
4. Add instructions to convert back to single-protocol app.
--- .gitignore | 1 + examples/Makefile.am | 6 +- examples/nfq6.c | 782 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 788 insertions(+), 1 deletion(-) create mode 100644 examples/nfq6.c
.gitignore +1 -0
@@ -19,6 +19,7 @@ Makefile.in /libnetfilter_queue.pc /examples/nf-queue +/examples/nfq6 /doxygen/doxyfile.stamp /doxygen/html/ /doxygen/man/
examples/Makefile.am +5 -1
@@ -1,7 +1,11 @@ include ${top_srcdir}/Make_global.am -check_PROGRAMS = nf-queue +check_PROGRAMS = nf-queue nfq6 nf_queue_SOURCES = nf-queue.c nf_queue_LDADD = ../src/libnetfilter_queue.la -lmnl nf_queue_LDFLAGS = -dynamic + +nfq6_SOURCES = nfq6.c +nfq6_LDADD = ../src/libnetfilter_queue.la -lmnl +nfq6_LDFLAGS = -dynamic
examples/nfq6.c new file +782 -0
782 lines not on this page · raw message
Signature · 1 line
2.35.8
Pablo Neira Ayuso
maintainerQuoted 3 lines · Duncan Roe
Hi Pablo,
I've been using nfq6 as a patch testbed for some time.
Thanks for offering. Please find an alternative spot to store this file, you can write a webpage and documentation for ti, this does not really need to be in libnetfilter_queue.
Quoted 9 lines · Pablo Neira Ayuso
Quoted 3 lines · Duncan Roe
Hi Pablo,
I've been using nfq6 as a patch testbed for some time.
Thanks for offering. Please find an alternative spot to store this file, you can write a webpage and documentation for ti, this does not really need to be in
libnetfilter_queue.
And link to it from the Main page? I don't have a website, would have to be a link to GitHub, but I could put more in README.md there.