forked from hi-glenn/xdp_acl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
58 lines (44 loc) · 1.13 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
package main
import (
"context"
"os"
"os/signal"
"syscall"
"time"
"github.com/cilium/ebpf/rlimit"
"golang.org/x/sync/errgroup"
)
//go:generate bash ./script/compile-bpf.sh
func main() {
b := time.Now()
flags := parseFlags()
if err := rlimit.RemoveMemlock(); err != nil {
zlog.Fatalf("Failed to remove memory lock: %v", err)
}
zlog.Info("dev: ", flags.Dev)
if len(flags.Dev) == 0 {
return
}
ts := time.Now()
rules, err := LoadRules(flags.Conf, flags.LastRuleAccept, flags.LastRuleFixed)
if err != nil {
zlog.Errorf("Failed to load rules: %v", err)
return
}
zlog.Infof("🍉 name: %s. Cost: %s.", "loading rules", time.Since(ts))
xdp, err := newXdp(flags, rules)
if err != nil {
zlog.Fatalf("Failed to new xdp: %v", err)
}
defer xdp.Close()
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
errg, ctx := errgroup.WithContext(ctx)
errg.Go(func() error {
return runWebApp(ctx, flags, rules, xdp)
})
zlog.Infof("🍉🍉 name: %s. Cost: %s.", "app", time.Since(b))
if err := errg.Wait(); err != nil {
zlog.Errorf("Failed to run web server: %v", err)
}
}