Browse Source

Merge pull request #14 from lyondhill/master

Add a RenameChain function
Jonathan Boulle 9 years ago
parent
commit
90456be57f
2 changed files with 13 additions and 1 deletions
  1. 5 0
      iptables/iptables.go
  2. 8 1
      iptables/iptables_test.go

+ 5 - 0
iptables/iptables.go

@@ -159,6 +159,11 @@ func (ipt *IPTables) ClearChain(table, chain string) error {
 	}
 }
 
+// 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)
+}
+
 // DeleteChain deletes the chain in the specified table.
 // The chain must be empty
 func (ipt *IPTables) DeleteChain(table, chain string) error {

+ 8 - 1
iptables/iptables_test.go

@@ -67,8 +67,15 @@ func TestChain(t *testing.T) {
 		t.Fatalf("ClearChain (of non-empty) failed: %v", err)
 	}
 
+	// rename the chain
+	newChain := randChain(t)
+	err = ipt.RenameChain("filter", chain, newChain)
+	if err != nil {
+		t.Fatalf("RenameChain failed: %v", err)
+	}
+
 	// chain empty, should be ok
-	err = ipt.DeleteChain("filter", chain)
+	err = ipt.DeleteChain("filter", newChain)
 	if err != nil {
 		t.Fatalf("DeleteChain of empty chain failed: %v", err)
 	}