diff --git a/constant/metadata.go b/constant/metadata.go index fe1b7c50..4ddb1bd9 100644 --- a/constant/metadata.go +++ b/constant/metadata.go @@ -83,7 +83,7 @@ type Metadata struct { AddrType int `json:"-"` Host string `json:"host"` DNSMode DNSMode `json:"dnsMode"` - Uid int32 `json:"uid"` + Uid *int32 `json:"uid"` Process string `json:"process"` ProcessPath string `json:"processPath"` } @@ -101,10 +101,10 @@ func (m *Metadata) SourceDetail() string { return fmt.Sprintf("[%s]", ClashName) } - if m.Process != "" && m.Uid != 0 { - return fmt.Sprintf("%s(%s, uid=%d)", m.SourceAddress(), m.Process, m.Uid) - } else if m.Uid != 0 { - return fmt.Sprintf("%s(%d)", m.SourceAddress(), m.Uid) + if m.Process != "" && m.Uid != nil { + return fmt.Sprintf("%s(%s, uid=%d)", m.SourceAddress(), m.Process, *m.Uid) + } else if m.Uid != nil { + return fmt.Sprintf("%s(%d)", m.SourceAddress(), *m.Uid) } else if m.Process != "" { return fmt.Sprintf("%s(%s)", m.SourceAddress(), m.Process) } else { diff --git a/rule/common/uid.go b/rule/common/uid.go index 2ab1beb6..00f0c3d8 100644 --- a/rule/common/uid.go +++ b/rule/common/uid.go @@ -72,10 +72,10 @@ func (u *Uid) Match(metadata *C.Metadata) bool { return false } var uid int32 - if metadata.Uid != 0 { - uid = metadata.Uid + if metadata.Uid != nil { + uid = *metadata.Uid } else if uid, err = process.FindUid(metadata.NetWork.String(), metadata.SrcIP, srcPort); err == nil { - metadata.Uid = uid + metadata.Uid = &uid } else { log.Warnln("[UID] could not get uid from %s", metadata.String()) return false