mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-01-05 17:13:32 +08:00
feat: GEOIP
,IP-ASN
,IP-CIDR
,IP-CIDR6
and IP-SUFFIX
in rules support ,src
option
keep the same writing style as `RULE-SET`
This commit is contained in:
parent
763a127287
commit
38fd37108b
@ -8,8 +8,12 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
errPayload = errors.New("payloadRule error")
|
errPayload = errors.New("payloadRule error")
|
||||||
noResolve = "no-resolve"
|
)
|
||||||
src = "src"
|
|
||||||
|
// params
|
||||||
|
var (
|
||||||
|
NoResolve = "no-resolve"
|
||||||
|
Src = "src"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Base struct {
|
type Base struct {
|
||||||
@ -25,10 +29,12 @@ func (b *Base) ShouldResolveIP() bool {
|
|||||||
|
|
||||||
func (b *Base) ProviderNames() []string { return nil }
|
func (b *Base) ProviderNames() []string { return nil }
|
||||||
|
|
||||||
func HasNoResolve(params []string) bool {
|
func ParseParams(params []string) (isSrc bool, noResolve bool) {
|
||||||
return slices.Contains(params, noResolve)
|
isSrc = slices.Contains(params, Src)
|
||||||
}
|
if isSrc {
|
||||||
|
noResolve = true
|
||||||
func HasSrc(params []string) bool {
|
} else {
|
||||||
return slices.Contains(params, src)
|
noResolve = slices.Contains(params, NoResolve)
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
@ -22,23 +22,23 @@ func ParseRule(tp, payload, target string, params []string, subRules map[string]
|
|||||||
case "GEOSITE":
|
case "GEOSITE":
|
||||||
parsed, parseErr = RC.NewGEOSITE(payload, target)
|
parsed, parseErr = RC.NewGEOSITE(payload, target)
|
||||||
case "GEOIP":
|
case "GEOIP":
|
||||||
noResolve := RC.HasNoResolve(params)
|
isSrc, noResolve := RC.ParseParams(params)
|
||||||
parsed, parseErr = RC.NewGEOIP(payload, target, false, noResolve)
|
parsed, parseErr = RC.NewGEOIP(payload, target, isSrc, noResolve)
|
||||||
case "SRC-GEOIP":
|
case "SRC-GEOIP":
|
||||||
parsed, parseErr = RC.NewGEOIP(payload, target, true, true)
|
parsed, parseErr = RC.NewGEOIP(payload, target, true, true)
|
||||||
case "IP-ASN":
|
case "IP-ASN":
|
||||||
noResolve := RC.HasNoResolve(params)
|
isSrc, noResolve := RC.ParseParams(params)
|
||||||
parsed, parseErr = RC.NewIPASN(payload, target, false, noResolve)
|
parsed, parseErr = RC.NewIPASN(payload, target, isSrc, noResolve)
|
||||||
case "SRC-IP-ASN":
|
case "SRC-IP-ASN":
|
||||||
parsed, parseErr = RC.NewIPASN(payload, target, true, true)
|
parsed, parseErr = RC.NewIPASN(payload, target, true, true)
|
||||||
case "IP-CIDR", "IP-CIDR6":
|
case "IP-CIDR", "IP-CIDR6":
|
||||||
noResolve := RC.HasNoResolve(params)
|
isSrc, noResolve := RC.ParseParams(params)
|
||||||
parsed, parseErr = RC.NewIPCIDR(payload, target, RC.WithIPCIDRNoResolve(noResolve))
|
parsed, parseErr = RC.NewIPCIDR(payload, target, RC.WithIPCIDRSourceIP(isSrc), RC.WithIPCIDRNoResolve(noResolve))
|
||||||
case "SRC-IP-CIDR":
|
case "SRC-IP-CIDR":
|
||||||
parsed, parseErr = RC.NewIPCIDR(payload, target, RC.WithIPCIDRSourceIP(true), RC.WithIPCIDRNoResolve(true))
|
parsed, parseErr = RC.NewIPCIDR(payload, target, RC.WithIPCIDRSourceIP(true), RC.WithIPCIDRNoResolve(true))
|
||||||
case "IP-SUFFIX":
|
case "IP-SUFFIX":
|
||||||
noResolve := RC.HasNoResolve(params)
|
isSrc, noResolve := RC.ParseParams(params)
|
||||||
parsed, parseErr = RC.NewIPSuffix(payload, target, false, noResolve)
|
parsed, parseErr = RC.NewIPSuffix(payload, target, isSrc, noResolve)
|
||||||
case "SRC-IP-SUFFIX":
|
case "SRC-IP-SUFFIX":
|
||||||
parsed, parseErr = RC.NewIPSuffix(payload, target, true, true)
|
parsed, parseErr = RC.NewIPSuffix(payload, target, true, true)
|
||||||
case "SRC-PORT":
|
case "SRC-PORT":
|
||||||
@ -76,11 +76,7 @@ func ParseRule(tp, payload, target string, params []string, subRules map[string]
|
|||||||
case "NOT":
|
case "NOT":
|
||||||
parsed, parseErr = logic.NewNOT(payload, target, ParseRule)
|
parsed, parseErr = logic.NewNOT(payload, target, ParseRule)
|
||||||
case "RULE-SET":
|
case "RULE-SET":
|
||||||
noResolve := RC.HasNoResolve(params)
|
isSrc, noResolve := RC.ParseParams(params)
|
||||||
isSrc := RC.HasSrc(params)
|
|
||||||
if isSrc {
|
|
||||||
noResolve = true
|
|
||||||
}
|
|
||||||
parsed, parseErr = RP.NewRuleSet(payload, target, isSrc, noResolve)
|
parsed, parseErr = RP.NewRuleSet(payload, target, isSrc, noResolve)
|
||||||
case "MATCH":
|
case "MATCH":
|
||||||
parsed = RC.NewMatch(target)
|
parsed = RC.NewMatch(target)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user