Skip to content

Commit 53b948b

Browse files
fixed exception loading outdated configuration
TODO: send the error to the GUI. It's important enough to warn the user about it. Issue: #1380
1 parent faeed35 commit 53b948b

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

daemon/firewall/rules.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ var (
4747
// If iptables is not installed, we can add nftables rules directly to the kernel,
4848
// without relying on any binaries.
4949
func Init(fwType, configPath, monitorInterval string, bypassQueue bool, qNum uint16) (err error) {
50+
confError := false
51+
if fwType == "" {
52+
confError = true
53+
fwType = nftables.Name
54+
}
55+
if configPath == "" {
56+
confError = true
57+
configPath = config.DefaultConfigFile
58+
}
59+
5060
if fwType == iptables.Name {
5161
fw, err = iptables.Fw()
5262
if err != nil {
@@ -66,13 +76,14 @@ func Init(fwType, configPath, monitorInterval string, bypassQueue bool, qNum uin
6676
}
6777

6878
if fw == nil {
69-
return fmt.Errorf("Firewall not initialized")
70-
}
71-
if configPath == "" {
72-
configPath = config.DefaultConfigFile
79+
return fmt.Errorf("Firewall not initialized. Be sure that you're using latest configuration file. Report it on github if needed.")
7380
}
7481
fw.Stop()
7582
fw.Init(qNum, configPath, monitorInterval, bypassQueue)
83+
if confError {
84+
log.Error("Firewall error: the default configuration seem to be outdated (default-config.json). Get latest configuration from github.")
85+
}
86+
7687
queueNum = qNum
7788

7889
log.Info("Using %s firewall", fw.Name())
@@ -149,10 +160,16 @@ func SaveConfiguration(rawConfig []byte) error {
149160

150161
// Serialize transforms firewall json configuration to protobuf
151162
func Serialize() (*protocol.SysFirewall, error) {
163+
if fw == nil {
164+
return nil, fmt.Errorf("firewall not initialized, report please")
165+
}
152166
return fw.Serialize()
153167
}
154168

155169
// Deserialize transforms firewall json configuration to protobuf
156170
func Deserialize(sysfw *protocol.SysFirewall) ([]byte, error) {
171+
if fw == nil {
172+
return nil, fmt.Errorf("firewall not initialized, report please")
173+
}
157174
return fw.Deserialize(sysfw)
158175
}

daemon/ui/config_utils.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,15 @@ func (c *Client) reloadConfiguration(reload bool, newConfig *config.Config) (err
231231
log.Debug("[config] reloading config.firewall")
232232
reloadFw = true
233233

234-
firewall.Reload(
234+
if err := firewall.Reload(
235235
newConfig.Firewall,
236236
newConfig.FwOptions.ConfigPath,
237237
newConfig.FwOptions.MonitorInterval,
238238
newConfig.FwOptions.QueueBypass,
239239
newConfig.FwOptions.QueueNum,
240-
)
240+
); err != nil {
241+
log.Error("[config] firewall reload error: %s", err)
242+
}
241243
} else {
242244
log.Debug("[config] config.firewall not changed")
243245
}

0 commit comments

Comments
 (0)