mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-05-29 15:36:00 +03:00
Add AdGuard DNS filter support
This commit is contained in:
@@ -142,6 +142,15 @@ func NewDefaultHeadlessRule(router adapter.Router, options option.DefaultHeadles
|
||||
rule.allItems = append(rule.allItems, item)
|
||||
}
|
||||
}
|
||||
if len(options.AdGuardDomain) > 0 {
|
||||
item := NewAdGuardDomainItem(options.AdGuardDomain)
|
||||
rule.destinationAddressItems = append(rule.destinationAddressItems, item)
|
||||
rule.allItems = append(rule.allItems, item)
|
||||
} else if options.AdGuardDomainMatcher != nil {
|
||||
item := NewRawAdGuardDomainItem(options.AdGuardDomainMatcher)
|
||||
rule.destinationAddressItems = append(rule.destinationAddressItems, item)
|
||||
rule.allItems = append(rule.allItems, item)
|
||||
}
|
||||
return rule, nil
|
||||
}
|
||||
|
||||
|
||||
43
route/rule_item_adguard.go
Normal file
43
route/rule_item_adguard.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package route
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
"github.com/sagernet/sing/common/domain"
|
||||
)
|
||||
|
||||
var _ RuleItem = (*AdGuardDomainItem)(nil)
|
||||
|
||||
type AdGuardDomainItem struct {
|
||||
matcher *domain.AdGuardMatcher
|
||||
}
|
||||
|
||||
func NewAdGuardDomainItem(ruleLines []string) *AdGuardDomainItem {
|
||||
return &AdGuardDomainItem{
|
||||
domain.NewAdGuardMatcher(ruleLines),
|
||||
}
|
||||
}
|
||||
|
||||
func NewRawAdGuardDomainItem(matcher *domain.AdGuardMatcher) *AdGuardDomainItem {
|
||||
return &AdGuardDomainItem{
|
||||
matcher,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *AdGuardDomainItem) Match(metadata *adapter.InboundContext) bool {
|
||||
var domainHost string
|
||||
if metadata.Domain != "" {
|
||||
domainHost = metadata.Domain
|
||||
} else {
|
||||
domainHost = metadata.Destination.Fqdn
|
||||
}
|
||||
if domainHost == "" {
|
||||
return false
|
||||
}
|
||||
return r.matcher.Match(strings.ToLower(domainHost))
|
||||
}
|
||||
|
||||
func (r *AdGuardDomainItem) String() string {
|
||||
return "!adguard_domain_rules=<binary>"
|
||||
}
|
||||
Reference in New Issue
Block a user