Add ServerInfo to resolvers and caches

This commit is contained in:
Daniel 2020-09-22 15:30:21 +02:00
parent 3f3d82bdf1
commit 1b11d1589b
8 changed files with 29 additions and 1 deletions

View file

@ -35,6 +35,7 @@ type NameRecord struct {
Server string Server string
ServerScope int8 ServerScope int8
ServerInfo string
} }
func makeNameRecordKey(domain string, question string) string { func makeNameRecordKey(domain string, question string) string {

View file

@ -23,6 +23,7 @@ var (
Server: ServerSourceEnv, Server: ServerSourceEnv,
ServerType: ServerTypeEnv, ServerType: ServerTypeEnv,
ServerIPScope: netutils.SiteLocal, ServerIPScope: netutils.SiteLocal,
ServerInfo: "Portmaster environment",
Source: ServerSourceEnv, Source: ServerSourceEnv,
Conn: &envResolverConn{}, Conn: &envResolverConn{},
} }
@ -114,6 +115,7 @@ func (er *envResolverConn) makeRRCache(q *Query, answers []dns.RR) *RRCache {
Extra: []dns.RR{internalSpecialUseComment}, // Always add comment about this TLD. Extra: []dns.RR{internalSpecialUseComment}, // Always add comment about this TLD.
Server: envResolver.Server, Server: envResolver.Server,
ServerScope: envResolver.ServerIPScope, ServerScope: envResolver.ServerIPScope,
ServerInfo: envResolver.ServerInfo,
} }
} }

View file

@ -34,6 +34,7 @@ var (
Server: ServerSourceMDNS, Server: ServerSourceMDNS,
ServerType: ServerTypeDNS, ServerType: ServerTypeDNS,
ServerIPScope: netutils.SiteLocal, ServerIPScope: netutils.SiteLocal,
ServerInfo: "mDNS resolver",
Source: ServerSourceMDNS, Source: ServerSourceMDNS,
Conn: &mDNSResolverConn{}, Conn: &mDNSResolverConn{},
} }
@ -203,6 +204,7 @@ func handleMDNSMessages(ctx context.Context, messages chan *dns.Msg) error {
Question: dns.Type(question.Qtype), Question: dns.Type(question.Qtype),
Server: mDNSResolver.Server, Server: mDNSResolver.Server,
ServerScope: mDNSResolver.ServerIPScope, ServerScope: mDNSResolver.ServerIPScope,
ServerInfo: mDNSResolver.ServerInfo,
} }
} }
} }
@ -304,6 +306,7 @@ func handleMDNSMessages(ctx context.Context, messages chan *dns.Msg) error {
Answer: []dns.RR{v}, Answer: []dns.RR{v},
Server: mDNSResolver.Server, Server: mDNSResolver.Server,
ServerScope: mDNSResolver.ServerIPScope, ServerScope: mDNSResolver.ServerIPScope,
ServerInfo: mDNSResolver.ServerInfo,
} }
rrCache.Clean(minMDnsTTL) rrCache.Clean(minMDnsTTL)
err := rrCache.Save() err := rrCache.Save()
@ -416,7 +419,14 @@ func queryMulticastDNS(ctx context.Context, q *Query) (*RRCache, error) {
} }
} }
return nil, ErrNotFound // Respond with NXDomain.
return &RRCache{
Domain: q.FQDN,
Question: q.QType,
Server: mDNSResolver.Server,
ServerScope: mDNSResolver.ServerIPScope,
ServerInfo: mDNSResolver.ServerInfo,
}, nil
} }
func cleanSavedQuestions() { func cleanSavedQuestions() {

View file

@ -86,6 +86,7 @@ func (pr *PlainResolver) Query(ctx context.Context, q *Query) (*RRCache, error)
Extra: reply.Extra, Extra: reply.Extra,
Server: pr.resolver.Server, Server: pr.resolver.Server,
ServerScope: pr.resolver.ServerIPScope, ServerScope: pr.resolver.ServerIPScope,
ServerInfo: pr.resolver.ServerInfo,
} }
// TODO: check if reply.Answer is valid // TODO: check if reply.Answer is valid

View file

@ -51,6 +51,7 @@ func (ifq *InFlightQuery) MakeCacheRecord(reply *dns.Msg) *RRCache {
Extra: reply.Extra, Extra: reply.Extra,
Server: ifq.Resolver.Server, Server: ifq.Resolver.Server,
ServerScope: ifq.Resolver.ServerIPScope, ServerScope: ifq.Resolver.ServerIPScope,
ServerInfo: ifq.Resolver.ServerInfo,
} }
} }

View file

@ -60,6 +60,7 @@ type Resolver struct {
ServerIP net.IP ServerIP net.IP
ServerIPScope int8 ServerIPScope int8
ServerPort uint16 ServerPort uint16
ServerInfo string
// Special Options // Special Options
VerifyDomain string VerifyDomain string

View file

@ -128,6 +128,13 @@ func createResolver(resolverURL, source string) (*Resolver, bool, error) {
UpstreamBlockDetection: blockType, UpstreamBlockDetection: blockType,
} }
u.RawQuery = "" // Remove options from parsed URL
if new.Name != "" {
new.ServerInfo = fmt.Sprintf("%s (%s, from %s)", new.Name, u, source)
} else {
new.ServerInfo = fmt.Sprintf("%s (from %s)", u, source)
}
new.Conn = resolverConnFactory(new) new.Conn = resolverConnFactory(new)
return new, false, nil return new, false, nil
} }

View file

@ -1,6 +1,7 @@
package resolver package resolver
import ( import (
"context"
"fmt" "fmt"
"math/rand" "math/rand"
"net" "net"
@ -8,6 +9,7 @@ import (
"time" "time"
"github.com/safing/portbase/log" "github.com/safing/portbase/log"
"github.com/safing/portmaster/nameserver/nsutil"
"github.com/safing/portmaster/netenv" "github.com/safing/portmaster/netenv"
"github.com/miekg/dns" "github.com/miekg/dns"
@ -130,6 +132,7 @@ func (rrCache *RRCache) ToNameRecord() *NameRecord {
TTL: rrCache.TTL, TTL: rrCache.TTL,
Server: rrCache.Server, Server: rrCache.Server,
ServerScope: rrCache.ServerScope, ServerScope: rrCache.ServerScope,
ServerInfo: rrCache.ServerInfo,
} }
// stringify RR entries // stringify RR entries
@ -176,6 +179,7 @@ func GetRRCache(domain string, question dns.Type) (*RRCache, error) {
rrCache.Server = nameRecord.Server rrCache.Server = nameRecord.Server
rrCache.ServerScope = nameRecord.ServerScope rrCache.ServerScope = nameRecord.ServerScope
rrCache.ServerInfo = nameRecord.ServerInfo
rrCache.servedFromCache = true rrCache.servedFromCache = true
return rrCache, nil return rrCache, nil
} }
@ -239,6 +243,7 @@ func (rrCache *RRCache) ShallowCopy() *RRCache {
Server: rrCache.Server, Server: rrCache.Server,
ServerScope: rrCache.ServerScope, ServerScope: rrCache.ServerScope,
ServerInfo: rrCache.ServerInfo,
updated: rrCache.updated, updated: rrCache.updated,
servedFromCache: rrCache.servedFromCache, servedFromCache: rrCache.servedFromCache,