mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
Add detailed logging throughout DNS proxy operations to improve visibility into query processing, cache operations, and upstream resolver performance. Key improvements: - DNS server setup and listener management logging - Complete query processing pipeline visibility - Cache hit/miss and stale response handling logs - Upstream resolver iteration and failure tracking - Resolver-specific logging (OS, DoH, DoT, DoQ, Legacy) - All log messages capitalized for better readability This provides comprehensive debugging capabilities for DNS proxy operations and helps identify performance bottlenecks and failure points in the resolution chain.
52 lines
1.5 KiB
Go
52 lines
1.5 KiB
Go
package ctrld
|
|
|
|
import (
|
|
"context"
|
|
"crypto/tls"
|
|
"net"
|
|
|
|
"github.com/miekg/dns"
|
|
)
|
|
|
|
type dotResolver struct {
|
|
uc *UpstreamConfig
|
|
}
|
|
|
|
func (r *dotResolver) Resolve(ctx context.Context, msg *dns.Msg) (*dns.Msg, error) {
|
|
logger := LoggerFromCtx(ctx)
|
|
Log(ctx, logger.Debug(), "DoT resolver query started")
|
|
|
|
// The dialer is used to prevent bootstrapping cycle.
|
|
// If r.endpoint is set to dns.controld.dev, we need to resolve
|
|
// dns.controld.dev first. By using a dialer with custom resolver,
|
|
// we ensure that we can always resolve the bootstrap domain
|
|
// regardless of the machine DNS status.
|
|
dialer := newDialer(net.JoinHostPort(controldPublicDns, "53"))
|
|
dnsTyp := uint16(0)
|
|
if msg != nil && len(msg.Question) > 0 {
|
|
dnsTyp = msg.Question[0].Qtype
|
|
}
|
|
tcpNet, _ := r.uc.netForDNSType(ctx, dnsTyp)
|
|
dnsClient := &dns.Client{
|
|
Net: tcpNet,
|
|
Dialer: dialer,
|
|
TLSConfig: &tls.Config{RootCAs: r.uc.certPool},
|
|
}
|
|
endpoint := r.uc.Endpoint
|
|
if r.uc.BootstrapIP != "" {
|
|
dnsClient.TLSConfig.ServerName = r.uc.Domain
|
|
dnsClient.Net = "tcp-tls"
|
|
_, port, _ := net.SplitHostPort(endpoint)
|
|
endpoint = net.JoinHostPort(r.uc.BootstrapIP, port)
|
|
}
|
|
|
|
Log(ctx, logger.Debug(), "Sending DoT request to: %s", endpoint)
|
|
answer, _, err := dnsClient.ExchangeContext(ctx, msg, endpoint)
|
|
if err != nil {
|
|
Log(ctx, logger.Error().Err(err), "DoT request failed")
|
|
} else {
|
|
Log(ctx, logger.Debug(), "DoT resolver query successful")
|
|
}
|
|
return answer, wrapCertificateVerificationError(err)
|
|
}
|