Skip to content

Commit

Permalink
log deleting iptables rule (#4031)
Browse files Browse the repository at this point in the history
Signed-off-by: bobz965 <[email protected]>
  • Loading branch information
bobz965 committed May 17, 2024
1 parent 87c0074 commit a0c2a43
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/daemon/gateway_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1093,15 +1093,20 @@ func (c *Controller) generateNatOutgoingPolicyChainRules(protocol string) ([]uti
}

func deleteIptablesRule(ipt *iptables.IPTables, rule util.IPTableRule) error {
klog.V(3).Infof("delete iptables rule: %v", rule)
if rule.Pos != "" {
klog.Infof("delete iptables rule by pos %s: %v", rule.Pos, rule)
if err := ipt.Delete(rule.Table, rule.Chain, rule.Pos); err != nil {
klog.Errorf("failed to delete iptables %s rule %q: %v", rule.Chain, strings.Join(rule.Rule, " "), err)
return err
}
return nil
}
if err := ipt.DeleteIfExists(rule.Table, rule.Chain, rule.Rule...); err != nil {
exists, err := ipt.Exists(rule.Table, rule.Chain, rule.Rule...)
if err == nil && exists {
klog.Infof("delete iptables rule: %v", rule)
err = ipt.Delete(rule.Table, rule.Chain, rule.Rule...)
}
if err != nil {
klog.Errorf("failed to delete iptables rule %q: %v", strings.Join(rule.Rule, " "), err)
return err
}
Expand Down

0 comments on commit a0c2a43

Please sign in to comment.