@@ -2,48 +2,24 @@ package dns
22
33import (
44 "github.com/xtls/xray-core/common/errors"
5+ "github.com/xtls/xray-core/common/geodata"
56 "github.com/xtls/xray-core/common/net"
6- "github.com/xtls/xray-core/common/strmatcher"
77 "github.com/xtls/xray-core/common/uuid"
88)
99
10- var typeMap = map [DomainMatchingType ]strmatcher.Type {
11- DomainMatchingType_Full : strmatcher .Full ,
12- DomainMatchingType_Subdomain : strmatcher .Domain ,
13- DomainMatchingType_Keyword : strmatcher .Substr ,
14- DomainMatchingType_Regex : strmatcher .Regex ,
15- }
16-
1710// References:
1811// https://www.iana.org/assignments/special-use-domain-names/special-use-domain-names.xhtml
1912// https://unix.stackexchange.com/questions/92441/whats-the-difference-between-local-home-and-lan
20- var localTLDsAndDotlessDomains = []* NameServer_PriorityDomain {
21- {Type : DomainMatchingType_Regex , Domain : "^[^.]+$" }, // This will only match domains without any dot
22- {Type : DomainMatchingType_Subdomain , Domain : "local" },
23- {Type : DomainMatchingType_Subdomain , Domain : "localdomain" },
24- {Type : DomainMatchingType_Subdomain , Domain : "localhost" },
25- {Type : DomainMatchingType_Subdomain , Domain : "lan" },
26- {Type : DomainMatchingType_Subdomain , Domain : "home.arpa" },
27- {Type : DomainMatchingType_Subdomain , Domain : "example" },
28- {Type : DomainMatchingType_Subdomain , Domain : "invalid" },
29- {Type : DomainMatchingType_Subdomain , Domain : "test" },
30- }
31-
32- var localTLDsAndDotlessDomainsRule = & NameServer_OriginalRule {
33- Rule : "geosite:private" ,
34- Size : uint32 (len (localTLDsAndDotlessDomains )),
35- }
36-
37- func toStrMatcher (t DomainMatchingType , domain string ) (strmatcher.Matcher , error ) {
38- strMType , f := typeMap [t ]
39- if ! f {
40- return nil , errors .New ("unknown mapping type" , t ).AtWarning ()
41- }
42- matcher , err := strMType .New (domain )
43- if err != nil {
44- return nil , errors .New ("failed to create str matcher" ).Base (err )
45- }
46- return matcher , nil
13+ var localTLDsAndDotlessDomainsRules = []* geodata.DomainRule {
14+ {Value : & geodata.DomainRule_Custom {Custom : & geodata.Domain {Type : geodata .Domain_Regex , Value : "^[^.]+$" }}}, // This will only match domains without any dot
15+ {Value : & geodata.DomainRule_Custom {Custom : & geodata.Domain {Type : geodata .Domain_Domain , Value : "local" }}},
16+ {Value : & geodata.DomainRule_Custom {Custom : & geodata.Domain {Type : geodata .Domain_Domain , Value : "localdomain" }}},
17+ {Value : & geodata.DomainRule_Custom {Custom : & geodata.Domain {Type : geodata .Domain_Domain , Value : "localhost" }}},
18+ {Value : & geodata.DomainRule_Custom {Custom : & geodata.Domain {Type : geodata .Domain_Domain , Value : "lan" }}},
19+ {Value : & geodata.DomainRule_Custom {Custom : & geodata.Domain {Type : geodata .Domain_Domain , Value : "home.arpa" }}},
20+ {Value : & geodata.DomainRule_Custom {Custom : & geodata.Domain {Type : geodata .Domain_Domain , Value : "example" }}},
21+ {Value : & geodata.DomainRule_Custom {Custom : & geodata.Domain {Type : geodata .Domain_Domain , Value : "invalid" }}},
22+ {Value : & geodata.DomainRule_Custom {Custom : & geodata.Domain {Type : geodata .Domain_Domain , Value : "test" }}},
4723}
4824
4925func toNetIP (addrs []net.Address ) ([]net.IP , error ) {
0 commit comments