-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
80 lines (64 loc) · 2.29 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
package main
import (
"errors"
"os"
"os/signal"
"path/filepath"
"runtime"
"syscall"
"github.com/oddmario/tunnel-manager/config"
"github.com/oddmario/tunnel-manager/dynamicipupdater"
"github.com/oddmario/tunnel-manager/logger"
"github.com/oddmario/tunnel-manager/tunnel"
"github.com/oddmario/tunnel-manager/utils"
"github.com/oddmario/tunnel-manager/vars"
)
func main() {
logger.Init()
if runtime.GOOS != "linux" {
logger.Fatal("Sorry! Tunnel Manager can only run on Linux systems.")
}
args := os.Args[1:]
if len(args) >= 1 {
vars.ConfigFilePath = args[0]
} else {
vars.ConfigFilePath, _ = filepath.Abs("./config.json")
}
if _, err := os.Stat(vars.ConfigFilePath); errors.Is(err, os.ErrNotExist) {
logger.Fatal("The specified configuration file does not exist.")
}
logger.Info("Starting Tunnel Manager v" + vars.Version + "...")
config.LoadConfig()
tunnel.InitStorage()
defer func() {
tunnel.DestroyStorage(config.Config.Tunnels, config.Config.Mode, config.Config.MainNetworkInterface)
}()
var shouldEnableIPIPmod bool = false
var shouldEnableGREmod bool = false
var shouldEnableWGmod bool = false
for _, tun := range config.Config.Tunnels {
if tun.TunnelDriver == "gre" && !shouldEnableGREmod {
shouldEnableGREmod = true
}
if tun.TunnelDriver == "ipip" && !shouldEnableIPIPmod {
shouldEnableIPIPmod = true
}
if tun.TunnelDriver == "wireguard" && !shouldEnableWGmod {
shouldEnableWGmod = true
}
}
utils.SysTuning(shouldEnableIPIPmod, shouldEnableGREmod, shouldEnableWGmod, config.Config.Mode, config.Config.MainNetworkInterface, config.Config.ApplyKernelTuningTweaks)
if config.Config.DynamicIPUpdaterAPIIsEnabled {
if config.Config.Mode == "tunnel_host" {
go dynamicipupdater.InitServer()
} else {
logger.Warn("The dynamic IP updater API is meant to be enabled only on the tunnel host. Ignoring `dynamic_ip_updater_api.is_enabled`...")
}
}
for _, tun := range config.Config.Tunnels {
tun.Init(config.Config.Mode, config.Config.MainNetworkInterface, config.Config.DynamicIPUpdaterAPIListenPort, config.Config.DynamicIPUpdateInterval, config.Config.DynamicIPUpdateTimeout, config.Config.PingInterval, config.Config.PingTimeout)
}
quitChannel := make(chan os.Signal, 1)
signal.Notify(quitChannel, syscall.SIGINT, syscall.SIGTERM)
<-quitChannel
}