fix: fix package name rules match

This commit is contained in:
gVisor bot 2023-11-17 19:39:57 +08:00
parent 923f3cc1e3
commit 320b3babc1
3 changed files with 23 additions and 7 deletions

View File

@ -3,7 +3,6 @@ package inbound
import (
C "github.com/metacubex/mihomo/constant"
"github.com/metacubex/mihomo/transport/socks5"
"github.com/metacubex/mihomo/constant/features"
)
// NewPacket is PacketAdapter generator

View File

@ -3,6 +3,7 @@ package process
import (
"errors"
"net/netip"
"github.com/metacubex/mihomo/constant"
)
var (
@ -19,3 +20,7 @@ const (
func FindProcessName(network string, srcIP netip.Addr, srcPort int) (uint32, string, error) {
return findProcessName(network, srcIP, srcPort)
}
func FindPackageName(metadata *constant.Metadata) (string, error) {
return "", nil
}

View File

@ -18,6 +18,7 @@ import (
"github.com/metacubex/mihomo/component/resolver"
"github.com/metacubex/mihomo/component/sniffer"
C "github.com/metacubex/mihomo/constant"
"github.com/metacubex/mihomo/constant/features"
"github.com/metacubex/mihomo/constant/provider"
icontext "github.com/metacubex/mihomo/context"
"github.com/metacubex/mihomo/log"
@ -620,14 +621,25 @@ func match(metadata *C.Metadata) (C.Proxy, C.Rule, error) {
if attemptProcessLookup && !findProcessMode.Off() && (findProcessMode.Always() || rule.ShouldFindProcess()) {
attemptProcessLookup = false
if !features.Contains("cmfa") {
// normal check for process
uid, path, err := P.FindProcessName(metadata.NetWork.String(), metadata.SrcIP, int(metadata.SrcPort))
if err != nil {
log.Debugln("[Process] find process %s: %v", metadata.String(), err)
log.Debugln("[Process] find process %s error: %v", metadata.String(), err)
} else {
metadata.Process = filepath.Base(path)
metadata.ProcessPath = path
metadata.Uid = uid
}
} else {
// check package names
pkg, err := P.FindPackageName(metadata)
if err != nil {
log.Debugln("[Process] find process %s error: %v", metadata.String(), err)
} else {
metadata.Process = pkg
}
}
}
if matched, ada := rule.Match(metadata); matched {