hotfix(firewall): save and restore behavior fixed

- restore if IPv4 set all policies fails
- fix deadlock when using iptables custom rules
- fix setting ipv6 rules when running runMixedIptablesInstruction
This commit is contained in:
Quentin McGaw
2026-02-28 14:37:58 +00:00
parent b9d49e0661
commit ec24ffdfd8
3 changed files with 9 additions and 9 deletions
+6 -6
View File
@@ -45,6 +45,12 @@ func (c *Config) enable(ctx context.Context) (err error) {
return fmt.Errorf("saving firewall rules: %w", err) return fmt.Errorf("saving firewall rules: %w", err)
} }
defer func() {
if err != nil {
c.restore(context.Background())
}
}()
if err = c.impl.SetIPv4AllPolicies(ctx, "DROP"); err != nil { if err = c.impl.SetIPv4AllPolicies(ctx, "DROP"); err != nil {
return err return err
} }
@@ -53,12 +59,6 @@ func (c *Config) enable(ctx context.Context) (err error) {
return err return err
} }
defer func() {
if err != nil {
c.restore(context.Background())
}
}()
// Loopback traffic // Loopback traffic
if err = c.impl.AcceptInputThroughInterface(ctx, "lo"); err != nil { if err = c.impl.AcceptInputThroughInterface(ctx, "lo"); err != nil {
return err return err
+2 -2
View File
@@ -337,11 +337,11 @@ func (c *Config) RunUserPostRules(ctx context.Context, filepath string) error {
switch { switch {
case ipv4: case ipv4:
err = c.runIptablesInstruction(ctx, rule) err = c.runIptablesInstructionNoSave(ctx, rule)
case c.ip6Tables == "": case c.ip6Tables == "":
err = fmt.Errorf("running user ip6tables rule: %w", ErrNeedIP6Tables) err = fmt.Errorf("running user ip6tables rule: %w", ErrNeedIP6Tables)
default: // ipv6 default: // ipv6
err = c.runIP6tablesInstruction(ctx, rule) err = c.runIP6tablesInstructionNoSave(ctx, rule)
} }
if err != nil { if err != nil {
restore(ctx) restore(ctx)
+1 -1
View File
@@ -34,7 +34,7 @@ func (c *Config) runMixedIptablesInstruction(ctx context.Context, instruction st
if err != nil { if err != nil {
return err return err
} }
err = c.runIptablesInstructionNoSave(ctx, instruction) err = c.runMixedIptablesInstructionNoSave(ctx, instruction)
if err != nil { if err != nil {
restore(ctx) restore(ctx)
} }