diff --git a/adapter/inbound/socket.go b/adapter/inbound/socket.go index cca260c6..ebb2095e 100644 --- a/adapter/inbound/socket.go +++ b/adapter/inbound/socket.go @@ -28,7 +28,7 @@ func NewInner(conn net.Conn, dst string, host string) *context.ConnContext { metadata.DNSMode = C.DNSMapping metadata.Host = host metadata.AddrType = C.AtypDomainName - + metadata.Process = C.ClashName if ip, port, err := parseAddr(dst); err == nil { metadata.DstPort = port if host == "" { diff --git a/constant/version.go b/constant/version.go index 5a511382..1d4e6e7b 100644 --- a/constant/version.go +++ b/constant/version.go @@ -5,4 +5,5 @@ var ( Version = "1.9.0" BuildTime = "unknown time" AutoIptables string + ClashName = "Clash.Meta" ) diff --git a/rule/common/process.go b/rule/common/process.go index 47731443..669714ec 100644 --- a/rule/common/process.go +++ b/rule/common/process.go @@ -35,26 +35,28 @@ func (ps *Process) Match(metadata *C.Metadata) bool { } key := fmt.Sprintf("%s:%s:%s", metadata.NetWork.String(), metadata.SrcIP.String(), metadata.SrcPort) - cached, hit := processCache.Get(key) - if !hit { - srcPort, err := strconv.Atoi(metadata.SrcPort) - if err != nil { - processCache.Set(key, "") - return false + if strings.TrimSpace(metadata.Process) == "" { + cached, hit := processCache.Get(key) + if !hit { + srcPort, err := strconv.Atoi(metadata.SrcPort) + if err != nil { + processCache.Set(key, "") + return false + } + + name, err := process.FindProcessName(metadata.NetWork.String(), metadata.SrcIP, srcPort) + if err != nil { + log.Debugln("[Rule] find process name %s error: %s", C.Process.String(), err.Error()) + } + + processCache.Set(key, name) + + cached = name } - name, err := process.FindProcessName(metadata.NetWork.String(), metadata.SrcIP, srcPort) - if err != nil { - log.Debugln("[Rule] find process name %s error: %s", C.Process.String(), err.Error()) - } - - processCache.Set(key, name) - - cached = name + metadata.Process = cached.(string) } - metadata.Process = cached.(string) - return strings.EqualFold(metadata.Process, ps.process) }