-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheDNS.go
58 lines (44 loc) · 1.05 KB
/
eDNS.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
55
56
57
58
package main
import (
"eDNS/kernel"
"eDNS/modules"
"log"
"os"
"os/signal"
"sync"
"syscall"
"github.com/cilium/ebpf/rlimit"
)
var once sync.Once
func main() {
// 环境检测
// 系统内核版本检测
kv, err := kernel.HostVersion()
if err != nil {
log.Fatal(err)
}
if kv < kernel.VersionCode(4, 15, 0) {
log.Fatalf("Linux Kernel version %v is not supported. Need > 4.15 .", kv)
} else {
log.Printf("linux kernel version %v check ok!", kv)
}
// Allow the current process to lock memory for eBPF resources.
if err := rlimit.RemoveMemlock(); err != nil {
log.Fatal(err)
}
stopper := make(chan os.Signal, 1)
signal.Notify(stopper, os.Interrupt, syscall.SIGTERM)
log.Println("eDNS start...")
log.Printf("process pid: %d\n", os.Getpid())
localIP, localIF := modules.GetLocalIP()
log.Printf("local ip: %s on %s\n", localIP, localIF)
dw, err := modules.NewWorker()
if err != nil {
log.Printf("Start eDNS worker error: %v", err)
return
}
go dw.Run()
<-stopper
dw.Stop()
log.Println("Received signal, exiting program..")
}