From 0368bb418080bdb58cc7bd18ab9b490cc89a4d08 Mon Sep 17 00:00:00 2001 From: Skyxim Date: Sat, 23 Apr 2022 09:36:11 +0800 Subject: [PATCH] fix: sniffer port whitelist error --- component/sniffer/dispatcher.go | 2 ++ config/config.go | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/component/sniffer/dispatcher.go b/component/sniffer/dispatcher.go index 7bb52ebf..2d78fcdf 100644 --- a/component/sniffer/dispatcher.go +++ b/component/sniffer/dispatcher.go @@ -49,6 +49,8 @@ func (sd *SnifferDispatcher) TCPSniff(conn net.Conn, metadata *C.Metadata) { for _, portRange := range *sd.portRanges { if !portRange.Contains(uint16(port)) { return + } else { + break } } diff --git a/config/config.go b/config/config.go index 67843ff1..bf2a8745 100644 --- a/config/config.go +++ b/config/config.go @@ -4,6 +4,7 @@ import ( "container/list" "errors" "fmt" + "github.com/Dreamacro/clash/listener/tun/ipstack/commons" "net" "net/netip" "net/url" @@ -30,7 +31,6 @@ import ( C "github.com/Dreamacro/clash/constant" providerTypes "github.com/Dreamacro/clash/constant/provider" "github.com/Dreamacro/clash/dns" - "github.com/Dreamacro/clash/listener/tun/ipstack/commons" "github.com/Dreamacro/clash/log" T "github.com/Dreamacro/clash/tunnel" @@ -924,27 +924,28 @@ func parseSniffer(snifferRaw SnifferRaw) (*Sniffer, error) { Force: snifferRaw.Force, } - ports := []utils.Range[uint16]{} + var ports []utils.Range[uint16] if len(snifferRaw.Ports) == 0 { ports = append(ports, *utils.NewRange[uint16](0, 65535)) } else { for _, portRange := range snifferRaw.Ports { portRaws := strings.Split(portRange, "-") + p, err := strconv.ParseUint(portRaws[0], 10, 16) + if err != nil { + return nil, fmt.Errorf("%s format error", portRange) + } + + start := uint16(p) if len(portRaws) > 1 { - p, err := strconv.ParseUint(portRaws[0], 10, 16) - if err != nil { - return nil, fmt.Errorf("%s format error", portRange) - } - - start := uint16(p) - - p, err = strconv.ParseUint(portRaws[0], 10, 16) + p, err = strconv.ParseUint(portRaws[1], 10, 16) if err != nil { return nil, fmt.Errorf("%s format error", portRange) } end := uint16(p) ports = append(ports, *utils.NewRange(start, end)) + } else { + ports = append(ports, *utils.NewRange(start, start)) } } }