mirror of
https://github.com/net-byte/vtun
synced 2024-03-14 10:50:03 +08:00
update route on mac
This commit is contained in:
parent
e7a3807389
commit
0ba21e6641
@ -11,7 +11,6 @@ type Config struct {
|
||||
LocalAddr string
|
||||
ServerAddr string
|
||||
CIDR string
|
||||
Gateway string
|
||||
Key string
|
||||
Protocol string
|
||||
ServerMode bool
|
||||
|
@ -100,7 +100,7 @@ func getAllPhysicalInterfaces() []net.Interface {
|
||||
}
|
||||
|
||||
func isPhysicalInterface(addr string) bool {
|
||||
prefixArray := []string{"ens", "enp", "enx", "eth", "wlan", "wlp"}
|
||||
prefixArray := []string{"ens", "enp", "enx", "eth", "en0", "wlan", "wlp"}
|
||||
for _, pref := range prefixArray {
|
||||
if strings.HasPrefix(strings.ToLower(addr), pref) {
|
||||
return true
|
||||
|
22
tun/tun.go
22
tun/tun.go
@ -38,20 +38,30 @@ func configTun(config config.Config, iface *water.Interface) {
|
||||
physicalIface, gateway, _ := netutil.GetPhysicalInterface()
|
||||
serverIP := netutil.LookupIP(strings.Split(config.ServerAddr, ":")[0])
|
||||
if physicalIface != "" && serverIP != "" {
|
||||
execCmd("/sbin/ip", "route", "add", "0.0.0.0/0", "dev", iface.Name())
|
||||
execCmd("/sbin/ip", "route", "add", "0.0.0.0/1", "dev", iface.Name())
|
||||
execCmd("/sbin/ip", "route", "add", "128.0.0.0/1", "dev", iface.Name())
|
||||
execCmd("/sbin/ip", "route", "delete", strings.Join([]string{serverIP, "32"}, "/"), "via", gateway, "dev", physicalIface)
|
||||
execCmd("/sbin/ip", "route", "add", strings.Join([]string{serverIP, "32"}, "/"), "via", gateway, "dev", physicalIface)
|
||||
}
|
||||
}
|
||||
|
||||
} else if os == "darwin" {
|
||||
execCmd("ifconfig", iface.Name(), "inet", ip.String(), config.Gateway, "up")
|
||||
gateway := ipNet.IP.To4()
|
||||
gateway[3]++
|
||||
execCmd("ifconfig", iface.Name(), "inet", ip.String(), gateway.String(), "up")
|
||||
physicalIface, localGateway, _ := netutil.GetPhysicalInterface()
|
||||
if config.GlobalMode {
|
||||
_, _, localNetwork := netutil.GetPhysicalInterface()
|
||||
if localNetwork != "" {
|
||||
execCmd("route", "add", "0.0.0.0/0", "-interface", iface.Name())
|
||||
execCmd("route", "add", localNetwork, "-interface", ipNet.IP.To4().String())
|
||||
serverIP := netutil.LookupIP(strings.Split(config.ServerAddr, ":")[0])
|
||||
if physicalIface != "" && serverIP != "" {
|
||||
execCmd("route", "add", serverIP, localGateway)
|
||||
execCmd("route", "add", "0.0.0.0/1", "-interface", iface.Name())
|
||||
execCmd("route", "add", "128.0.0.0/1", "-interface", iface.Name())
|
||||
execCmd("route", "add", "default", gateway.String())
|
||||
execCmd("route", "change", "default", gateway.String())
|
||||
}
|
||||
} else {
|
||||
execCmd("route", "add", "default", localGateway)
|
||||
execCmd("route", "change", "default", localGateway)
|
||||
}
|
||||
} else {
|
||||
log.Printf("not support os:%v", os)
|
||||
|
Loading…
Reference in New Issue
Block a user