feat: cache uid
This commit is contained in:
parent
931d5dd5b3
commit
162dcd56e6
2 changed files with 20 additions and 6 deletions
|
@ -83,6 +83,7 @@ type Metadata struct {
|
||||||
AddrType int `json:"-"`
|
AddrType int `json:"-"`
|
||||||
Host string `json:"host"`
|
Host string `json:"host"`
|
||||||
DNSMode DNSMode `json:"dnsMode"`
|
DNSMode DNSMode `json:"dnsMode"`
|
||||||
|
Uid int32 `json:"uid"`
|
||||||
Process string `json:"process"`
|
Process string `json:"process"`
|
||||||
ProcessPath string `json:"processPath"`
|
ProcessPath string `json:"processPath"`
|
||||||
}
|
}
|
||||||
|
@ -100,7 +101,11 @@ func (m *Metadata) SourceDetail() string {
|
||||||
return fmt.Sprintf("[%s]", ClashName)
|
return fmt.Sprintf("[%s]", ClashName)
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.Process != "" {
|
if m.Process != "" && m.Uid != 0 {
|
||||||
|
return fmt.Sprintf("%s(%s:%d)", m.SourceAddress(), m.Process, m.Uid)
|
||||||
|
} else if m.Uid != 0 {
|
||||||
|
return fmt.Sprintf("%s(%d)", m.SourceAddress(), m.Uid)
|
||||||
|
} else if m.Process != "" {
|
||||||
return fmt.Sprintf("%s(%s)", m.SourceAddress(), m.Process)
|
return fmt.Sprintf("%s(%s)", m.SourceAddress(), m.Process)
|
||||||
} else {
|
} else {
|
||||||
return fmt.Sprintf("%s", m.SourceAddress())
|
return fmt.Sprintf("%s", m.SourceAddress())
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"github.com/Dreamacro/clash/common/utils"
|
"github.com/Dreamacro/clash/common/utils"
|
||||||
"github.com/Dreamacro/clash/component/process"
|
"github.com/Dreamacro/clash/component/process"
|
||||||
C "github.com/Dreamacro/clash/constant"
|
C "github.com/Dreamacro/clash/constant"
|
||||||
|
"github.com/Dreamacro/clash/log"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
@ -70,11 +71,19 @@ func (u *Uid) Match(metadata *C.Metadata) bool {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if uid, err := process.FindUid(metadata.NetWork.String(), metadata.SrcIP, srcPort); err == nil {
|
var uid int32
|
||||||
for _, _uid := range u.uids {
|
if metadata.Uid != 0 {
|
||||||
if _uid.Contains(uid) {
|
uid = metadata.Uid
|
||||||
return true
|
} else if uid, err := process.FindUid(metadata.NetWork.String(), metadata.SrcIP, srcPort); err == nil {
|
||||||
}
|
metadata.Uid = uid
|
||||||
|
} else {
|
||||||
|
log.Warnln("[UID] could not get uid from %s", metadata.String())
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, _uid := range u.uids {
|
||||||
|
if _uid.Contains(uid) {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|
Loading…
Reference in a new issue