diff --git a/app/dns/config.pb.go b/app/dns/config.pb.go index bde69bdd7..d6ce66c6c 100644 --- a/app/dns/config.pb.go +++ b/app/dns/config.pb.go @@ -456,8 +456,7 @@ type Config_HostMapping struct { Domain string `protobuf:"bytes,2,opt,name=domain,proto3" json:"domain,omitempty"` Ip [][]byte `protobuf:"bytes,3,rep,name=ip,proto3" json:"ip,omitempty"` // ProxiedDomain indicates the mapped domain has the same IP address on this - // domain. V2Ray will use this domain for IP queries. This field is only - // effective if ip is empty. + // domain. V2Ray will use this domain for IP queries. ProxiedDomain string `protobuf:"bytes,4,opt,name=proxied_domain,json=proxiedDomain,proto3" json:"proxied_domain,omitempty"` } diff --git a/app/dns/config.proto b/app/dns/config.proto index e0097dae4..d226dd70f 100644 --- a/app/dns/config.proto +++ b/app/dns/config.proto @@ -67,8 +67,7 @@ message Config { repeated bytes ip = 3; // ProxiedDomain indicates the mapped domain has the same IP address on this - // domain. V2Ray will use this domain for IP queries. This field is only - // effective if ip is empty. + // domain. V2Ray will use this domain for IP queries. string proxied_domain = 4; } diff --git a/app/dns/dns.go b/app/dns/dns.go index 4c32ed541..75df565e4 100644 --- a/app/dns/dns.go +++ b/app/dns/dns.go @@ -214,7 +214,7 @@ func (s *DNS) lookupIPInternal(domain string, option dns.IPOption) ([]net.IP, er newError("domain replaced: ", domain, " -> ", addrs[0].Domain()).WriteToLog() domain = addrs[0].Domain() default: // Successfully found ip records in static host - newError("returning ", len(addrs), " IPs for domain ", domain, " -> ", addrs).WriteToLog() + newError("returning ", len(addrs), " IP(s) for domain ", domain, " -> ", addrs).WriteToLog() return toNetIP(addrs) } diff --git a/app/dns/hosts.go b/app/dns/hosts.go index 94746e0ae..fab215d36 100644 --- a/app/dns/hosts.go +++ b/app/dns/hosts.go @@ -49,6 +49,8 @@ func NewStaticHosts(hosts []*Config_HostMapping, legacy map[string]*net.IPOrDoma id := g.Add(matcher) ips := make([]net.Address, 0, len(mapping.Ip)+1) switch { + case len(mapping.ProxiedDomain) > 0: + ips = append(ips, net.DomainAddress(mapping.ProxiedDomain)) case len(mapping.Ip) > 0: for _, ip := range mapping.Ip { addr := net.IPAddress(ip) @@ -57,10 +59,6 @@ func NewStaticHosts(hosts []*Config_HostMapping, legacy map[string]*net.IPOrDoma } ips = append(ips, addr) } - - case len(mapping.ProxiedDomain) > 0: - ips = append(ips, net.DomainAddress(mapping.ProxiedDomain)) - default: return nil, newError("neither IP address nor proxied domain specified for domain: ", mapping.Domain).AtWarning() } @@ -94,6 +92,7 @@ func (h *StaticHosts) lookup(domain string, option dns.IPOption, maxDepth int) [ case len(addrs) == 0: // Not recorded in static hosts, return nil return nil case len(addrs) == 1 && addrs[0].Family().IsDomain(): // Try to unwrap domain + newError("found replaced domain: ", domain, " -> ", addrs[0].Domain(), ". Try to unwrap it").AtDebug().WriteToLog() if maxDepth > 0 { unwrapped := h.lookup(addrs[0].Domain(), option, maxDepth-1) if unwrapped != nil { diff --git a/app/dns/hosts_test.go b/app/dns/hosts_test.go index 6bf2caf22..1a36bbb4d 100644 --- a/app/dns/hosts_test.go +++ b/app/dns/hosts_test.go @@ -20,6 +20,20 @@ func TestStaticHosts(t *testing.T) { {1, 1, 1, 1}, }, }, + { + Type: DomainMatchingType_Full, + Domain: "proxy.v2fly.org", + Ip: [][]byte{ + {1, 2, 3, 4}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, + }, + ProxiedDomain: "another-proxy.v2fly.org", + }, + { + Type: DomainMatchingType_Full, + Domain: "proxy2.v2fly.org", + ProxiedDomain: "proxy.v2fly.org", + }, { Type: DomainMatchingType_Subdomain, Domain: "v2ray.cn", @@ -53,6 +67,32 @@ func TestStaticHosts(t *testing.T) { } } + { + domain := hosts.Lookup("proxy.v2fly.org", dns.IPOption{ + IPv4Enable: true, + IPv6Enable: false, + }) + if len(domain) != 1 { + t.Error("expect 1 domain, but got ", len(domain)) + } + if diff := cmp.Diff(domain[0].Domain(), "another-proxy.v2fly.org"); diff != "" { + t.Error(diff) + } + } + + { + domain := hosts.Lookup("proxy2.v2fly.org", dns.IPOption{ + IPv4Enable: true, + IPv6Enable: false, + }) + if len(domain) != 1 { + t.Error("expect 1 domain, but got ", len(domain)) + } + if diff := cmp.Diff(domain[0].Domain(), "another-proxy.v2fly.org"); diff != "" { + t.Error(diff) + } + } + { ips := hosts.Lookup("www.v2ray.cn", dns.IPOption{ IPv4Enable: true,