mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-03-05 13:37:30 +00:00
chore: the resolve and findProcess behaviors of Logic and SubRules follow the order and needs of the internal rules
This commit is contained in:
@@ -21,14 +21,6 @@ var (
|
||||
type Base struct {
|
||||
}
|
||||
|
||||
func (b *Base) ShouldFindProcess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (b *Base) ShouldResolveIP() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (b *Base) ProviderNames() []string { return nil }
|
||||
|
||||
func ParseParams(params []string) (isSrc bool, noResolve bool) {
|
||||
|
||||
@@ -17,7 +17,7 @@ func (d *Domain) RuleType() C.RuleType {
|
||||
return C.Domain
|
||||
}
|
||||
|
||||
func (d *Domain) Match(metadata *C.Metadata) (bool, string) {
|
||||
func (d *Domain) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
|
||||
return metadata.RuleHost() == d.domain, d.adapter
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ func (dk *DomainKeyword) RuleType() C.RuleType {
|
||||
return C.DomainKeyword
|
||||
}
|
||||
|
||||
func (dk *DomainKeyword) Match(metadata *C.Metadata) (bool, string) {
|
||||
func (dk *DomainKeyword) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
|
||||
domain := metadata.RuleHost()
|
||||
return strings.Contains(domain, dk.keyword), dk.adapter
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ func (dr *DomainRegex) RuleType() C.RuleType {
|
||||
return C.DomainRegex
|
||||
}
|
||||
|
||||
func (dr *DomainRegex) Match(metadata *C.Metadata) (bool, string) {
|
||||
func (dr *DomainRegex) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
|
||||
domain := metadata.RuleHost()
|
||||
match, _ := dr.regex.MatchString(domain)
|
||||
return match, dr.adapter
|
||||
|
||||
@@ -17,7 +17,7 @@ func (ds *DomainSuffix) RuleType() C.RuleType {
|
||||
return C.DomainSuffix
|
||||
}
|
||||
|
||||
func (ds *DomainSuffix) Match(metadata *C.Metadata) (bool, string) {
|
||||
func (ds *DomainSuffix) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
|
||||
domain := metadata.RuleHost()
|
||||
return strings.HasSuffix(domain, "."+ds.suffix) || domain == ds.suffix, ds.adapter
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ func (d *DSCP) RuleType() C.RuleType {
|
||||
return C.DSCP
|
||||
}
|
||||
|
||||
func (d *DSCP) Match(metadata *C.Metadata) (bool, string) {
|
||||
func (d *DSCP) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
|
||||
return d.ranges.Check(metadata.DSCP), d.adapter
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ func (f *Match) RuleType() C.RuleType {
|
||||
return C.MATCH
|
||||
}
|
||||
|
||||
func (f *Match) Match(metadata *C.Metadata) (bool, string) {
|
||||
func (f *Match) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
|
||||
return true, f.adapter
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,11 @@ func (g *GEOIP) RuleType() C.RuleType {
|
||||
return C.GEOIP
|
||||
}
|
||||
|
||||
func (g *GEOIP) Match(metadata *C.Metadata) (bool, string) {
|
||||
func (g *GEOIP) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
|
||||
if !g.noResolveIP && !g.isSourceIP && helper.ResolveIP != nil {
|
||||
helper.ResolveIP()
|
||||
}
|
||||
|
||||
ip := metadata.DstIP
|
||||
if g.isSourceIP {
|
||||
ip = metadata.SrcIP
|
||||
@@ -161,10 +165,6 @@ func (g *GEOIP) Payload() string {
|
||||
return g.country
|
||||
}
|
||||
|
||||
func (g *GEOIP) ShouldResolveIP() bool {
|
||||
return !g.noResolveIP
|
||||
}
|
||||
|
||||
func (g *GEOIP) GetCountry() string {
|
||||
return g.country
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func (gs *GEOSITE) RuleType() C.RuleType {
|
||||
return C.GEOSITE
|
||||
}
|
||||
|
||||
func (gs *GEOSITE) Match(metadata *C.Metadata) (bool, string) {
|
||||
func (gs *GEOSITE) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
|
||||
return gs.MatchDomain(metadata.RuleHost()), gs.adapter
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ type InName struct {
|
||||
payload string
|
||||
}
|
||||
|
||||
func (u *InName) Match(metadata *C.Metadata) (bool, string) {
|
||||
func (u *InName) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
|
||||
for _, name := range u.names {
|
||||
if metadata.InName == name {
|
||||
return true, u.adapter
|
||||
|
||||
@@ -13,7 +13,7 @@ type InType struct {
|
||||
payload string
|
||||
}
|
||||
|
||||
func (u *InType) Match(metadata *C.Metadata) (bool, string) {
|
||||
func (u *InType) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
|
||||
for _, tp := range u.types {
|
||||
if metadata.Type == tp {
|
||||
return true, u.adapter
|
||||
|
||||
@@ -13,7 +13,7 @@ type InUser struct {
|
||||
payload string
|
||||
}
|
||||
|
||||
func (u *InUser) Match(metadata *C.Metadata) (bool, string) {
|
||||
func (u *InUser) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
|
||||
for _, user := range u.users {
|
||||
if metadata.InUser == user {
|
||||
return true, u.adapter
|
||||
|
||||
@@ -15,7 +15,11 @@ type ASN struct {
|
||||
isSourceIP bool
|
||||
}
|
||||
|
||||
func (a *ASN) Match(metadata *C.Metadata) (bool, string) {
|
||||
func (a *ASN) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
|
||||
if !a.noResolveIP && !a.isSourceIP && helper.ResolveIP != nil {
|
||||
helper.ResolveIP()
|
||||
}
|
||||
|
||||
ip := metadata.DstIP
|
||||
if a.isSourceIP {
|
||||
ip = metadata.SrcIP
|
||||
@@ -49,10 +53,6 @@ func (a *ASN) Payload() string {
|
||||
return a.asn
|
||||
}
|
||||
|
||||
func (a *ASN) ShouldResolveIP() bool {
|
||||
return !a.noResolveIP
|
||||
}
|
||||
|
||||
func (a *ASN) GetASN() string {
|
||||
return a.asn
|
||||
}
|
||||
|
||||
@@ -35,7 +35,11 @@ func (i *IPCIDR) RuleType() C.RuleType {
|
||||
return C.IPCIDR
|
||||
}
|
||||
|
||||
func (i *IPCIDR) Match(metadata *C.Metadata) (bool, string) {
|
||||
func (i *IPCIDR) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
|
||||
if !i.noResolveIP && !i.isSourceIP && helper.ResolveIP != nil {
|
||||
helper.ResolveIP()
|
||||
}
|
||||
|
||||
ip := metadata.DstIP
|
||||
if i.isSourceIP {
|
||||
ip = metadata.SrcIP
|
||||
@@ -51,10 +55,6 @@ func (i *IPCIDR) Payload() string {
|
||||
return i.ipnet.String()
|
||||
}
|
||||
|
||||
func (i *IPCIDR) ShouldResolveIP() bool {
|
||||
return !i.noResolveIP
|
||||
}
|
||||
|
||||
func NewIPCIDR(s string, adapter string, opts ...IPCIDROption) (*IPCIDR, error) {
|
||||
ipnet, err := netip.ParsePrefix(s)
|
||||
if err != nil {
|
||||
|
||||
@@ -22,7 +22,11 @@ func (is *IPSuffix) RuleType() C.RuleType {
|
||||
return C.IPSuffix
|
||||
}
|
||||
|
||||
func (is *IPSuffix) Match(metadata *C.Metadata) (bool, string) {
|
||||
func (is *IPSuffix) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
|
||||
if !is.noResolveIP && !is.isSourceIP && helper.ResolveIP != nil {
|
||||
helper.ResolveIP()
|
||||
}
|
||||
|
||||
ip := metadata.DstIP
|
||||
if is.isSourceIP {
|
||||
ip = metadata.SrcIP
|
||||
@@ -57,10 +61,6 @@ func (is *IPSuffix) Payload() string {
|
||||
return is.payload
|
||||
}
|
||||
|
||||
func (is *IPSuffix) ShouldResolveIP() bool {
|
||||
return !is.noResolveIP
|
||||
}
|
||||
|
||||
func NewIPSuffix(payload, adapter string, isSrc, noResolveIP bool) (*IPSuffix, error) {
|
||||
ipnet, err := netip.ParsePrefix(payload)
|
||||
if err != nil {
|
||||
|
||||
@@ -34,7 +34,7 @@ func (n *NetworkType) RuleType() C.RuleType {
|
||||
return C.Network
|
||||
}
|
||||
|
||||
func (n *NetworkType) Match(metadata *C.Metadata) (bool, string) {
|
||||
func (n *NetworkType) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
|
||||
return n.network == metadata.NetWork, n.adapter
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ func (p *Port) RuleType() C.RuleType {
|
||||
return p.ruleType
|
||||
}
|
||||
|
||||
func (p *Port) Match(metadata *C.Metadata) (bool, string) {
|
||||
func (p *Port) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
|
||||
targetPort := metadata.DstPort
|
||||
switch p.ruleType {
|
||||
case C.InPort:
|
||||
|
||||
@@ -30,7 +30,10 @@ func (ps *Process) RuleType() C.RuleType {
|
||||
return C.ProcessPath
|
||||
}
|
||||
|
||||
func (ps *Process) Match(metadata *C.Metadata) (bool, string) {
|
||||
func (ps *Process) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
|
||||
if helper.FindProcess != nil {
|
||||
helper.FindProcess()
|
||||
}
|
||||
if ps.nameOnly {
|
||||
if ps.regexp != nil {
|
||||
match, _ := ps.regexp.MatchString(metadata.Process)
|
||||
@@ -54,10 +57,6 @@ func (ps *Process) Payload() string {
|
||||
return ps.process
|
||||
}
|
||||
|
||||
func (ps *Process) ShouldFindProcess() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func NewProcess(process string, adapter string, nameOnly bool, regex bool) (*Process, error) {
|
||||
var r *regexp2.Regexp
|
||||
var err error
|
||||
|
||||
@@ -41,7 +41,10 @@ func (u *Uid) RuleType() C.RuleType {
|
||||
return C.Uid
|
||||
}
|
||||
|
||||
func (u *Uid) Match(metadata *C.Metadata) (bool, string) {
|
||||
func (u *Uid) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
|
||||
if helper.FindProcess != nil {
|
||||
helper.FindProcess()
|
||||
}
|
||||
if metadata.Uid != 0 {
|
||||
if u.uids.Check(metadata.Uid) {
|
||||
return true, u.adapter
|
||||
@@ -58,7 +61,3 @@ func (u *Uid) Adapter() string {
|
||||
func (u *Uid) Payload() string {
|
||||
return u.oUid
|
||||
}
|
||||
|
||||
func (u *Uid) ShouldFindProcess() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user