From cc1f051d995a62dbf3f2c23de67b2cc564d1f5e1 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Mon, 28 Nov 2022 20:31:32 +0800 Subject: [PATCH] Chore: allow tunnels don't set special proxy --- config/config.go | 12 ++++++++---- listener/tunnel/tcp.go | 3 --- listener/tunnel/udp.go | 3 --- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/config/config.go b/config/config.go index 3f57a0a1..9033f162 100644 --- a/config/config.go +++ b/config/config.go @@ -340,7 +340,7 @@ func (t *Tunnel) UnmarshalYAML(unmarshal func(any) error) error { parts := lo.Map(strings.Split(tp, ","), func(s string, _ int) string { return strings.TrimSpace(s) }) - if len(parts) != 4 { + if len(parts) != 3 && len(parts) != 4 { return fmt.Errorf("invalid tunnel config %s", tp) } network := strings.Split(parts[0], "/") @@ -367,8 +367,10 @@ func (t *Tunnel) UnmarshalYAML(unmarshal func(any) error) error { Network: network, Address: address, Target: target, - Proxy: parts[3], }) + if len(parts) == 4 { + t.Proxy = parts[3] + } return nil } @@ -620,8 +622,10 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) { config.Tunnels = rawCfg.Tunnels // verify tunnels for _, t := range config.Tunnels { - if _, ok := config.Proxies[t.Proxy]; !ok { - return nil, fmt.Errorf("tunnel proxy %s not found", t.Proxy) + if len(t.Proxy) > 0 { + if _, ok := config.Proxies[t.Proxy]; !ok { + return nil, fmt.Errorf("tunnel proxy %s not found", t.Proxy) + } } } diff --git a/listener/tunnel/tcp.go b/listener/tunnel/tcp.go index 58949550..4ae5865c 100644 --- a/listener/tunnel/tcp.go +++ b/listener/tunnel/tcp.go @@ -6,7 +6,6 @@ import ( "github.com/Dreamacro/clash/adapter/inbound" C "github.com/Dreamacro/clash/constant" - "github.com/Dreamacro/clash/log" "github.com/Dreamacro/clash/transport/socks5" ) @@ -52,8 +51,6 @@ func New(addr, target, proxy string, in chan<- C.ConnContext) (*Listener, error) return nil, fmt.Errorf("invalid target address %s", target) } - log.Infoln("TCP tunnel %s <-> %s", l.Addr().String(), target) - rl := &Listener{ listener: l, target: targetAddr, diff --git a/listener/tunnel/udp.go b/listener/tunnel/udp.go index 22e194a9..ee0ecbaf 100644 --- a/listener/tunnel/udp.go +++ b/listener/tunnel/udp.go @@ -7,7 +7,6 @@ import ( "github.com/Dreamacro/clash/adapter/inbound" "github.com/Dreamacro/clash/common/pool" C "github.com/Dreamacro/clash/constant" - "github.com/Dreamacro/clash/log" "github.com/Dreamacro/clash/transport/socks5" ) @@ -46,8 +45,6 @@ func NewUDP(addr, target, proxy string, in chan<- *inbound.PacketAdapter) (*Pack return nil, fmt.Errorf("invalid target address %s", target) } - log.Infoln("Udp tunnel %s <-> %s", l.LocalAddr().String(), target) - sl := &PacketConn{ conn: l, target: targetAddr,