mirror of https://github.com/v2ray/v2ray-core
fix usability for both IPv4 and v6 in static dns mapping
parent
b7c3e1da66
commit
c27050ad90
|
@ -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()
|
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
|
sh.ips[id] = ips
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
. "v2ray.com/core/app/dns"
|
. "v2ray.com/core/app/dns"
|
||||||
"v2ray.com/core/common"
|
"v2ray.com/core/common"
|
||||||
|
"v2ray.com/core/common/net"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestStaticHosts(t *testing.T) {
|
func TestStaticHosts(t *testing.T) {
|
||||||
|
@ -25,6 +26,13 @@ func TestStaticHosts(t *testing.T) {
|
||||||
{2, 2, 2, 2},
|
{2, 2, 2, 2},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Type: DomainMatchingType_Subdomain,
|
||||||
|
Domain: "baidu.com",
|
||||||
|
Ip: [][]byte{
|
||||||
|
{127, 0, 0, 1},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
hosts, err := NewStaticHosts(pb, nil)
|
hosts, err := NewStaticHosts(pb, nil)
|
||||||
|
@ -55,4 +63,17 @@ func TestStaticHosts(t *testing.T) {
|
||||||
t.Error(diff)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue