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