diff --git a/iptables/iptables.go b/iptables/iptables.go index 8db2597..a3a0992 100644 --- a/iptables/iptables.go +++ b/iptables/iptables.go @@ -324,6 +324,11 @@ func (ipt *IPTables) ClearChain(table, chain string) error { } } +// Flush table chain +func (ipt *IPTables) FlushChain(table string, chain string) error { + return ipt.run("-t", table, "--flush", chain) +} + // RenameChain renames the old chain to the new one. func (ipt *IPTables) RenameChain(table, oldChain, newChain string) error { return ipt.run("-t", table, "-E", oldChain, newChain) diff --git a/iptables/iptables_test.go b/iptables/iptables_test.go index dcd996c..0a207be 100644 --- a/iptables/iptables_test.go +++ b/iptables/iptables_test.go @@ -152,6 +152,18 @@ func runChainTests(t *testing.T, ipt *IPTables) { t.Fatal("DeleteChain of non-empty chain returned IsNotExist") } + // lets re-put a simple rule in again + err = ipt.Append("filter", chain, "-s", "0/0", "-j", "ACCEPT") + if err != nil { + t.Fatalf("Append failed: %v", err) + } + + // lets flush the chain + err = ipt.FlushChain("filter", chain) + if err != nil { + t.Fatalf("Flush table chain failed: %v", err) + } + err = ipt.ClearChain("filter", chain) if err != nil { t.Fatalf("ClearChain (of non-empty) failed: %v", err)