1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-10 09:50:43 +00:00

fix usability for both IPv4 and v6 in static dns mapping

This commit is contained in:
Darien Raymond 2019-02-21 00:03:31 +01:00
parent b7c3e1da66
commit c27050ad90
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 26 additions and 0 deletions

View File

@ -80,6 +80,11 @@ func NewStaticHosts(hosts []*Config_HostMapping, legacy map[string]*net.IPOrDoma
return nil, newError("neither IP address nor proxied domain specified for domain: ", mapping.Domain).AtWarning()
}
// Special handling for localhost IPv6. This is a dirty workaround as JSON config supports only single IP mapping.
if len(ips) == 1 && ips[0] == net.LocalHostIP {
ips = append(ips, net.LocalHostIPv6)
}
sh.ips[id] = ips
}

View File

@ -7,6 +7,7 @@ import (
. "v2ray.com/core/app/dns"
"v2ray.com/core/common"
"v2ray.com/core/common/net"
)
func TestStaticHosts(t *testing.T) {
@ -25,6 +26,13 @@ func TestStaticHosts(t *testing.T) {
{2, 2, 2, 2},
},
},
{
Type: DomainMatchingType_Subdomain,
Domain: "baidu.com",
Ip: [][]byte{
{127, 0, 0, 1},
},
},
}
hosts, err := NewStaticHosts(pb, nil)
@ -55,4 +63,17 @@ func TestStaticHosts(t *testing.T) {
t.Error(diff)
}
}
{
ips := hosts.LookupIP("baidu.com", IPOption{
IPv4Enable: false,
IPv6Enable: true,
})
if len(ips) != 1 {
t.Error("expect 1 IP, but got ", len(ips))
}
if diff := cmp.Diff([]byte(ips[0].IP()), []byte(net.LocalHostIPv6.IP())); diff != "" {
t.Error(diff)
}
}
}