CR fixes
This commit is contained in:
parent
919abdc34f
commit
3c0f824ccc
|
@ -137,7 +137,7 @@ func TestTableCreateDestroy(t *testing.T) {
|
||||||
Family: nftables.TableFamilyIPv4,
|
Family: nftables.TableFamilyIPv4,
|
||||||
Name: "filter",
|
Name: "filter",
|
||||||
}
|
}
|
||||||
c.DelTable(filter, true)
|
c.DestroyTable(filter)
|
||||||
c.AddTable(filter)
|
c.AddTable(filter)
|
||||||
err := c.Flush()
|
err := c.Flush()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -157,17 +157,16 @@ func TestTableCreateDestroy(t *testing.T) {
|
||||||
t.Fatal("AddTable doesn't create my table!")
|
t.Fatal("AddTable doesn't create my table!")
|
||||||
}
|
}
|
||||||
|
|
||||||
c.DelTable(filter)
|
c.DestroyTable(filter)
|
||||||
err = c.Flush()
|
if err = c.Flush(); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("on Flush: %q", err.Error())
|
t.Fatalf("on Flush: %q", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if LookupMyTable() {
|
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) {
|
func TestRuleOperations(t *testing.T) {
|
||||||
|
|
18
table.go
18
table.go
|
@ -16,7 +16,6 @@ package nftables
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"slices"
|
|
||||||
|
|
||||||
"github.com/mdlayher/netlink"
|
"github.com/mdlayher/netlink"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
|
@ -55,7 +54,16 @@ type Table struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// DelTable deletes a specific table, along with all chains/rules it contains.
|
// 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()
|
cc.mu.Lock()
|
||||||
defer cc.mu.Unlock()
|
defer cc.mu.Unlock()
|
||||||
data := cc.marshalAttr([]netlink.Attribute{
|
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}},
|
{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{
|
cc.messages = append(cc.messages, netlinkMessage{
|
||||||
Header: netlink.Header{
|
Header: netlink.Header{
|
||||||
Type: hdrType,
|
Type: hdrType,
|
||||||
|
|
Loading…
Reference in New Issue