mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 19:56:51 +08:00
8595d6c2e9
1.Add Network rule, match network type(TCP/UDP) 2.Add logic rules(NOT,OR,AND) -AND,((DOMAIN,baidu.com),(NETWORK,UDP)),REJECT (cherry picked from commit d7092e2e37f2c48282c878edea1b2ebc2912b09a)
49 lines
802 B
Go
49 lines
802 B
Go
package common
|
|
|
|
import (
|
|
"strings"
|
|
|
|
C "github.com/Dreamacro/clash/constant"
|
|
)
|
|
|
|
type Domain struct {
|
|
domain string
|
|
adapter string
|
|
ruleExtra *C.RuleExtra
|
|
}
|
|
|
|
func (d *Domain) RuleType() C.RuleType {
|
|
return C.Domain
|
|
}
|
|
|
|
func (d *Domain) Match(metadata *C.Metadata) bool {
|
|
if metadata.AddrType != C.AtypDomainName {
|
|
return false
|
|
}
|
|
return metadata.Host == d.domain
|
|
}
|
|
|
|
func (d *Domain) Adapter() string {
|
|
return d.adapter
|
|
}
|
|
|
|
func (d *Domain) Payload() string {
|
|
return d.domain
|
|
}
|
|
|
|
func (d *Domain) ShouldResolveIP() bool {
|
|
return false
|
|
}
|
|
|
|
func (d *Domain) RuleExtra() *C.RuleExtra {
|
|
return d.ruleExtra
|
|
}
|
|
|
|
func NewDomain(domain string, adapter string, ruleExtra *C.RuleExtra) *Domain {
|
|
return &Domain{
|
|
domain: strings.ToLower(domain),
|
|
adapter: adapter,
|
|
ruleExtra: ruleExtra,
|
|
}
|
|
}
|