Chore: allow tunnels don't set special proxy

This commit is contained in:
gVisor bot 2022-11-28 20:31:32 +08:00
parent a3873404ba
commit cc1f051d99
3 changed files with 8 additions and 10 deletions

View file

@ -340,7 +340,7 @@ func (t *Tunnel) UnmarshalYAML(unmarshal func(any) error) error {
parts := lo.Map(strings.Split(tp, ","), func(s string, _ int) string { parts := lo.Map(strings.Split(tp, ","), func(s string, _ int) string {
return strings.TrimSpace(s) return strings.TrimSpace(s)
}) })
if len(parts) != 4 { if len(parts) != 3 && len(parts) != 4 {
return fmt.Errorf("invalid tunnel config %s", tp) return fmt.Errorf("invalid tunnel config %s", tp)
} }
network := strings.Split(parts[0], "/") network := strings.Split(parts[0], "/")
@ -367,8 +367,10 @@ func (t *Tunnel) UnmarshalYAML(unmarshal func(any) error) error {
Network: network, Network: network,
Address: address, Address: address,
Target: target, Target: target,
Proxy: parts[3],
}) })
if len(parts) == 4 {
t.Proxy = parts[3]
}
return nil return nil
} }
@ -620,8 +622,10 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) {
config.Tunnels = rawCfg.Tunnels config.Tunnels = rawCfg.Tunnels
// verify tunnels // verify tunnels
for _, t := range config.Tunnels { for _, t := range config.Tunnels {
if _, ok := config.Proxies[t.Proxy]; !ok { if len(t.Proxy) > 0 {
return nil, fmt.Errorf("tunnel proxy %s not found", t.Proxy) if _, ok := config.Proxies[t.Proxy]; !ok {
return nil, fmt.Errorf("tunnel proxy %s not found", t.Proxy)
}
} }
} }

View file

@ -6,7 +6,6 @@ import (
"github.com/Dreamacro/clash/adapter/inbound" "github.com/Dreamacro/clash/adapter/inbound"
C "github.com/Dreamacro/clash/constant" C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/log"
"github.com/Dreamacro/clash/transport/socks5" "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) return nil, fmt.Errorf("invalid target address %s", target)
} }
log.Infoln("TCP tunnel %s <-> %s", l.Addr().String(), target)
rl := &Listener{ rl := &Listener{
listener: l, listener: l,
target: targetAddr, target: targetAddr,

View file

@ -7,7 +7,6 @@ import (
"github.com/Dreamacro/clash/adapter/inbound" "github.com/Dreamacro/clash/adapter/inbound"
"github.com/Dreamacro/clash/common/pool" "github.com/Dreamacro/clash/common/pool"
C "github.com/Dreamacro/clash/constant" C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/log"
"github.com/Dreamacro/clash/transport/socks5" "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) return nil, fmt.Errorf("invalid target address %s", target)
} }
log.Infoln("Udp tunnel %s <-> %s", l.LocalAddr().String(), target)
sl := &PacketConn{ sl := &PacketConn{
conn: l, conn: l,
target: targetAddr, target: targetAddr,