From e2a0437685301b753dfb73480b689176ddde7700 Mon Sep 17 00:00:00 2001 From: "Maze.tsz" Date: Mon, 27 Dec 2021 03:16:48 +0800 Subject: [PATCH] [fix] --- hub/route/configs.go | 2 +- listener/tun/dev/dev.go | 5 ++++- listener/tun/dev/dev_linux.go | 4 ++-- listener/tun/dev/dev_windows_extra.go | 2 +- listener/tun/ipstack/gvisor/tun.go | 2 +- listener/tun/tun_adapter.go | 2 +- 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/hub/route/configs.go b/hub/route/configs.go index 1a9ac8ce..99337dd9 100644 --- a/hub/route/configs.go +++ b/hub/route/configs.go @@ -79,7 +79,7 @@ func patchConfigs(w http.ResponseWriter, r *http.Request) { P.ReCreateMixed(pointerOrDefault(general.MixedPort, ports.MixedPort), tcpIn, udpIn) if general.Tun != nil { - err := P.ReCreateTun(*general.Tun, nil, nil) + err := P.ReCreateTun(*general.Tun, tcpIn, udpIn) if err == nil { log.Infoln("Recreate tun success.") } else { diff --git a/listener/tun/dev/dev.go b/listener/tun/dev/dev.go index 56d85f26..13dca8d5 100644 --- a/listener/tun/dev/dev.go +++ b/listener/tun/dev/dev.go @@ -1,6 +1,7 @@ package dev import ( + "bytes" "os/exec" "runtime" @@ -49,8 +50,10 @@ func addLinuxSystemRoute(net string) { return } cmd := exec.Command("route", "add", "-net", net, "198.18.0.1") + var stderr bytes.Buffer + cmd.Stderr = &stderr if err := cmd.Run(); err != nil { - log.Errorln("[auto route] Failed to add system route: %s, cmd: %s", err.Error(), cmd.String()) + log.Errorln("[auto route] Failed to add system route: %s: %s , cmd: %s", err.Error(), stderr.String(), cmd.String()) } } diff --git a/listener/tun/dev/dev_linux.go b/listener/tun/dev/dev_linux.go index ed4e265a..c4f1cd92 100644 --- a/listener/tun/dev/dev_linux.go +++ b/listener/tun/dev/dev_linux.go @@ -38,7 +38,7 @@ type tunLinux struct { // OpenTunDevice return a TunDevice according a URL func OpenTunDevice(tunAddress string, autoRoute bool) (TunDevice, error) { - deviceURL, _ := url.Parse("dev://clash0") + deviceURL, _ := url.Parse("dev://utun") mtu, _ := strconv.ParseInt(deviceURL.Query().Get("mtu"), 0, 32) t := &tunLinux{ @@ -204,7 +204,7 @@ func (t *tunLinux) configInterface() error { } // set netmask for tun - netmask := []byte{255, 255, 255, 0} + netmask := []byte{255, 255, 0, 0} copy(ifr[unix.IFNAMSIZ+4:], netmask) _, _, errno = unix.Syscall( diff --git a/listener/tun/dev/dev_windows_extra.go b/listener/tun/dev/dev_windows_extra.go index e5c0d301..e4b1193f 100644 --- a/listener/tun/dev/dev_windows_extra.go +++ b/listener/tun/dev/dev_windows_extra.go @@ -50,7 +50,7 @@ func OpenTunDevice(tunAddress string, autoRoute bool) (TunDevice, error) { log.Warnln("Error parese GUID from string: %v", err) } - interfaceName := "Clash.Mini" + interfaceName := "Meta Tunnel" mtu := 9000 tun, err := CreateTUN(interfaceName, mtu, tunAddress, autoRoute) diff --git a/listener/tun/ipstack/gvisor/tun.go b/listener/tun/ipstack/gvisor/tun.go index c9f57641..5e89969d 100644 --- a/listener/tun/ipstack/gvisor/tun.go +++ b/listener/tun/ipstack/gvisor/tun.go @@ -48,7 +48,7 @@ type gvisorAdapter struct { } // GvisorAdapter create GvisorAdapter -func NewAdapter(device dev.TunDevice, conf config.Tun, tunAddress string, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.PacketAdapter) (ipstack.TunAdapter, error) { +func NewAdapter(device dev.TunDevice, conf config.Tun, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.PacketAdapter) (ipstack.TunAdapter, error) { ipstack := stack.New(stack.Options{ NetworkProtocols: []stack.NetworkProtocolFactory{ipv4.NewProtocol, ipv6.NewProtocol}, TransportProtocols: []stack.TransportProtocolFactory{tcp.NewProtocol, udp.NewProtocol}, diff --git a/listener/tun/tun_adapter.go b/listener/tun/tun_adapter.go index 3f232dab..882eaabe 100644 --- a/listener/tun/tun_adapter.go +++ b/listener/tun/tun_adapter.go @@ -47,7 +47,7 @@ func New(conf config.Tun, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.Pack if strings.EqualFold(stack, "system") { tunAdapter, err = system.NewAdapter(device, conf, mtu, tunAddress, tunAddress, func() {}, tcpIn, udpIn) } else if strings.EqualFold(stack, "gvisor") { - tunAdapter, err = gvisor.NewAdapter(device, conf, tunAddress, tcpIn, udpIn) + tunAdapter, err = gvisor.NewAdapter(device, conf, tcpIn, udpIn) } else { err = fmt.Errorf("can not support tun ip stack: %s, only support \"lwip\" \"system\" and \"gvisor\"", stack) }