-
Notifications
You must be signed in to change notification settings - Fork 10
/
singlequeue.go
42 lines (36 loc) · 926 Bytes
/
singlequeue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"fmt"
"os"
"os/signal"
"runtime"
"github.com/OneOfOne/go-nfqueue"
)
func print_packets(qid uint16, pkt *nfqueue.Packet) {
fmt.Println(pkt)
pkt.Accept()
}
func main() {
runtime.GOMAXPROCS(runtime.NumCPU()) //if it's less than 2, the program will never exit, it blocks on recv
var (
q = nfqueue.NewNFQueue(0)
)
defer q.Destroy()
fmt.Println("The queue is active, add an iptables rule to use it, for example: ")
fmt.Println("\tiptables -I INPUT 1 [-i eth0] -m conntrack --ctstate NEW -j NFQUEUE --queue-num", 0)
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, os.Kill)
packets := q.Process()
LOOP:
for {
select {
case pkt := <-packets:
fmt.Println(pkt)
pkt.Accept()
case <-sig:
break LOOP
}
}
fmt.Println("Exiting, remember to remove the iptables rule :")
fmt.Println("\tiptables -D INPUT -m conntrack --ctstate NEW -j NFQUEUE --queue-num", 0)
}