forked from gojue/ecapture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (64 loc) · 1.79 KB
/
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"ecapture/cli"
"ecapture/pkg/util/ebpf"
"ecapture/pkg/util/kernel"
_ "github.com/shuLhan/go-bindata" // add for bindata in Makefile
"log"
"runtime"
)
const (
BtfNotSupport = "You can compile the BTF-free version by using the command `make nocore`, please read the Makefile for more information."
)
var (
enableCORE = "true"
)
func main() {
// 环境检测
// 系统内核版本检测
kv, err := kernel.HostVersion()
if err != nil {
log.Fatal(err)
}
switch runtime.GOARCH {
case "amd64":
if kv < kernel.VersionCode(4, 18, 0) {
log.Fatalf("The Linux/Android Kernel version %v (x86_64) is not supported. Requires a version greater than 4.18.", kv)
}
case "arm64":
if kv < kernel.VersionCode(5, 5, 0) {
log.Fatalf("The Linux/Android Kernel version %v (aarch64) is not supported. Requires a version greater than 5.5.", kv)
}
default:
log.Fatalf("Unsupported CPU arch:%v. ", runtime.GOARCH)
}
// 检测是否是容器
isContainer, err := ebpf.IsContainer()
if err != nil {
log.Fatal("Check container error:", err)
}
if isContainer {
log.Printf("Your environment is like a container. We won't be able to detect the BTF configuration.")
} else {
enable, e := ebpf.IsEnableBPF()
if e != nil {
log.Fatalf("Failed to read kernel configuration., error:%v", e)
}
if !enable {
log.Fatalf("Unsupported kernel, error:%v", e)
}
// changed by go build '-ldflags X'
if enableCORE == "true" {
// BTF支持情况检测
enable, e := ebpf.IsEnableBTF()
if e != nil {
log.Fatalf("Unable to find BTF configuration due to an error:%v.\n"+BtfNotSupport, e)
}
if !enable {
log.Fatal("BTF is not supported, please check it. shell: cat /boot/config-`uname -r` | grep CONFIG_DEBUG_INFO_BTF \n " +
BtfNotSupport)
}
}
}
cli.Start()
}