hotfix(firewall/iptables): only restore firewall if IPv6 port redirection failed but NAT is supported

This commit is contained in:
Quentin McGaw
2026-05-23 21:26:08 +00:00
parent a1ef736b0f
commit 3eebbf65a8
+1 -1
View File
@@ -278,7 +278,6 @@ func (c *Config) RedirectPort(ctx context.Context, intf string,
appendOrDelete(remove), interfaceFlag, destinationPort), appendOrDelete(remove), interfaceFlag, destinationPort),
}) })
if err != nil { if err != nil {
restore(ctx) // just in case
errMessage := err.Error() errMessage := err.Error()
if strings.Contains(errMessage, "can't initialize ip6tables table `nat': Table does not exist") { if strings.Contains(errMessage, "can't initialize ip6tables table `nat': Table does not exist") {
if !remove { if !remove {
@@ -286,6 +285,7 @@ func (c *Config) RedirectPort(ctx context.Context, intf string,
} }
return nil return nil
} }
restore(ctx)
return fmt.Errorf("redirecting IPv6 source port %d to destination port %d on interface %s: %w", return fmt.Errorf("redirecting IPv6 source port %d to destination port %d on interface %s: %w",
sourcePort, destinationPort, intf, err) sourcePort, destinationPort, intf, err)
} }