From e49143a9d1b5144dae59ca80569c45624083c2d6 Mon Sep 17 00:00:00 2001 From: Maxime Demode Date: Wed, 23 Oct 2019 14:37:48 +0200 Subject: [PATCH] [table] Add FlushTable function. --- table.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/table.go b/table.go index e25b566..507f6b9 100644 --- a/table.go +++ b/table.go @@ -74,6 +74,21 @@ func (cc *Conn) AddTable(t *Table) *Table { return t } +// FlushTable removes all rules in all chains within the specified Table. See also +// https://wiki.nftables.org/wiki-nftables/index.php/Configuring_tables#Flushing_tables +func (cc *Conn) FlushTable(t *Table) { + data := cc.marshalAttr([]netlink.Attribute{ + {Type: unix.NFTA_RULE_TABLE, Data: []byte(t.Name + "\x00")}, + }) + cc.messages = append(cc.messages, netlink.Message{ + Header: netlink.Header{ + Type: netlink.HeaderType((unix.NFNL_SUBSYS_NFTABLES << 8) | unix.NFT_MSG_DELRULE), + Flags: netlink.Request | netlink.Acknowledge, + }, + Data: append(extraHeader(uint8(t.Family), 0), data...), + }) +} + // ListTables returns currently configured tables in the kernel func (cc *Conn) ListTables() ([]*Table, error) { conn, err := cc.dialNetlink()