/
main.go
53 lines (36 loc) · 923 Bytes
/
main.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
package main
import (
"encoding/json"
"flag"
"log"
"os"
"os/signal"
"syscall"
"github.com/cilium/ebpf/rlimit"
)
func main() {
log.SetFlags(log.Ldate | log.Lmicroseconds)
f := SetFlags()
flag.Parse()
fBytes, _ := json.MarshalIndent(f, "", "\t")
log.Printf("\n%s\n", string(fBytes))
neti := NewNetInterface()
neti.LoadIfInterface()
// Allow the current process to lock memory for eBPF resources.
if err := rlimit.RemoveMemlock(); err != nil {
log.Fatal(err)
}
uname, _ := GetOSUnamer()
unameBytes, _ := json.MarshalIndent(uname, "", "\t")
log.Printf("\n%s\n", string(unameBytes))
log.Println("tc-filter start...")
log.Printf("process pid: %d\n", os.Getpid())
o := NewOutput(neti)
p := NewTcProbe(neti, o)
p.Start(f)
stopper := make(chan os.Signal, 1)
signal.Notify(stopper, os.Interrupt, syscall.SIGTERM)
<-stopper
p.Stop()
log.Println("Received signal, exiting program..")
}