FIREWALL_IMPLEMENTATION option

This commit is contained in:
Quentin McGaw
2026-08-06 15:56:19 +00:00
parent 113253b523
commit 27b089d757
6 changed files with 37 additions and 9 deletions
@@ -4,6 +4,7 @@ import (
"fmt"
"net/netip"
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
"github.com/qdm12/gosettings"
"github.com/qdm12/gosettings/reader"
"github.com/qdm12/gotree"
@@ -16,6 +17,7 @@ type Firewall struct {
OutboundSubnets []netip.Prefix
Enabled *bool
Debug *bool
Implementation string
}
func (f Firewall) validate() (err error) {
@@ -33,6 +35,10 @@ func (f Firewall) validate() (err error) {
}
}
if !helpers.IsOneOf(f.Implementation, "iptables", "nftables") {
return fmt.Errorf("firewall implementation %q must be either 'iptables' or 'nftables'", f.Implementation)
}
return nil
}
@@ -52,6 +58,7 @@ func (f *Firewall) copy() (copied Firewall) {
OutboundSubnets: gosettings.CopySlice(f.OutboundSubnets),
Enabled: gosettings.CopyPointer(f.Enabled),
Debug: gosettings.CopyPointer(f.Debug),
Implementation: f.Implementation,
}
}
@@ -64,11 +71,13 @@ func (f *Firewall) overrideWith(other Firewall) {
f.OutboundSubnets = gosettings.OverrideWithSlice(f.OutboundSubnets, other.OutboundSubnets)
f.Enabled = gosettings.OverrideWithPointer(f.Enabled, other.Enabled)
f.Debug = gosettings.OverrideWithPointer(f.Debug, other.Debug)
f.Implementation = gosettings.OverrideWithComparable(f.Implementation, other.Implementation)
}
func (f *Firewall) setDefaults() {
f.Enabled = gosettings.DefaultPointer(f.Enabled, true)
f.Debug = gosettings.DefaultPointer(f.Debug, false)
f.Implementation = gosettings.DefaultComparable(f.Implementation, "iptables")
}
func (f Firewall) String() string {
@@ -83,6 +92,8 @@ func (f Firewall) toLinesNode() (node *gotree.Node) {
return node
}
node.Appendf("Implementation: %s", f.Implementation)
if *f.Debug {
node.Appendf("Debug mode: on")
}
@@ -138,5 +149,7 @@ func (f *Firewall) read(r *reader.Reader) (err error) {
return err
}
f.Implementation = r.String("FIREWALL_IMPLEMENTATION")
return nil
}
@@ -65,7 +65,8 @@ func Test_Settings_String(t *testing.T) {
| ├── Block ads: no
| └── Block surveillance: yes
├── Firewall settings:
| ── Enabled: yes
| ── Enabled: yes
| └── Implementation: iptables
├── Log settings:
| └── Log level: INFO
├── Health settings: