Add workaround for resolver/compat integration

This commit is contained in:
Daniel
2021-11-29 16:13:08 +01:00
parent 3bcb6f377c
commit dc31400caa
6 changed files with 32 additions and 15 deletions

View File

@@ -7,6 +7,7 @@ import (
"github.com/safing/portbase/log" "github.com/safing/portbase/log"
"github.com/safing/portbase/modules" "github.com/safing/portbase/modules"
"github.com/safing/portmaster/netenv" "github.com/safing/portmaster/netenv"
"github.com/safing/portmaster/resolver"
"github.com/tevino/abool" "github.com/tevino/abool"
) )
@@ -28,6 +29,12 @@ var (
func init() { func init() {
module = modules.Register("compat", prep, start, stop, "base", "network", "interception", "netenv", "notifications") module = modules.Register("compat", prep, start, stop, "base", "network", "interception", "netenv", "notifications")
// Workaround resolver integration.
// See resolver/compat.go for details.
resolver.CompatDNSCheckInternalDomainScope = DNSCheckInternalDomainScope
resolver.CompatSelfCheckIsFailing = SelfCheckIsFailing
resolver.CompatSubmitDNSCheckDomain = SubmitDNSCheckDomain
} }
func prep() error { func prep() error {

View File

@@ -12,6 +12,7 @@ import (
"github.com/safing/portbase/log" "github.com/safing/portbase/log"
"github.com/safing/portbase/rng" "github.com/safing/portbase/rng"
"github.com/safing/portmaster/network/packet" "github.com/safing/portmaster/network/packet"
"github.com/safing/portmaster/resolver"
) )
var ( var (
@@ -25,7 +26,7 @@ var (
systemIntegrationCheckPackets = make(chan packet.Packet, 1) systemIntegrationCheckPackets = make(chan packet.Packet, 1)
systemIntegrationCheckWaitDuration = 3 * time.Second systemIntegrationCheckWaitDuration = 3 * time.Second
DNSCheckInternalDomainScope string DNSCheckInternalDomainScope = ".self-check." + resolver.InternalSpecialUseDomain
dnsCheckReceivedDomain = make(chan string, 1) dnsCheckReceivedDomain = make(chan string, 1)
dnsCheckWaitDuration = 3 * time.Second dnsCheckWaitDuration = 3 * time.Second
dnsCheckAnswerLock sync.Mutex dnsCheckAnswerLock sync.Mutex

12
resolver/compat.go Normal file
View File

@@ -0,0 +1,12 @@
package resolver
import "net"
// This is a workaround for enabling the resolver to work with the compat
// module without importing it. Long-term, the network module should not import
// the resolver package, as this breaks the SPN hub.
var (
CompatDNSCheckInternalDomainScope string
CompatSelfCheckIsFailing func() bool
CompatSubmitDNSCheckDomain func(subdomain string) (respondWith net.IP)
)

View File

@@ -11,7 +11,6 @@ import (
"github.com/safing/portbase/database" "github.com/safing/portbase/database"
"github.com/safing/portbase/log" "github.com/safing/portbase/log"
"github.com/safing/portmaster/compat"
"github.com/safing/portmaster/netenv" "github.com/safing/portmaster/netenv"
) )
@@ -407,7 +406,7 @@ resolveLoop:
err = fmt.Errorf("all %d query-compliant resolvers failed, last error: %s", len(resolvers), err) err = fmt.Errorf("all %d query-compliant resolvers failed, last error: %s", len(resolvers), err)
if primarySource == ServerSourceConfigured && if primarySource == ServerSourceConfigured &&
netenv.Online() && compat.SelfCheckIsFailing() { netenv.Online() && CompatSelfCheckIsFailing() {
notifyAboutFailingResolvers(err) notifyAboutFailingResolvers(err)
} else { } else {
resetFailingResolversNotification() resetFailingResolversNotification()

View File

@@ -8,16 +8,15 @@ import (
"github.com/miekg/dns" "github.com/miekg/dns"
"github.com/safing/portbase/log" "github.com/safing/portbase/log"
"github.com/safing/portmaster/compat"
"github.com/safing/portmaster/netenv" "github.com/safing/portmaster/netenv"
"github.com/safing/portmaster/network/netutils" "github.com/safing/portmaster/network/netutils"
) )
const ( const (
internalSpecialUseDomain = "portmaster.home.arpa." InternalSpecialUseDomain = "portmaster.home.arpa."
routerDomain = "router.local." + internalSpecialUseDomain routerDomain = "router.local." + InternalSpecialUseDomain
captivePortalDomain = "captiveportal.local." + internalSpecialUseDomain captivePortalDomain = "captiveportal.local." + InternalSpecialUseDomain
) )
var ( var (
@@ -38,11 +37,10 @@ var (
func prepEnvResolver() (err error) { func prepEnvResolver() (err error) {
netenv.SpecialCaptivePortalDomain = captivePortalDomain netenv.SpecialCaptivePortalDomain = captivePortalDomain
compat.DNSCheckInternalDomainScope = ".self-check." + internalSpecialUseDomain
internalSpecialUseSOA, err = dns.NewRR(fmt.Sprintf( internalSpecialUseSOA, err = dns.NewRR(fmt.Sprintf(
"%s 17 IN SOA localhost. none.localhost. 0 0 0 0 0", "%s 17 IN SOA localhost. none.localhost. 0 0 0 0 0",
internalSpecialUseDomain, InternalSpecialUseDomain,
)) ))
if err != nil { if err != nil {
return err return err
@@ -50,7 +48,7 @@ func prepEnvResolver() (err error) {
internalSpecialUseComment, err = dns.NewRR(fmt.Sprintf( internalSpecialUseComment, err = dns.NewRR(fmt.Sprintf(
`%s 17 IN TXT "This is a special use TLD of the Portmaster."`, `%s 17 IN TXT "This is a special use TLD of the Portmaster."`,
internalSpecialUseDomain, InternalSpecialUseDomain,
)) ))
return err return err
} }
@@ -94,9 +92,9 @@ func (er *envResolverConn) Query(ctx context.Context, q *Query) (*RRCache, error
// Check for suffix matches. // Check for suffix matches.
switch { switch {
case strings.HasSuffix(q.FQDN, compat.DNSCheckInternalDomainScope): case strings.HasSuffix(q.FQDN, CompatDNSCheckInternalDomainScope):
subdomain := strings.TrimSuffix(q.FQDN, compat.DNSCheckInternalDomainScope) subdomain := strings.TrimSuffix(q.FQDN, CompatDNSCheckInternalDomainScope)
respondWith := compat.SubmitDNSCheckDomain(subdomain) respondWith := CompatSubmitDNSCheckDomain(subdomain)
// We'll get an A record. Only respond if it's an A question. // We'll get an A record. Only respond if it's an A question.
if respondWith != nil && uint16(q.QType) == dns.TypeA { if respondWith != nil && uint16(q.QType) == dns.TypeA {
@@ -110,7 +108,7 @@ func (er *envResolverConn) Query(ctx context.Context, q *Query) (*RRCache, error
} }
case dns.TypeSOA: case dns.TypeSOA:
// Direct query for the SOA record. // Direct query for the SOA record.
if q.FQDN == internalSpecialUseDomain { if q.FQDN == InternalSpecialUseDomain {
return er.makeRRCache(q, []dns.RR{internalSpecialUseSOA}), nil return er.makeRRCache(q, []dns.RR{internalSpecialUseSOA}), nil
} }
} }

View File

@@ -26,7 +26,7 @@ var (
// Internal Special-Use Domain // Internal Special-Use Domain
// Used by Portmaster for special addressing. // Used by Portmaster for special addressing.
internalSpecialUseDomains = []string{ internalSpecialUseDomains = []string{
"." + internalSpecialUseDomain, "." + InternalSpecialUseDomain,
} }
// Multicast DNS // Multicast DNS