Skip to content

Commit

Permalink
sys-fw: load default config path if non supplied
Browse files Browse the repository at this point in the history
By default load the system fw config file from
/etc/opensnitchd/system-fw.json.

There're these options to specify the file to load:

 - via cli option with -fw-config-file
 - writing it in the default-config.json file:
   "FwOptions": { "ConfigPath": "..." }

If both options are empty, then the default one is used.

FIXME:
 When the cli option is used to load the fw configuration, and the main
preferences are saved, the fw is reloaded but the path to the fw config
is lost.
  • Loading branch information
gustavo-iniguez-goya committed Jan 7, 2024
1 parent b2bd56d commit bb95a77
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions daemon/firewall/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,19 @@ type Firewall interface {
}

var (
fw Firewall
queueNum = 0
fw Firewall
queueNum = 0
DefaultConfig = "/etc/opensnitchd/system-fw.json"
)

// Init initializes the firewall and loads firewall rules.
// We'll try to use the firewall configured in the configuration (iptables/nftables).
// If iptables is not installed, we can add nftables rules directly to the kernel,
// without relying on any binaries.
func Init(fwType, configPath, monitorInterval string, qNum *int) (err error) {
if configPath == "" {
configPath = DefaultConfig
}
if fwType == iptables.Name {
fw, err = iptables.Fw()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ func main() {
repeatPktChan = repeatQueue.Packets()

fwConfigPath := fwConfigFile
if cfg.FwOptions.ConfigPath != "" {
if fwConfigPath == "" {
fwConfigPath = cfg.FwOptions.ConfigPath
}
log.Info("Using system fw configuration %s ...", fwConfigPath)
Expand Down

0 comments on commit bb95a77

Please sign in to comment.