mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-08-23 01:27:13 +02:00
Do not send legacy DNS queries to bootstrap DNS
This commit is contained in:
@@ -402,12 +402,6 @@ func (uc *UpstreamConfig) SetCertPool(cp *x509.CertPool) {
|
|||||||
uc.certPool = cp
|
uc.certPool = cp
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetupBootstrapIP manually find all available IPs of the upstream.
|
|
||||||
// The first usable IP will be used as bootstrap IP of the upstream.
|
|
||||||
func (uc *UpstreamConfig) SetupBootstrapIP() {
|
|
||||||
uc.setupBootstrapIP(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UID returns the unique identifier of the upstream.
|
// UID returns the unique identifier of the upstream.
|
||||||
func (uc *UpstreamConfig) UID() string {
|
func (uc *UpstreamConfig) UID() string {
|
||||||
return uc.uid
|
return uc.uid
|
||||||
@@ -415,11 +409,11 @@ func (uc *UpstreamConfig) UID() string {
|
|||||||
|
|
||||||
// SetupBootstrapIP manually find all available IPs of the upstream.
|
// SetupBootstrapIP manually find all available IPs of the upstream.
|
||||||
// The first usable IP will be used as bootstrap IP of the upstream.
|
// The first usable IP will be used as bootstrap IP of the upstream.
|
||||||
func (uc *UpstreamConfig) setupBootstrapIP(withBootstrapDNS bool) {
|
func (uc *UpstreamConfig) SetupBootstrapIP() {
|
||||||
b := backoff.NewBackoff("setupBootstrapIP", func(format string, args ...any) {}, 10*time.Second)
|
b := backoff.NewBackoff("setupBootstrapIP", func(format string, args ...any) {}, 10*time.Second)
|
||||||
isControlD := uc.IsControlD()
|
isControlD := uc.IsControlD()
|
||||||
for {
|
for {
|
||||||
uc.bootstrapIPs = lookupIP(uc.Domain, uc.Timeout, withBootstrapDNS)
|
uc.bootstrapIPs = lookupIP(uc.Domain, uc.Timeout)
|
||||||
// For ControlD upstream, the bootstrap IPs could not be RFC 1918 addresses,
|
// For ControlD upstream, the bootstrap IPs could not be RFC 1918 addresses,
|
||||||
// filtering them out here to prevent weird behavior.
|
// filtering them out here to prevent weird behavior.
|
||||||
if isControlD {
|
if isControlD {
|
||||||
|
|||||||
@@ -2,16 +2,12 @@ package ctrld
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/rs/zerolog"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUpstreamConfig_SetupBootstrapIP(t *testing.T) {
|
func TestUpstreamConfig_SetupBootstrapIP(t *testing.T) {
|
||||||
l := zerolog.New(os.Stdout)
|
|
||||||
ProxyLogger.Store(&l)
|
|
||||||
uc := &UpstreamConfig{
|
uc := &UpstreamConfig{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Type: ResolverTypeDOH,
|
Type: ResolverTypeDOH,
|
||||||
@@ -19,7 +15,7 @@ func TestUpstreamConfig_SetupBootstrapIP(t *testing.T) {
|
|||||||
Timeout: 5000,
|
Timeout: 5000,
|
||||||
}
|
}
|
||||||
uc.Init()
|
uc.Init()
|
||||||
uc.setupBootstrapIP(false)
|
uc.SetupBootstrapIP()
|
||||||
if len(uc.bootstrapIPs) == 0 {
|
if len(uc.bootstrapIPs) == 0 {
|
||||||
t.Log(defaultNameservers())
|
t.Log(defaultNameservers())
|
||||||
t.Fatal("could not bootstrap ip without bootstrap DNS")
|
t.Fatal("could not bootstrap ip without bootstrap DNS")
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ func (r *dotResolver) Resolve(ctx context.Context, msg *dns.Msg) (*dns.Msg, erro
|
|||||||
// dns.controld.dev first. By using a dialer with custom resolver,
|
// dns.controld.dev first. By using a dialer with custom resolver,
|
||||||
// we ensure that we can always resolve the bootstrap domain
|
// we ensure that we can always resolve the bootstrap domain
|
||||||
// regardless of the machine DNS status.
|
// regardless of the machine DNS status.
|
||||||
dialer := newDialer(net.JoinHostPort(controldBootstrapDns, "53"))
|
dialer := newDialer(net.JoinHostPort(controldPublicDns, "53"))
|
||||||
dnsTyp := uint16(0)
|
dnsTyp := uint16(0)
|
||||||
if msg != nil && len(msg.Question) > 0 {
|
if msg != nil && len(msg.Question) > 0 {
|
||||||
dnsTyp = msg.Question[0].Qtype
|
dnsTyp = msg.Question[0].Qtype
|
||||||
|
|||||||
+4
-10
@@ -41,10 +41,7 @@ const (
|
|||||||
ResolverTypeSDNS = "sdns"
|
ResolverTypeSDNS = "sdns"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const controldPublicDns = "76.76.2.0"
|
||||||
controldBootstrapDns = "76.76.2.22"
|
|
||||||
controldPublicDns = "76.76.2.0"
|
|
||||||
)
|
|
||||||
|
|
||||||
var controldPublicDnsWithPort = net.JoinHostPort(controldPublicDns, "53")
|
var controldPublicDnsWithPort = net.JoinHostPort(controldPublicDns, "53")
|
||||||
|
|
||||||
@@ -440,7 +437,7 @@ type legacyResolver struct {
|
|||||||
|
|
||||||
func (r *legacyResolver) Resolve(ctx context.Context, msg *dns.Msg) (*dns.Msg, error) {
|
func (r *legacyResolver) Resolve(ctx context.Context, msg *dns.Msg) (*dns.Msg, error) {
|
||||||
// See comment in (*dotResolver).resolve method.
|
// See comment in (*dotResolver).resolve method.
|
||||||
dialer := newDialer(net.JoinHostPort(controldBootstrapDns, "53"))
|
dialer := newDialer(net.JoinHostPort(controldPublicDns, "53"))
|
||||||
dnsTyp := uint16(0)
|
dnsTyp := uint16(0)
|
||||||
if msg != nil && len(msg.Question) > 0 {
|
if msg != nil && len(msg.Question) > 0 {
|
||||||
dnsTyp = msg.Question[0].Qtype
|
dnsTyp = msg.Question[0].Qtype
|
||||||
@@ -472,10 +469,10 @@ func (d dummyResolver) Resolve(ctx context.Context, msg *dns.Msg) (*dns.Msg, err
|
|||||||
// LookupIP looks up host using OS resolver.
|
// LookupIP looks up host using OS resolver.
|
||||||
// It returns a slice of that host's IPv4 and IPv6 addresses.
|
// It returns a slice of that host's IPv4 and IPv6 addresses.
|
||||||
func LookupIP(domain string) []string {
|
func LookupIP(domain string) []string {
|
||||||
return lookupIP(domain, -1, true)
|
return lookupIP(domain, -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func lookupIP(domain string, timeout int, withBootstrapDNS bool) (ips []string) {
|
func lookupIP(domain string, timeout int) (ips []string) {
|
||||||
resolverMutex.Lock()
|
resolverMutex.Lock()
|
||||||
if or == nil {
|
if or == nil {
|
||||||
ProxyLogger.Load().Debug().Msgf("Initialize OS resolver in lookupIP")
|
ProxyLogger.Load().Debug().Msgf("Initialize OS resolver in lookupIP")
|
||||||
@@ -485,9 +482,6 @@ func lookupIP(domain string, timeout int, withBootstrapDNS bool) (ips []string)
|
|||||||
|
|
||||||
nss := *or.lanServers.Load()
|
nss := *or.lanServers.Load()
|
||||||
nss = append(nss, *or.publicServers.Load()...)
|
nss = append(nss, *or.publicServers.Load()...)
|
||||||
if withBootstrapDNS {
|
|
||||||
nss = append([]string{net.JoinHostPort(controldBootstrapDns, "53")}, nss...)
|
|
||||||
}
|
|
||||||
resolver := newResolverWithNameserver(nss)
|
resolver := newResolverWithNameserver(nss)
|
||||||
ProxyLogger.Load().Debug().Msgf("resolving %q using bootstrap DNS %q", domain, nss)
|
ProxyLogger.Load().Debug().Msgf("resolving %q using bootstrap DNS %q", domain, nss)
|
||||||
timeoutMs := 2000
|
timeoutMs := 2000
|
||||||
|
|||||||
Reference in New Issue
Block a user