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,
|
||||
ReleaseLevel: config.ReleaseLevelStable,
|
||||
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,
|
||||
Annotations: config.Annotations{
|
||||
config.DisplayHintAnnotation: config.DisplayHintOrdered,
|
||||
|
||||
@@ -12,20 +12,20 @@ import (
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
// HttpsResolver is a resolver using just a single tcp connection with pipelining.
|
||||
type HttpsResolver struct {
|
||||
// HTTPSResolver is a resolver using just a single tcp connection with pipelining.
|
||||
type HTTPSResolver struct {
|
||||
BasicResolverConn
|
||||
Client *http.Client
|
||||
}
|
||||
|
||||
// HttpsQuery holds the query information for a httpsResolverConn.
|
||||
type HttpsQuery struct {
|
||||
// HTTPSQuery holds the query information for a hTTPSResolverConn.
|
||||
type HTTPSQuery struct {
|
||||
Query *Query
|
||||
Response chan *dns.Msg
|
||||
}
|
||||
|
||||
// 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{
|
||||
Domain: tq.Query.FQDN,
|
||||
Question: tq.Query.QType,
|
||||
@@ -37,8 +37,8 @@ func (tq *HttpsQuery) MakeCacheRecord(reply *dns.Msg, resolverInfo *ResolverInfo
|
||||
}
|
||||
}
|
||||
|
||||
// NewHTTPSResolver returns a new HttpsResolver.
|
||||
func NewHTTPSResolver(resolver *Resolver) *HttpsResolver {
|
||||
// NewHTTPSResolver returns a new HTTPSResolver.
|
||||
func NewHTTPSResolver(resolver *Resolver) *HTTPSResolver {
|
||||
tr := &http.Transport{}
|
||||
|
||||
if resolver.Info.IP != nil {
|
||||
@@ -53,7 +53,7 @@ func NewHTTPSResolver(resolver *Resolver) *HttpsResolver {
|
||||
|
||||
client := &http.Client{Transport: tr}
|
||||
|
||||
newResolver := &HttpsResolver{
|
||||
newResolver := &HTTPSResolver{
|
||||
BasicResolverConn: BasicResolverConn{
|
||||
resolver: resolver,
|
||||
},
|
||||
@@ -64,15 +64,7 @@ func NewHTTPSResolver(resolver *Resolver) *HttpsResolver {
|
||||
}
|
||||
|
||||
// Query executes the given query against the resolver.
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
func (hr *HTTPSResolver) Query(ctx context.Context, q *Query) (*RRCache, error) {
|
||||
dnsQuery := new(dns.Msg)
|
||||
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.
|
||||
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.
|
||||
resolverConn, err := tr.getOrCreateResolverConn(ctx)
|
||||
if err != nil {
|
||||
|
||||
@@ -30,9 +30,10 @@ const (
|
||||
ServerSourceEnv = "env"
|
||||
)
|
||||
|
||||
// DNS Resolver alias
|
||||
const (
|
||||
HttpsProtocol = "https"
|
||||
TlsProtocol = "tls"
|
||||
HTTPSProtocol = "https"
|
||||
TLSProtocol = "tls"
|
||||
)
|
||||
|
||||
// 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.ID(),
|
||||
)
|
||||
case info.IP == nil:
|
||||
case info.Domain != "":
|
||||
return fmt.Sprintf(
|
||||
"%s (%s)",
|
||||
info.Domain,
|
||||
@@ -183,6 +184,7 @@ func (info *ResolverInfo) Copy() *ResolverInfo {
|
||||
Type: info.Type,
|
||||
Source: info.Source,
|
||||
IP: info.IP,
|
||||
Domain: info.Domain,
|
||||
IPScope: info.IPScope,
|
||||
Port: info.Port,
|
||||
id: info.id,
|
||||
|
||||
@@ -103,9 +103,9 @@ func createResolver(resolverURL, source string) (*Resolver, bool, error) {
|
||||
|
||||
switch u.Scheme {
|
||||
case ServerTypeDNS, ServerTypeDoT, ServerTypeDoH, ServerTypeTCP:
|
||||
case HttpsProtocol:
|
||||
case HTTPSProtocol:
|
||||
u.Scheme = ServerTypeDoH
|
||||
case TlsProtocol:
|
||||
case TLSProtocol:
|
||||
u.Scheme = ServerTypeDoT
|
||||
default:
|
||||
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)
|
||||
if ip == nil && u.Scheme != ServerTypeDoH && u.Scheme != ServerTypeDoT {
|
||||
return fmt.Errorf("resolver IP %q is invalid", u.Hostname())
|
||||
} else {
|
||||
resolver.Info.IP = ip
|
||||
}
|
||||
|
||||
// Add default port for scheme if it is missing.
|
||||
@@ -198,6 +196,7 @@ func checkAndSetResolverParamters(u *url.URL, resolver *Resolver) error {
|
||||
return err
|
||||
}
|
||||
resolver.Info.Port = port
|
||||
resolver.Info.IP = ip
|
||||
|
||||
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
|
||||
selected = append(selected, resolver)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user