Bugs and lint warning fixex
Fix domain map cuncurrent access Fix ResolverInfo Domain was not copied bug Fix linter warnings
This commit is contained in:
@@ -111,7 +111,7 @@ The format is: "protocol://ip:port?parameter=value¶meter=value"
|
|||||||
ExpertiseLevel: config.ExpertiseLevelExpert,
|
ExpertiseLevel: config.ExpertiseLevelExpert,
|
||||||
ReleaseLevel: config.ReleaseLevelStable,
|
ReleaseLevel: config.ReleaseLevelStable,
|
||||||
DefaultValue: defaultNameServers,
|
DefaultValue: defaultNameServers,
|
||||||
ValidationRegex: fmt.Sprintf("^(%s|%s|%s|%s|%s|%s)://.*", ServerTypeDoT, ServerTypeDoH, ServerTypeDNS, ServerTypeTCP, HttpsProtocol, TlsProtocol),
|
ValidationRegex: fmt.Sprintf("^(%s|%s|%s|%s|%s|%s)://.*", ServerTypeDoT, ServerTypeDoH, ServerTypeDNS, ServerTypeTCP, HTTPSProtocol, TLSProtocol),
|
||||||
ValidationFunc: validateNameservers,
|
ValidationFunc: validateNameservers,
|
||||||
Annotations: config.Annotations{
|
Annotations: config.Annotations{
|
||||||
config.DisplayHintAnnotation: config.DisplayHintOrdered,
|
config.DisplayHintAnnotation: config.DisplayHintOrdered,
|
||||||
|
|||||||
@@ -12,20 +12,20 @@ import (
|
|||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HttpsResolver is a resolver using just a single tcp connection with pipelining.
|
// HTTPSResolver is a resolver using just a single tcp connection with pipelining.
|
||||||
type HttpsResolver struct {
|
type HTTPSResolver struct {
|
||||||
BasicResolverConn
|
BasicResolverConn
|
||||||
Client *http.Client
|
Client *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
// HttpsQuery holds the query information for a httpsResolverConn.
|
// HTTPSQuery holds the query information for a hTTPSResolverConn.
|
||||||
type HttpsQuery struct {
|
type HTTPSQuery struct {
|
||||||
Query *Query
|
Query *Query
|
||||||
Response chan *dns.Msg
|
Response chan *dns.Msg
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeCacheRecord creates an RRCache record from a reply.
|
// MakeCacheRecord creates an RRCache record from a reply.
|
||||||
func (tq *HttpsQuery) MakeCacheRecord(reply *dns.Msg, resolverInfo *ResolverInfo) *RRCache {
|
func (tq *HTTPSQuery) MakeCacheRecord(reply *dns.Msg, resolverInfo *ResolverInfo) *RRCache {
|
||||||
return &RRCache{
|
return &RRCache{
|
||||||
Domain: tq.Query.FQDN,
|
Domain: tq.Query.FQDN,
|
||||||
Question: tq.Query.QType,
|
Question: tq.Query.QType,
|
||||||
@@ -37,8 +37,8 @@ func (tq *HttpsQuery) MakeCacheRecord(reply *dns.Msg, resolverInfo *ResolverInfo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHTTPSResolver returns a new HttpsResolver.
|
// NewHTTPSResolver returns a new HTTPSResolver.
|
||||||
func NewHTTPSResolver(resolver *Resolver) *HttpsResolver {
|
func NewHTTPSResolver(resolver *Resolver) *HTTPSResolver {
|
||||||
tr := &http.Transport{}
|
tr := &http.Transport{}
|
||||||
|
|
||||||
if resolver.Info.IP != nil {
|
if resolver.Info.IP != nil {
|
||||||
@@ -53,7 +53,7 @@ func NewHTTPSResolver(resolver *Resolver) *HttpsResolver {
|
|||||||
|
|
||||||
client := &http.Client{Transport: tr}
|
client := &http.Client{Transport: tr}
|
||||||
|
|
||||||
newResolver := &HttpsResolver{
|
newResolver := &HTTPSResolver{
|
||||||
BasicResolverConn: BasicResolverConn{
|
BasicResolverConn: BasicResolverConn{
|
||||||
resolver: resolver,
|
resolver: resolver,
|
||||||
},
|
},
|
||||||
@@ -64,15 +64,7 @@ func NewHTTPSResolver(resolver *Resolver) *HttpsResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Query executes the given query against the resolver.
|
// Query executes the given query against the resolver.
|
||||||
func (hr *HttpsResolver) Query(ctx context.Context, q *Query) (*RRCache, error) {
|
func (hr *HTTPSResolver) Query(ctx context.Context, q *Query) (*RRCache, error) {
|
||||||
|
|
||||||
// Do not resolve domain names that are needed to initialize a resolver
|
|
||||||
if hr.resolver.Info.IP == nil {
|
|
||||||
if _, ok := resolverInitDomains[q.FQDN]; ok {
|
|
||||||
return nil, ErrContinue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dnsQuery := new(dns.Msg)
|
dnsQuery := new(dns.Msg)
|
||||||
dnsQuery.SetQuestion(q.FQDN, uint16(q.QType))
|
dnsQuery.SetQuestion(q.FQDN, uint16(q.QType))
|
||||||
|
|
||||||
|
|||||||
@@ -185,13 +185,6 @@ func (tr *TCPResolver) getOrCreateResolverConn(ctx context.Context) (*tcpResolve
|
|||||||
|
|
||||||
// Query executes the given query against the resolver.
|
// Query executes the given query against the resolver.
|
||||||
func (tr *TCPResolver) Query(ctx context.Context, q *Query) (*RRCache, error) {
|
func (tr *TCPResolver) Query(ctx context.Context, q *Query) (*RRCache, error) {
|
||||||
// Do not resolve domain names that are needed to initialize a resolver
|
|
||||||
if tr.resolver.Info.IP == nil && tr.dnsClient.TLSConfig != nil {
|
|
||||||
if _, ok := resolverInitDomains[q.FQDN]; ok {
|
|
||||||
return nil, ErrContinue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get resolver connection.
|
// Get resolver connection.
|
||||||
resolverConn, err := tr.getOrCreateResolverConn(ctx)
|
resolverConn, err := tr.getOrCreateResolverConn(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -30,9 +30,10 @@ const (
|
|||||||
ServerSourceEnv = "env"
|
ServerSourceEnv = "env"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// DNS Resolver alias
|
||||||
const (
|
const (
|
||||||
HttpsProtocol = "https"
|
HTTPSProtocol = "https"
|
||||||
TlsProtocol = "tls"
|
TLSProtocol = "tls"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FailThreshold is amount of errors a resolvers must experience in order to be regarded as failed.
|
// FailThreshold is amount of errors a resolvers must experience in order to be regarded as failed.
|
||||||
@@ -157,7 +158,7 @@ func (info *ResolverInfo) DescriptiveName() string {
|
|||||||
info.Name,
|
info.Name,
|
||||||
info.ID(),
|
info.ID(),
|
||||||
)
|
)
|
||||||
case info.IP == nil:
|
case info.Domain != "":
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
"%s (%s)",
|
"%s (%s)",
|
||||||
info.Domain,
|
info.Domain,
|
||||||
@@ -183,6 +184,7 @@ func (info *ResolverInfo) Copy() *ResolverInfo {
|
|||||||
Type: info.Type,
|
Type: info.Type,
|
||||||
Source: info.Source,
|
Source: info.Source,
|
||||||
IP: info.IP,
|
IP: info.IP,
|
||||||
|
Domain: info.Domain,
|
||||||
IPScope: info.IPScope,
|
IPScope: info.IPScope,
|
||||||
Port: info.Port,
|
Port: info.Port,
|
||||||
id: info.id,
|
id: info.id,
|
||||||
|
|||||||
@@ -103,9 +103,9 @@ func createResolver(resolverURL, source string) (*Resolver, bool, error) {
|
|||||||
|
|
||||||
switch u.Scheme {
|
switch u.Scheme {
|
||||||
case ServerTypeDNS, ServerTypeDoT, ServerTypeDoH, ServerTypeTCP:
|
case ServerTypeDNS, ServerTypeDoT, ServerTypeDoH, ServerTypeTCP:
|
||||||
case HttpsProtocol:
|
case HTTPSProtocol:
|
||||||
u.Scheme = ServerTypeDoH
|
u.Scheme = ServerTypeDoH
|
||||||
case TlsProtocol:
|
case TLSProtocol:
|
||||||
u.Scheme = ServerTypeDoT
|
u.Scheme = ServerTypeDoT
|
||||||
default:
|
default:
|
||||||
return nil, false, fmt.Errorf("DNS resolver scheme %q invalid", u.Scheme)
|
return nil, false, fmt.Errorf("DNS resolver scheme %q invalid", u.Scheme)
|
||||||
@@ -188,8 +188,6 @@ func checkAndSetResolverParamters(u *url.URL, resolver *Resolver) error {
|
|||||||
hostnameIsDomaion := (ip == nil)
|
hostnameIsDomaion := (ip == nil)
|
||||||
if ip == nil && u.Scheme != ServerTypeDoH && u.Scheme != ServerTypeDoT {
|
if ip == nil && u.Scheme != ServerTypeDoH && u.Scheme != ServerTypeDoT {
|
||||||
return fmt.Errorf("resolver IP %q is invalid", u.Hostname())
|
return fmt.Errorf("resolver IP %q is invalid", u.Hostname())
|
||||||
} else {
|
|
||||||
resolver.Info.IP = ip
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add default port for scheme if it is missing.
|
// Add default port for scheme if it is missing.
|
||||||
@@ -198,6 +196,7 @@ func checkAndSetResolverParamters(u *url.URL, resolver *Resolver) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
resolver.Info.Port = port
|
resolver.Info.Port = port
|
||||||
|
resolver.Info.IP = ip
|
||||||
|
|
||||||
query := u.Query()
|
query := u.Query()
|
||||||
|
|
||||||
|
|||||||
@@ -220,6 +220,13 @@ addNextResolver:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the domains from the configured resolvers should not be resolved with the same resolvers
|
||||||
|
if resolver.Info.Source == ServerSourceConfigured && resolver.Info.IP == nil {
|
||||||
|
if _, ok := resolverInitDomains[q.FQDN]; ok {
|
||||||
|
continue addNextResolver
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// add compliant and unique resolvers to selected resolvers
|
// add compliant and unique resolvers to selected resolvers
|
||||||
selected = append(selected, resolver)
|
selected = append(selected, resolver)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user