From 2a8f8f90107069bdd501a402c4b3d77e5a80692b Mon Sep 17 00:00:00 2001 From: mzz <2017@duck.com> Date: Sat, 27 May 2023 23:58:50 +0800 Subject: [PATCH] feat: support geosite attr (#98) --- component/routing/optimizer.go | 15 +++++++++++++++ docs/dns.md | 1 + 2 files changed, 16 insertions(+) diff --git a/component/routing/optimizer.go b/component/routing/optimizer.go index 8ae1a07..c0de779 100644 --- a/component/routing/optimizer.go +++ b/component/routing/optimizer.go @@ -167,11 +167,26 @@ func (o *DatReaderOptimizer) loadGeoSite(filename string, code string) (params [ return nil, err } o.Logger.Debugf("Read geosite \"%v:%v\" from %v", filename, code, filePath) + code, attr, _ := strings.Cut(code, "@") geoSite, err := geodata.UnmarshalGeoSite(o.Logger, filePath, code) if err != nil { return nil, err } for _, item := range geoSite.Domain { + if attr != "" { + // Filter by attr. + attrHit := false + for _, itemAttr := range item.Attribute { + if strings.EqualFold(itemAttr.Key, attr) { + attrHit = true + break + } + } + if !attrHit { + continue + } + } + switch item.Type { case geodata.Domain_Full: // Full. diff --git a/docs/dns.md b/docs/dns.md index a121db6..ac47b35 100644 --- a/docs/dns.md +++ b/docs/dns.md @@ -33,6 +33,7 @@ dns { # DNS request name (omit suffix dot '.'). qname(geosite:category-ads-all) -> reject + qname(geosite:google@cn) -> alidns # Also see: https://github.com/v2ray/domain-list-community#attributes qname(suffix: abc.com, keyword: google) -> googledns qname(full: ok.com, regex: '^yes') -> googledns # DNS request type