Skip self-check if device is offline

This commit is contained in:
Daniel 2024-02-09 14:28:06 +01:00
parent e9940d77a0
commit 162ebffe48
2 changed files with 13 additions and 0 deletions

View file

@ -2,6 +2,7 @@ package compat
import ( import (
"context" "context"
"errors"
"time" "time"
"github.com/tevino/abool" "github.com/tevino/abool"
@ -92,6 +93,9 @@ func selfcheckTaskFunc(ctx context.Context, task *modules.Task) error {
case err == nil: case err == nil:
// Successful. // Successful.
tracer.Debugf("compat: self-check successful") tracer.Debugf("compat: self-check successful")
case errors.Is(err, errSelfcheckSkipped):
// Skipped.
tracer.Debugf("compat: %s", err)
case issue == nil: case issue == nil:
// Internal error. // Internal error.
tracer.Warningf("compat: %s", err) tracer.Warningf("compat: %s", err)

View file

@ -3,6 +3,7 @@ package compat
import ( import (
"context" "context"
"encoding/hex" "encoding/hex"
"errors"
"fmt" "fmt"
"net" "net"
"strings" "strings"
@ -11,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/netenv"
"github.com/safing/portmaster/network/packet" "github.com/safing/portmaster/network/packet"
"github.com/safing/portmaster/resolver" "github.com/safing/portmaster/resolver"
) )
@ -36,12 +38,19 @@ var (
dnsCheckWaitDuration = 45 * time.Second dnsCheckWaitDuration = 45 * time.Second
dnsCheckAnswerLock sync.Mutex dnsCheckAnswerLock sync.Mutex
dnsCheckAnswer net.IP dnsCheckAnswer net.IP
errSelfcheckSkipped = errors.New("self-check skipped")
) )
func selfcheck(ctx context.Context) (issue *systemIssue, err error) { func selfcheck(ctx context.Context) (issue *systemIssue, err error) {
selfcheckLock.Lock() selfcheckLock.Lock()
defer selfcheckLock.Unlock() 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. // Step 1: Check if the system integration sees a packet.
// Empty recv channel. // Empty recv channel.