Set tunneling options for (not) using community nodes

This commit is contained in:
Daniel 2022-08-30 13:27:18 +02:00
parent c459b0f4af
commit 770ce61b84
4 changed files with 34 additions and 14 deletions

View file

@ -1,10 +1,9 @@
package firewall package firewall
import ( import (
"github.com/safing/portbase/api"
"github.com/safing/portbase/config" "github.com/safing/portbase/config"
"github.com/safing/portbase/notifications" "github.com/safing/portbase/notifications"
"github.com/safing/portmaster/core" "github.com/safing/spn/captain"
) )
// Configuration Keys. // Configuration Keys.
@ -26,9 +25,6 @@ var (
CfgOptionDNSQueryInterceptionKey = "filter/dnsQueryInterception" CfgOptionDNSQueryInterceptionKey = "filter/dnsQueryInterception"
cfgOptionDNSQueryInterceptionOrder = 97 cfgOptionDNSQueryInterceptionOrder = 97
dnsQueryInterception config.BoolOption dnsQueryInterception config.BoolOption
devMode config.BoolOption
apiListenAddress config.StringOption
) )
func registerConfig() error { func registerConfig() error {
@ -108,8 +104,17 @@ func registerConfig() error {
} }
askTimeout = config.Concurrent.GetAsInt(CfgOptionAskTimeoutKey, 60) askTimeout = config.Concurrent.GetAsInt(CfgOptionAskTimeoutKey, 60)
devMode = config.Concurrent.GetAsBool(core.CfgDevModeKey, false)
apiListenAddress = config.GetAsString(api.CfgDefaultListenAddressKey, "")
return nil return nil
} }
var (
filterEnabled config.BoolOption
tunnelEnabled config.BoolOption
useCommunityNodes config.BoolOption
)
func getConfig() {
filterEnabled = config.Concurrent.GetAsBool(CfgOptionEnableFilterKey, true)
tunnelEnabled = config.Concurrent.GetAsBool(captain.CfgOptionEnableSPNKey, false)
useCommunityNodes = config.Concurrent.GetAsBool(captain.CfgOptionUseCommunityNodesKey, true)
}

View file

@ -7,13 +7,10 @@ import (
"github.com/safing/portbase/modules/subsystems" "github.com/safing/portbase/modules/subsystems"
_ "github.com/safing/portmaster/core" _ "github.com/safing/portmaster/core"
"github.com/safing/portmaster/intel/filterlists" "github.com/safing/portmaster/intel/filterlists"
"github.com/safing/spn/captain"
) )
var ( var (
filterModule *modules.Module filterModule *modules.Module
filterEnabled config.BoolOption
tunnelEnabled config.BoolOption
unbreakFilterListIDs = []string{"UNBREAK"} unbreakFilterListIDs = []string{"UNBREAK"}
resolvedUnbreakFilterListIDs []string resolvedUnbreakFilterListIDs []string
@ -48,12 +45,12 @@ func filterPrep() (err error) {
return err return err
} }
filterEnabled = config.Concurrent.GetAsBool(CfgOptionEnableFilterKey, true)
tunnelEnabled = config.Concurrent.GetAsBool(captain.CfgOptionEnableSPNKey, false)
return nil return nil
} }
func filterStart() error { func filterStart() error {
getConfig()
// TODO: Re-resolve IDs when filterlist index changes. // TODO: Re-resolve IDs when filterlist index changes.
resolvedIDs, err := filterlists.ResolveListIDs(unbreakFilterListIDs) resolvedIDs, err := filterlists.ResolveListIDs(unbreakFilterListIDs)
if err != nil { if err != nil {

View file

@ -13,9 +13,12 @@ import (
"github.com/tevino/abool" "github.com/tevino/abool"
"golang.org/x/sync/singleflight" "golang.org/x/sync/singleflight"
"github.com/safing/portbase/api"
"github.com/safing/portbase/config"
"github.com/safing/portbase/log" "github.com/safing/portbase/log"
"github.com/safing/portbase/modules" "github.com/safing/portbase/modules"
"github.com/safing/portmaster/compat" "github.com/safing/portmaster/compat"
"github.com/safing/portmaster/core"
_ "github.com/safing/portmaster/core/base" _ "github.com/safing/portmaster/core/base"
"github.com/safing/portmaster/firewall/inspection" "github.com/safing/portmaster/firewall/inspection"
"github.com/safing/portmaster/firewall/interception" "github.com/safing/portmaster/firewall/interception"
@ -43,7 +46,14 @@ var (
ownPID = os.Getpid() ownPID = os.Getpid()
) )
// Config variables for interception module.
var (
devMode config.BoolOption
apiListenAddress config.StringOption
)
func init() { func init() {
// TODO: Move interception module to own package (dir).
interceptionModule = modules.Register("interception", interceptionPrep, interceptionStart, interceptionStop, "base", "updates", "network", "notifications") interceptionModule = modules.Register("interception", interceptionPrep, interceptionStart, interceptionStop, "base", "updates", "network", "notifications")
network.SetDefaultFirewallHandler(defaultHandler) network.SetDefaultFirewallHandler(defaultHandler)
@ -54,6 +64,9 @@ func interceptionPrep() error {
} }
func interceptionStart() error { func interceptionStart() error {
devMode = config.Concurrent.GetAsBool(core.CfgDevModeKey, false)
apiListenAddress = config.GetAsString(api.CfgDefaultListenAddressKey, "")
if err := registerMetrics(); err != nil { if err := registerMetrics(); err != nil {
return err return err
} }

View file

@ -114,6 +114,11 @@ func checkTunneling(ctx context.Context, conn *network.Connection, pkt packet.Pa
RoutingProfile: layeredProfile.SPNRoutingAlgorithm(), RoutingProfile: layeredProfile.SPNRoutingAlgorithm(),
} }
// Add required verified owners if community nodes should not be used.
if !useCommunityNodes() {
conn.TunnelOpts.RequireVerifiedOwners = captain.NonCommunityVerifiedOwners
}
// If we have any exit hub policies, we need to raise the routing algorithm at least to single-hop. // If we have any exit hub policies, we need to raise the routing algorithm at least to single-hop.
if conn.TunnelOpts.RoutingProfile == navigator.RoutingProfileHomeID && if conn.TunnelOpts.RoutingProfile == navigator.RoutingProfileHomeID &&
conn.TunnelOpts.HubPoliciesAreSet() { conn.TunnelOpts.HubPoliciesAreSet() {