mirror of
https://github.com/net-byte/vtun
synced 2024-03-14 10:50:03 +08:00
fix global mode
This commit is contained in:
parent
8d6346e82e
commit
a79dd76fd6
14
main.go
14
main.go
@ -42,13 +42,15 @@ func main() {
|
||||
}
|
||||
|
||||
func initConfig(config *config.Config) {
|
||||
cipher.GenerateKey(config.Key)
|
||||
os := runtime.GOOS
|
||||
if os == "linux" {
|
||||
config.DefaultGateway = netutil.GetLinuxDefaultGateway()
|
||||
} else if os == "darwin" {
|
||||
config.DefaultGateway = netutil.GetMacDefaultGateway()
|
||||
if !config.ServerMode {
|
||||
os := runtime.GOOS
|
||||
if os == "linux" {
|
||||
config.DefaultGateway = netutil.GetLinuxDefaultGateway()
|
||||
} else if os == "darwin" {
|
||||
config.DefaultGateway = netutil.GetMacDefaultGateway()
|
||||
}
|
||||
}
|
||||
cipher.GenerateKey(config.Key)
|
||||
json, _ := json.Marshal(config)
|
||||
log.Printf("init config:%s", string(json))
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ func configTun(config config.Config, iface *water.Interface) {
|
||||
netutil.ExecCmd("/sbin/ip", "link", "set", "dev", iface.Name(), "mtu", strconv.Itoa(config.MTU))
|
||||
netutil.ExecCmd("/sbin/ip", "addr", "add", config.CIDR, "dev", iface.Name())
|
||||
netutil.ExecCmd("/sbin/ip", "link", "set", "dev", iface.Name(), "up")
|
||||
if config.GlobalMode {
|
||||
if !config.ServerMode && config.GlobalMode {
|
||||
physicalIface := netutil.GetPhysicalInterface()
|
||||
serverIP := netutil.LookupIP(strings.Split(config.ServerAddr, ":")[0])
|
||||
if physicalIface != "" && serverIP != "" {
|
||||
@ -48,8 +48,8 @@ func configTun(config config.Config, iface *water.Interface) {
|
||||
gateway := ipNet.IP.To4()
|
||||
gateway[3]++
|
||||
netutil.ExecCmd("ifconfig", iface.Name(), "inet", ip.String(), gateway.String(), "up")
|
||||
physicalIface := netutil.GetPhysicalInterface()
|
||||
if config.GlobalMode {
|
||||
if !config.ServerMode && config.GlobalMode {
|
||||
physicalIface := netutil.GetPhysicalInterface()
|
||||
serverIP := netutil.LookupIP(strings.Split(config.ServerAddr, ":")[0])
|
||||
if physicalIface != "" && serverIP != "" {
|
||||
netutil.ExecCmd("route", "add", serverIP, config.DefaultGateway)
|
||||
@ -67,7 +67,7 @@ func configTun(config config.Config, iface *water.Interface) {
|
||||
|
||||
func Reset(config config.Config) {
|
||||
os := runtime.GOOS
|
||||
if os == "darwin" && config.GlobalMode {
|
||||
if os == "darwin" && !config.ServerMode && config.GlobalMode {
|
||||
netutil.ExecCmd("route", "add", "default", config.DefaultGateway)
|
||||
netutil.ExecCmd("route", "change", "default", config.DefaultGateway)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user