Improve: add DOMAIN rule

This commit is contained in:
Dreamacro 2018-09-09 15:01:46 +08:00
parent fcb46e7706
commit 4082a2c700
3 changed files with 42 additions and 1 deletions

View File

@ -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":

View File

@ -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
View 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,
}
}