Skip to content

Commit

Permalink
networking: Ensure CNI iptables rules are appended to chain and not f…
Browse files Browse the repository at this point in the history
…orced to be first
  • Loading branch information
microadam authored and tgross committed Apr 15, 2021
1 parent c91bd23 commit da27daf
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions client/allocrunner/networking_bridge_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (b *bridgeNetworkConfigurator) ensureForwardingRules() error {
return err
}

if err := ensureFirstChainRule(ipt, cniAdminChainName, b.generateAdminChainRule()); err != nil {
if err := appendChainRule(ipt, cniAdminChainName, b.generateAdminChainRule()); err != nil {
return err
}

Expand Down Expand Up @@ -105,12 +105,11 @@ func ensureChain(ipt *iptables.IPTables, table, chain string) error {
return err
}

// ensureFirstChainRule ensures the given rule exists as the first rule in the chain
func ensureFirstChainRule(ipt *iptables.IPTables, chain string, rule []string) error {
// appendChainRule adds the given rule to the chain
func appendChainRule(ipt *iptables.IPTables, chain string, rule []string) error {
exists, err := ipt.Exists("filter", chain, rule...)
if !exists && err == nil {
// iptables rules are 1-indexed
err = ipt.Insert("filter", chain, 1, rule...)
err = ipt.Append("filter", chain, rule...)
}
return err
}
Expand Down

0 comments on commit da27daf

Please sign in to comment.