-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
54 lines (49 loc) · 1 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
package main
import (
"fmt"
"github.com/coreos/go-iptables/iptables"
"github.com/tatsushid/go-fastping"
"sync"
"time"
)
type TunnelInfo struct {
Ip string
Mark string
Weight int
ChainName string
RecoverCommand string
DownCommand string
status bool
lastlive time.Time
}
var (
tunnels map[string]*TunnelInfo
generatorLock sync.Mutex
ipt *iptables.IPTables
pin *fastping.Pinger
ip2tunnel map[string]string
)
func init() {
tunnels = make(map[string]*TunnelInfo)
ip2tunnel = make(map[string]string)
ipt, _ = iptables.New()
pin = fastping.NewPinger()
initConfig()
readConfig()
initLogger()
}
func main() {
defer logger.Close()
logger.Info("System start")
for name, t := range tunnels {
ip2tunnel[t.Ip] = name
pin.AddIP(t.Ip)
}
for n, t := range tunnels {
logger.Debug("[tunnel config]%s: %s", n, fmt.Sprint(*t))
}
for _, tunnel := range tunnels {
ipt.NewChain("mangle", tunnel.ChainName)
}
monitor()
}