Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions iptables/iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package iptables
// This package contains wrapper functions to program iptables rules

import (
"errors"
"fmt"

"github.com/Azure/azure-container-networking/cni/log"
Expand All @@ -11,6 +12,7 @@ import (
)

var logger = log.CNILogger.With(zap.String("component", "cni-iptables"))
var errCouldNotValidateRuleExists = errors.New("could not validate iptable rule exists after insertion")

// cni iptable chains
const (
Expand Down Expand Up @@ -171,7 +173,14 @@ func (c *Client) InsertIptableRule(version, tableName, chainName, match, target
}

cmd := c.GetInsertIptableRuleCmd(version, tableName, chainName, match, target)
return c.RunCmd(version, cmd.Params)
err := c.RunCmd(version, cmd.Params)
if err != nil {
return err
}
if !c.RuleExists(version, tableName, chainName, match, target) {
return errCouldNotValidateRuleExists
}
return nil
}

func (c *Client) GetAppendIptableRuleCmd(version, tableName, chainName, match, target string) IPTableEntry {
Expand All @@ -189,7 +198,14 @@ func (c *Client) AppendIptableRule(version, tableName, chainName, match, target
}

cmd := c.GetAppendIptableRuleCmd(version, tableName, chainName, match, target)
return c.RunCmd(version, cmd.Params)
err := c.RunCmd(version, cmd.Params)
if err != nil {
return err
}
if !c.RuleExists(version, tableName, chainName, match, target) {
return errCouldNotValidateRuleExists
}
return nil
}

// Delete matched iptable rule
Expand Down
Loading