@@ -10,7 +10,22 @@ Libnetfilter_queue (the netfilter library, not this module) is part of the `Netf
10
10
Example
11
11
=======
12
12
13
- Coming soon...
13
+ The following script prints a short description of each packet before accepting it::
14
+
15
+ from netfilterqueue import NetfilterQueue
16
+
17
+ class PacketPrinter(NetfilterQueue):
18
+ def handle(self, packet):
19
+ print packet
20
+ packet.accept()
21
+
22
+ p = PacketPrinter()
23
+ p.bind(1)
24
+ p.run()
25
+
26
+ To send packets destined for your LAN to the script, type something like::
27
+
28
+ iptables -I INPUT -d 192.168.0.0/24 -j NFQUEUE --queue-num 1
14
29
15
30
Installation
16
31
============
@@ -46,20 +61,53 @@ To install from source::
46
61
47
62
Setup will use Cython if it is installed, regenerating the .c source from the .pyx before compiling the .so.
48
63
64
+ API
65
+ ===
66
+
67
+ Coming soon...
68
+
49
69
Usage
50
70
=====
51
71
52
- Coming soon...
72
+ To route packets to the queue::
53
73
54
- Now route packets to the queue::
74
+ iptables -I <table or chain> <match specification> -j NFQUEUE --queue-num <queue number>
75
+
76
+ For example::
55
77
56
- # iptables -I INPUT -p tcp --dport 80 -j NFQUEUE --queue-num 1
78
+ iptables -I INPUT -d 192.168.0.0/24 -j NFQUEUE --queue-num 1
57
79
58
80
The only special part of the rule is the target. Rules can have any match and
59
81
can be added to any table or chain.
60
82
61
83
Valid queue numbers are integers from 0 to 65,536 inclusive.
62
84
85
+ To view libnetfilter_queue stats, refer to /proc/net/netfilter/nfnetlink_queue::
86
+
87
+ cat /proc/net/netfilter/nfnetlink_queue
88
+ 1 31621 0 2 4016 0 0 2 1
89
+
90
+ The fields are:
91
+
92
+ 1. Queue ID
93
+
94
+ 2. Bound process ID
95
+
96
+ 3. Number of currently queued packets
97
+
98
+ 4. Copy mode
99
+
100
+ 5. Copy size
101
+
102
+ 6. Number of packets dropped due to reaching max queue size
103
+
104
+ 7. Number of packets dropped due to netlink socket failure
105
+
106
+ 8. Total number of packets sent to queue
107
+
108
+ 9. Libnetfilter_queue internal use
109
+
110
+
63
111
Limitations
64
112
===========
65
113
0 commit comments