Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions iptables/iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions iptables/iptables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down