-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtest_nfqueue.go
54 lines (44 loc) · 1.13 KB
/
test_nfqueue.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
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"encoding/hex"
"fmt"
"github.com/chifflier/nfqueue-go/nfqueue"
"os"
"os/signal"
"syscall"
)
func real_callback(payload *nfqueue.Payload) int {
fmt.Println("Real callback")
fmt.Printf(" id: %d\n", payload.Id)
fmt.Printf(" mark: %d\n", payload.GetNFMark())
fmt.Printf(" in %d out %d\n", payload.GetInDev(), payload.GetOutDev())
fmt.Printf(" Φin %d Φout %d\n", payload.GetPhysInDev(), payload.GetPhysOutDev())
fmt.Println(hex.Dump(payload.Data))
fmt.Println("-- ")
payload.SetVerdict(nfqueue.NF_ACCEPT)
return 0
}
func main() {
q := new(nfqueue.Queue)
q.SetCallback(real_callback)
q.Init()
defer q.Close()
q.Unbind(syscall.AF_INET)
q.Bind(syscall.AF_INET)
q.CreateQueue(0)
q.SetMode(nfqueue.NFQNL_COPY_PACKET)
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func(){
for sig := range c {
// sig is a ^C, handle it
_ = sig
q.StopLoop()
}
}()
// XXX Drop privileges here
q.Loop()
q.DestroyQueue()
q.Close()
os.Exit(0)
}