Skip to content

Commit 3eb1386

Browse files
authored
Feature: android binary runtime default dns set 8.8.8.8:53 (#572)
ref golang/go#8877 ref v2ray/v2ray-core#1909
1 parent a58bfc4 commit 3eb1386

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

infra/conf/dns.go

+4
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ func (c *DNSConfig) Build() (*dns.Config, error) {
158158
config.NameServer = append(config.NameServer, ns)
159159
}
160160

161+
if BootstrapDNS() {
162+
newError("Bootstrap DNS: ", bootstrapDNS).AtWarning().WriteToLog()
163+
}
164+
161165
if c.Hosts != nil && len(c.Hosts) > 0 {
162166
domains := make([]string, 0, len(c.Hosts))
163167
for domain := range c.Hosts {

infra/conf/dns_bootstrap.go

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// +build !android
2+
3+
package conf
4+
5+
const bootstrapDNS = ""
6+
7+
func BootstrapDNS() bool {
8+
return false
9+
}

infra/conf/dns_bootstrap_android.go

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// +build android
2+
3+
package conf
4+
5+
import (
6+
"context"
7+
"net"
8+
)
9+
10+
const bootstrapDNS = "8.8.8.8:53"
11+
12+
func BootstrapDNS() bool {
13+
var dialer net.Dialer
14+
net.DefaultResolver = &net.Resolver{
15+
PreferGo: false,
16+
Dial: func(context context.Context, _, _ string) (net.Conn, error) {
17+
conn, err := dialer.DialContext(context, "udp", bootstrapDNS)
18+
if err != nil {
19+
return nil, err
20+
}
21+
return conn, nil
22+
},
23+
}
24+
return true
25+
}

infra/conf/dns_bootstrap_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package conf
2+
3+
import (
4+
"context"
5+
"net"
6+
"testing"
7+
)
8+
9+
func TestBootstrapDNS(t *testing.T) {
10+
const (
11+
defaultNS = "8.8.8.8:53"
12+
domain = "github.com"
13+
)
14+
var dialer net.Dialer
15+
net.DefaultResolver = &net.Resolver{
16+
PreferGo: true,
17+
Dial: func(context context.Context, network, address string) (net.Conn, error) {
18+
conn, err := dialer.DialContext(context, "udp", defaultNS)
19+
if err != nil {
20+
return nil, err
21+
}
22+
return conn, nil
23+
},
24+
}
25+
if ips, err := net.LookupIP(domain); len(ips) == 0 {
26+
t.Error("set BootstrapDNS failed: ", err)
27+
}
28+
}

0 commit comments

Comments
 (0)