diff --git a/config/config.go b/config/config.go index 02a9c105..847c2327 100644 --- a/config/config.go +++ b/config/config.go @@ -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": diff --git a/constant/rule.go b/constant/rule.go index 0acdcc39..db449c7e 100644 --- a/constant/rule.go +++ b/constant/rule.go @@ -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: diff --git a/rules/domian.go b/rules/domian.go new file mode 100644 index 00000000..a836ca67 --- /dev/null +++ b/rules/domian.go @@ -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, + } +}