feat: support geosite attr (#98)

This commit is contained in:
mzz 2023-05-27 23:58:50 +08:00 committed by GitHub
parent 9e20a7fff6
commit 2a8f8f9010
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -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.

View File

@ -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