Skip to content

Commit

Permalink
add support for more types in static hosts. fixes #1556
Browse files Browse the repository at this point in the history
  • Loading branch information
DarienRaymond committed Feb 26, 2019
1 parent 3c9fe03 commit a96babf
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
12 changes: 12 additions & 0 deletions infra/conf/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ func (c *DnsConfig) Build() (*dns.Config, error) {

mappings = append(mappings, mapping)
}
} else if strings.HasPrefix(domain, "regexp:") {
mapping := getHostMapping(addr)
mapping.Type = dns.DomainMatchingType_Regex
mapping.Domain = domain[7:]

mappings = append(mappings, mapping)
} else if strings.HasPrefix(domain, "keyword:") {
mapping := getHostMapping(addr)
mapping.Type = dns.DomainMatchingType_Keyword
mapping.Domain = domain[8:]

mappings = append(mappings, mapping)
} else {
mapping := getHostMapping(addr)
mapping.Type = dns.DomainMatchingType_Full
Expand Down
42 changes: 40 additions & 2 deletions infra/conf/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/golang/protobuf/proto"
"v2ray.com/core/app/dns"
"v2ray.com/core/app/router"
"v2ray.com/core/common"
"v2ray.com/core/common/net"
"v2ray.com/core/common/platform"
Expand All @@ -20,7 +21,26 @@ func init() {
common.Must(err)

common.Must(filesystem.CopyFile(platform.GetAssetLocation("geoip.dat"), filepath.Join(wd, "..", "..", "release", "config", "geoip.dat")))
common.Must(filesystem.CopyFile(platform.GetAssetLocation("geosite.dat"), filepath.Join(wd, "..", "..", "release", "config", "geosite.dat")))

geositeFilePath := platform.GetAssetLocation("geosite.dat")
geositeFile, err := os.OpenFile(geositeFilePath, os.O_CREATE|os.O_WRONLY, 0600)
common.Must(err)
defer geositeFile.Close()

list := &router.GeoSiteList{
Entry: []*router.GeoSite{
{
CountryCode: "TEST",
Domain: []*router.Domain{
{Type: router.Domain_Full, Value: "example.com"},
},
},
},
}

listBytes, err := proto.Marshal(list)
common.Must(err)
common.Must2(geositeFile.Write(listBytes))
}
func TestDnsConfigParsing(t *testing.T) {
geositePath := platform.GetAssetLocation("geosite.dat")
Expand Down Expand Up @@ -48,7 +68,10 @@ func TestDnsConfigParsing(t *testing.T) {
}],
"hosts": {
"v2ray.com": "127.0.0.1",
"domain:example.com": "google.com"
"domain:example.com": "google.com",
"geosite:test": "10.0.0.1",
"keyword:google": "8.8.8.8",
"regexp:.*\\.com": "8.8.4.4"
},
"clientIp": "10.0.0.1"
}`,
Expand Down Expand Up @@ -79,6 +102,21 @@ func TestDnsConfigParsing(t *testing.T) {
Domain: "example.com",
ProxiedDomain: "google.com",
},
{
Type: dns.DomainMatchingType_Full,
Domain: "example.com",
Ip: [][]byte{{10, 0, 0, 1}},
},
{
Type: dns.DomainMatchingType_Keyword,
Domain: "google",
Ip: [][]byte{{8, 8, 8, 8}},
},
{
Type: dns.DomainMatchingType_Regex,
Domain: ".*\\.com",
Ip: [][]byte{{8, 8, 4, 4}},
},
{
Type: dns.DomainMatchingType_Full,
Domain: "v2ray.com",
Expand Down

0 comments on commit a96babf

Please sign in to comment.