mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2025-02-23 03:03:14 +08:00
Improve: add DOMAIN rule
This commit is contained in:
parent
fcb46e7706
commit
4082a2c700
@ -322,6 +322,8 @@ func (c *Config) parseRules(cfg *ini.File) error {
|
|||||||
}
|
}
|
||||||
rule = trimArr(rule)
|
rule = trimArr(rule)
|
||||||
switch rule[0] {
|
switch rule[0] {
|
||||||
|
case "DOMAIN":
|
||||||
|
rules = append(rules, R.NewDomain(rule[1], rule[2]))
|
||||||
case "DOMAIN-SUFFIX":
|
case "DOMAIN-SUFFIX":
|
||||||
rules = append(rules, R.NewDomainSuffix(rule[1], rule[2]))
|
rules = append(rules, R.NewDomainSuffix(rule[1], rule[2]))
|
||||||
case "DOMAIN-KEYWORD":
|
case "DOMAIN-KEYWORD":
|
||||||
|
@ -2,7 +2,8 @@ package constant
|
|||||||
|
|
||||||
// Rule Type
|
// Rule Type
|
||||||
const (
|
const (
|
||||||
DomainSuffix RuleType = iota
|
Domain RuleType = iota
|
||||||
|
DomainSuffix
|
||||||
DomainKeyword
|
DomainKeyword
|
||||||
GEOIP
|
GEOIP
|
||||||
IPCIDR
|
IPCIDR
|
||||||
@ -13,6 +14,8 @@ type RuleType int
|
|||||||
|
|
||||||
func (rt RuleType) String() string {
|
func (rt RuleType) String() string {
|
||||||
switch rt {
|
switch rt {
|
||||||
|
case Domain:
|
||||||
|
return "Domain"
|
||||||
case DomainSuffix:
|
case DomainSuffix:
|
||||||
return "DomainSuffix"
|
return "DomainSuffix"
|
||||||
case DomainKeyword:
|
case DomainKeyword:
|
||||||
|
36
rules/domian.go
Normal file
36
rules/domian.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package rules
|
||||||
|
|
||||||
|
import (
|
||||||
|
C "github.com/Dreamacro/clash/constant"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Domain struct {
|
||||||
|
domain string
|
||||||
|
adapter string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Domain) RuleType() C.RuleType {
|
||||||
|
return C.Domain
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Domain) IsMatch(addr *C.Addr) bool {
|
||||||
|
if addr.AddrType != C.AtypDomainName {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return addr.Host == d.domain
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Domain) Adapter() string {
|
||||||
|
return d.adapter
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Domain) Payload() string {
|
||||||
|
return d.domain
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDomain(domain string, adapter string) *Domain {
|
||||||
|
return &Domain{
|
||||||
|
domain: domain,
|
||||||
|
adapter: adapter,
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user