-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
102 lines (95 loc) · 2.35 KB
/
main.go
File metadata and controls
102 lines (95 loc) · 2.35 KB
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
101
102
package main
import (
"fmt"
"log"
"os"
"os/signal"
"syscall"
tlink "github.com/ljysdfz/tlink/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: "tlink",
Usage: "a telecommunication link simulator",
EnableBashCompletion: true,
Authors: []*cli.Author{
{Name: "CTRI CyberRange Team"},
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
Usage: "Load configuration from `FILE`",
Destination: &config,
Required: true,
DefaultText: "not set",
},
&cli.BoolFlag{
Name: "flush",
Aliases: []string{"f"},
Usage: "Flush IPTABLES table mangle and clear all TC rules",
Destination: &flush,
},
// &cli.StringFlag{
// Name: "logs",
// Usage: "Log path for the log file",
// Destination: &logs,
// Required: false,
// DefaultText: "not set",
// },
// &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 := tlink.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)
}
}