Improve: add DOMAIN rule

This commit is contained in:
gVisor bot 2018-09-09 15:01:46 +08:00
parent 050c236e78
commit 1c4b253ff0
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)
switch rule[0] {
case "DOMAIN":
rules = append(rules, R.NewDomain(rule[1], rule[2]))
case "DOMAIN-SUFFIX":
rules = append(rules, R.NewDomainSuffix(rule[1], rule[2]))
case "DOMAIN-KEYWORD":

View file

@ -2,7 +2,8 @@ package constant
// Rule Type
const (
DomainSuffix RuleType = iota
Domain RuleType = iota
DomainSuffix
DomainKeyword
GEOIP
IPCIDR
@ -13,6 +14,8 @@ type RuleType int
func (rt RuleType) String() string {
switch rt {
case Domain:
return "Domain"
case DomainSuffix:
return "DomainSuffix"
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,
}
}