Skip to contentSkip to conversation

New example program nfq6

PATCH New Duncan Roe 1 participant 2 messages Oct 16, 2023 netfilter

lore
Share & tools
lore

Duncan Roe

author
#0 lore raw

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.

I did fix some errors from checkpatch.
I myself disagree with those that remain.
If you think some of them warrant fixing, I'll do it of course.

Cheers ... Duncan.

Duncan Roe (1):
examples: add an example which uses more functions

 .gitignore           |   1 +
 examples/Makefile.am |   6 +-
 examples/nfq6.c      | 648 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 654 insertions(+), 1 deletion(-)
 create mode 100644 examples/nfq6.c
Signature · 1 line
2.35.8
author
#1 lore raw

PATCH 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 #>] [-t <test #>],... queue_number

       nfq6 -h

-a <n>: Alternate queue for test 4
-h: give this Help and exit
-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 it to that 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)

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.

---
 .gitignore           |   1 +
 examples/Makefile.am |   6 +-
 examples/nfq6.c      | 650 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 656 insertions(+), 1 deletion(-)
 create mode 100644 examples/nfq6.c
.gitignore +1 -0
index ae3e740..b64534a 100644
@@ -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
index 97bb70c..c1bce54 100644
@@ -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 +648 -0

648 lines not on this page · raw message

Signature · 1 line
2.35.8