mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-07-04 01:07:49 +02:00
Use both os and bootstrap DNS to resolve bootstrap IP
This commit is contained in:
committed by
Cuong Manh Le
parent
e6800fbc82
commit
14bc29751f
@@ -155,7 +155,6 @@ func (uc *UpstreamConfig) Init() {
|
|||||||
// 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() {
|
func (uc *UpstreamConfig) SetupBootstrapIP() {
|
||||||
c := new(dns.Client)
|
|
||||||
bootstrapIP := func(record dns.RR) string {
|
bootstrapIP := func(record dns.RR) string {
|
||||||
switch ar := record.(type) {
|
switch ar := record.(type) {
|
||||||
case *dns.A:
|
case *dns.A:
|
||||||
@@ -166,14 +165,17 @@ func (uc *UpstreamConfig) SetupBootstrapIP() {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
ProxyLog.Debug().Msgf("Resolving %q using bootstrap DNS %q", uc.Domain, bootstrapDNS)
|
resolver := &osResolver{nameservers: nameservers()}
|
||||||
|
resolver.nameservers = append([]string{net.JoinHostPort(bootstrapDNS, "53")}, resolver.nameservers...)
|
||||||
|
ProxyLog.Debug().Msgf("Resolving %q using bootstrap DNS %q", uc.Domain, resolver.nameservers)
|
||||||
do := func(dnsType uint16) {
|
do := func(dnsType uint16) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(uc.Timeout)*time.Millisecond)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(uc.Timeout)*time.Millisecond)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
m.SetQuestion(uc.Domain+".", dnsType)
|
m.SetQuestion(uc.Domain+".", dnsType)
|
||||||
m.RecursionDesired = true
|
m.RecursionDesired = true
|
||||||
r, _, err := c.ExchangeContext(ctx, m, net.JoinHostPort(bootstrapDNS, "53"))
|
|
||||||
|
r, err := resolver.Resolve(ctx, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ProxyLog.Error().Err(err).Str("type", dns.TypeToString[dnsType]).Msgf("could not resolve domain %s for upstream", uc.Domain)
|
ProxyLog.Error().Err(err).Str("type", dns.TypeToString[dnsType]).Msgf("could not resolve domain %s for upstream", uc.Domain)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user