-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
100 lines (93 loc) · 2.22 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main
import (
"fmt"
"log"
"os"
"os/signal"
"syscall"
trunks "github.com/shynuu/trunks/runtime"
"github.com/urfave/cli/v2"
)
// Initialize signals handling
func initSignals() {
cancelChan := make(chan os.Signal, 1)
signal.Notify(cancelChan, syscall.SIGTERM, syscall.SIGINT)
func(_ os.Signal) {}(<-cancelChan)
os.Exit(0)
}
func main() {
var config string
var flush bool = false
var acm bool = false
var qos bool = false
var disable_kernel_version_check = false
var logs string
app := &cli.App{
Name: "trunks",
Usage: "a simple DVB-S2/DVB-RCS2 simulator",
EnableBashCompletion: true,
Authors: []*cli.Author{
{Name: "Youssouf Drif"},
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Usage: "Load configuration from `FILE`",
Destination: &config,
Required: true,
DefaultText: "not set",
},
&cli.StringFlag{
Name: "logs",
Usage: "Log path for the log file",
Destination: &logs,
Required: false,
DefaultText: "not set",
},
&cli.BoolFlag{
Name: "flush",
Usage: "Flush IPTABLES table mangle and clear all TC rules",
Destination: &flush,
},
&cli.BoolFlag{
Name: "acm",
Usage: "Activate the ACM simulation",
Destination: &acm,
DefaultText: "not activated",
},
&cli.BoolFlag{
Name: "qos",
Usage: "Process traffic using QoS",
Destination: &qos,
DefaultText: "not activated",
},
&cli.BoolFlag{
Name: "disable-kernel-version-check",
Usage: "Disable check for bugged kernel versions",
Destination: &disable_kernel_version_check,
DefaultText: "kernel version check enabled",
},
},
Action: func(c *cli.Context) error {
trunksConfig, err := trunks.InitTrunks(config, qos, logs, acm, disable_kernel_version_check)
if err != nil {
fmt.Println("Init error, exiting...")
os.Exit(1)
}
if flush {
err = trunksConfig.FlushTables()
if err != nil {
fmt.Println("Impossible to flush tables, exiting...")
os.Exit(1)
}
}
trunksConfig.Run()
return nil
},
}
go initSignals()
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}