From 162ebffe48e9239778353d2acedeb193b82062cc Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 9 Feb 2024 14:28:06 +0100 Subject: [PATCH] Skip self-check if device is offline --- compat/module.go | 4 ++++ compat/selfcheck.go | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/compat/module.go b/compat/module.go index ea5fcd69..c159d02f 100644 --- a/compat/module.go +++ b/compat/module.go @@ -2,6 +2,7 @@ package compat import ( "context" + "errors" "time" "github.com/tevino/abool" @@ -92,6 +93,9 @@ func selfcheckTaskFunc(ctx context.Context, task *modules.Task) error { case err == nil: // Successful. tracer.Debugf("compat: self-check successful") + case errors.Is(err, errSelfcheckSkipped): + // Skipped. + tracer.Debugf("compat: %s", err) case issue == nil: // Internal error. tracer.Warningf("compat: %s", err) diff --git a/compat/selfcheck.go b/compat/selfcheck.go index fd4a22bc..e26c1ed5 100644 --- a/compat/selfcheck.go +++ b/compat/selfcheck.go @@ -3,6 +3,7 @@ package compat import ( "context" "encoding/hex" + "errors" "fmt" "net" "strings" @@ -11,6 +12,7 @@ import ( "github.com/safing/portbase/log" "github.com/safing/portbase/rng" + "github.com/safing/portmaster/netenv" "github.com/safing/portmaster/network/packet" "github.com/safing/portmaster/resolver" ) @@ -36,12 +38,19 @@ var ( dnsCheckWaitDuration = 45 * time.Second dnsCheckAnswerLock sync.Mutex dnsCheckAnswer net.IP + + errSelfcheckSkipped = errors.New("self-check skipped") ) func selfcheck(ctx context.Context) (issue *systemIssue, err error) { selfcheckLock.Lock() defer selfcheckLock.Unlock() + // Step 0: Check if self-check makes sense. + if !netenv.Online() { + return nil, fmt.Errorf("%w: device is offline or in limited network", errSelfcheckSkipped) + } + // Step 1: Check if the system integration sees a packet. // Empty recv channel.