Improve: add DOMAIN rule
This commit is contained in:
parent
fcb46e7706
commit
4082a2c700
3 changed files with 42 additions and 1 deletions
|
@ -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":
|
||||
|
|
|
@ -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
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 a new issue