Skip to content

Commit

Permalink
datapath/loader: refactor function to remove iptables chain
Browse files Browse the repository at this point in the history
We do the same thing for IPv4 and IPv6, with just the name of the
program changing. Then we do nearly the same thing for flushing and
deleting a chain. Let's refactor (no functional change).

Signed-off-by: Quentin Monnet <quentin@isovalent.com>
  • Loading branch information
qmonnet authored and aanm committed Jun 11, 2020
1 parent b2c73e7 commit 66aa41d
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions pkg/datapath/iptables/iptables.go
Expand Up @@ -204,33 +204,25 @@ func (m *IptablesManager) removeCiliumRules(table, prog, match string) {
}

func (c *customChain) remove(waitArgs []string, quiet bool) {
if option.Config.EnableIPv4 {
prog := "iptables"
args := append(waitArgs, "-t", c.table, "-F", c.name)
doProcess := func(c *customChain, prog string, args []string, operation string, quiet bool) {
err := runProg(prog, args, true)
if err != nil && !quiet {
log.WithError(err).WithField(logfields.Object, args).Warnf("Unable to flush Cilium %s chain", prog)
}

args = append(waitArgs, "-t", c.table, "-X", c.name)
err = runProg(prog, args, true)
if err != nil && !quiet {
log.WithError(err).WithField(logfields.Object, args).Warnf("Unable to delete Cilium %s chain", prog)
log.WithError(err).WithField(logfields.Object, args).Warnf("Unable to %s Cilium %s chain", operation, prog)
}
}
if option.Config.EnableIPv6 && c.ipv6 == true {
prog := "ip6tables"
doRemove := func(c *customChain, prog string, waitArgs []string, quiet bool) {
args := append(waitArgs, "-t", c.table, "-F", c.name)
err := runProg(prog, args, true)
if err != nil && !quiet {
log.WithError(err).WithField(logfields.Object, args).Warnf("Unable to flush Cilium %s chain", prog)
}

doProcess(c, prog, args, "flush", quiet)
args = append(waitArgs, "-t", c.table, "-X", c.name)
err = runProg(prog, args, true)
if err != nil && !quiet {
log.WithError(err).WithField(logfields.Object, args).Warnf("Unable to delete Cilium %s chain", prog)
}
doProcess(c, prog, args, "delete", quiet)
}
if option.Config.EnableIPv4 {
prog := "iptables"
doRemove(c, prog, waitArgs, quiet)
}
if option.Config.EnableIPv6 && c.ipv6 {
prog := "ip6tables"
doRemove(c, prog, waitArgs, quiet)
}
}

Expand Down

0 comments on commit 66aa41d

Please sign in to comment.