From 59392e41c636651667c0dd6a319971545969a267 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 27 Sep 2022 14:52:09 +0200 Subject: [PATCH] Move all filter/interception config to interception module --- firewall/config.go | 11 +++++++++++ firewall/filter.go | 17 +---------------- firewall/interception.go | 16 +++++----------- 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/firewall/config.go b/firewall/config.go index b2f23486..5f6f92e9 100644 --- a/firewall/config.go +++ b/firewall/config.go @@ -1,8 +1,10 @@ package firewall import ( + "github.com/safing/portbase/api" "github.com/safing/portbase/config" "github.com/safing/portbase/notifications" + "github.com/safing/portmaster/core" "github.com/safing/spn/captain" ) @@ -107,13 +109,22 @@ func registerConfig() error { return nil } +// Config variables for interception and filter module. +// Everything is registered by the interception module, as the filter module +// can be disabled. var ( + devMode config.BoolOption + apiListenAddress config.StringOption + filterEnabled config.BoolOption tunnelEnabled config.BoolOption useCommunityNodes config.BoolOption ) func getConfig() { + devMode = config.Concurrent.GetAsBool(core.CfgDevModeKey, false) + apiListenAddress = config.GetAsString(api.CfgDefaultListenAddressKey, "") + filterEnabled = config.Concurrent.GetAsBool(CfgOptionEnableFilterKey, true) tunnelEnabled = config.Concurrent.GetAsBool(captain.CfgOptionEnableSPNKey, false) useCommunityNodes = config.Concurrent.GetAsBool(captain.CfgOptionUseCommunityNodesKey, true) diff --git a/firewall/filter.go b/firewall/filter.go index e5c4aa1e..d1b75f2e 100644 --- a/firewall/filter.go +++ b/firewall/filter.go @@ -10,7 +10,7 @@ import ( var filterModule *modules.Module func init() { - filterModule = modules.Register("filter", filterPrep, filterStart, nil, "core", "intel") + filterModule = modules.Register("filter", nil, nil, nil, "core", "interception", "intel") subsystems.Register( "filter", "Privacy Filter", @@ -31,18 +31,3 @@ func init() { }, ) } - -func filterPrep() (err error) { - err = registerConfig() - if err != nil { - return err - } - - return nil -} - -func filterStart() error { - getConfig() - - return nil -} diff --git a/firewall/interception.go b/firewall/interception.go index 3ef6a62b..32bf7f3f 100644 --- a/firewall/interception.go +++ b/firewall/interception.go @@ -13,12 +13,9 @@ import ( "github.com/tevino/abool" "golang.org/x/sync/singleflight" - "github.com/safing/portbase/api" - "github.com/safing/portbase/config" "github.com/safing/portbase/log" "github.com/safing/portbase/modules" "github.com/safing/portmaster/compat" - "github.com/safing/portmaster/core" _ "github.com/safing/portmaster/core/base" "github.com/safing/portmaster/firewall/inspection" "github.com/safing/portmaster/firewall/interception" @@ -46,12 +43,6 @@ var ( ownPID = os.Getpid() ) -// Config variables for interception module. -var ( - devMode config.BoolOption - apiListenAddress config.StringOption -) - func init() { // TODO: Move interception module to own package (dir). interceptionModule = modules.Register("interception", interceptionPrep, interceptionStart, interceptionStop, "base", "updates", "network", "notifications") @@ -60,12 +51,15 @@ func init() { } func interceptionPrep() error { + if err := registerConfig(); err != nil { + return err + } + return prepAPIAuth() } func interceptionStart() error { - devMode = config.Concurrent.GetAsBool(core.CfgDevModeKey, false) - apiListenAddress = config.GetAsString(api.CfgDefaultListenAddressKey, "") + getConfig() if err := registerMetrics(); err != nil { return err