[Fixed] Fixed clash process name is Clash.Meta

This commit is contained in:
gVisor bot 2022-02-04 17:36:34 +08:00
parent b79eb1cea9
commit a8dafd434e
3 changed files with 20 additions and 17 deletions

View file

@ -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 == "" {

View file

@ -5,4 +5,5 @@ var (
Version = "1.9.0"
BuildTime = "unknown time"
AutoIptables string
ClashName = "Clash.Meta"
)

View file

@ -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)
}