This commit is contained in:
Nikita Vorontsov 2025-08-28 16:48:33 +03:00
parent 919abdc34f
commit 3c0f824ccc
2 changed files with 15 additions and 14 deletions

View File

@ -137,7 +137,7 @@ func TestTableCreateDestroy(t *testing.T) {
Family: nftables.TableFamilyIPv4,
Name: "filter",
}
c.DelTable(filter, true)
c.DestroyTable(filter)
c.AddTable(filter)
err := c.Flush()
if err != nil {
@ -157,17 +157,16 @@ func TestTableCreateDestroy(t *testing.T) {
t.Fatal("AddTable doesn't create my table!")
}
c.DelTable(filter)
err = c.Flush()
if err != nil {
c.DestroyTable(filter)
if err = c.Flush(); err != nil {
t.Fatalf("on Flush: %q", err.Error())
}
if LookupMyTable() {
t.Fatal("DelTable doesn't delete my table!")
t.Fatal("DestroyTable doesn't delete my table!")
}
c.DelTable(filter, true) // just for test that 'force' ignore error 'not found'
c.DestroyTable(filter) // just for test that 'destroy' ignore error 'not found'
}
func TestRuleOperations(t *testing.T) {

View File

@ -16,7 +16,6 @@ package nftables
import (
"fmt"
"slices"
"github.com/mdlayher/netlink"
"golang.org/x/sys/unix"
@ -55,7 +54,16 @@ type Table struct {
}
// DelTable deletes a specific table, along with all chains/rules it contains.
func (cc *Conn) DelTable(t *Table, force ...bool) {
func (cc *Conn) DelTable(t *Table) {
cc.delTable(t, delTableHeaderType)
}
// DestroyTable is like DelTable, but not an error if table doesn't exists
func (cc *Conn) DestroyTable(t *Table) {
cc.delTable(t, destroyTableHeaderType)
}
func (cc *Conn) delTable(t *Table, hdrType netlink.HeaderType) {
cc.mu.Lock()
defer cc.mu.Unlock()
data := cc.marshalAttr([]netlink.Attribute{
@ -63,12 +71,6 @@ func (cc *Conn) DelTable(t *Table, force ...bool) {
{Type: unix.NFTA_TABLE_FLAGS, Data: []byte{0, 0, 0, 0}},
})
var hdrType netlink.HeaderType
if slices.Contains(force, true) {
hdrType = destroyTableHeaderType
} else {
hdrType = delTableHeaderType
}
cc.messages = append(cc.messages, netlinkMessage{
Header: netlink.Header{
Type: hdrType,