Check chain existence before deleting NAT OUTPUT jump rule

The cleanup path tried to delete the jump rule to NETBIRD-NAT-OUTPUT
unconditionally, producing a noisy debug log when the chain was never
created (common for the v6 router when no OutputDNAT rules exist).
Check ChainExists first, consistent with the chain deletion loop
below.
This commit is contained in:
Viktor Liu
2026-04-10 13:21:05 +02:00
parent 4b298fb53c
commit 4fc910031b

View File

@@ -401,9 +401,13 @@ func (r *router) cleanUpDefaultForwardRules() error {
// Remove jump rules from built-in chains before deleting custom chains, // Remove jump rules from built-in chains before deleting custom chains,
// otherwise the chain deletion fails with "device or resource busy". // otherwise the chain deletion fails with "device or resource busy".
jumpRule := []string{"-j", chainNATOutput} if ok, err := r.iptablesClient.ChainExists(tableNat, chainNATOutput); err != nil {
if err := r.iptablesClient.Delete(tableNat, "OUTPUT", jumpRule...); err != nil { return fmt.Errorf("check chain %s: %w", chainNATOutput, err)
log.Debugf("clean OUTPUT jump rule: %v", err) } else if ok {
jumpRule := []string{"-j", chainNATOutput}
if err := r.iptablesClient.Delete(tableNat, "OUTPUT", jumpRule...); err != nil {
log.Debugf("clean OUTPUT jump rule: %v", err)
}
} }
for _, chainInfo := range []struct { for _, chainInfo := range []struct {