[chain] Add FlushChain function.

This commit is contained in:
Maxime Demode 2019-10-23 14:18:45 +02:00
parent 35de0a609f
commit 22243d5c70
1 changed files with 16 additions and 0 deletions

View File

@ -151,6 +151,22 @@ func (cc *Conn) DelChain(c *Chain) {
}) })
} }
// FlushChain removes all rules within the specified Chain. See also
// https://wiki.nftables.org/wiki-nftables/index.php/Configuring_chains#Flushing_chain
func (cc *Conn) FlushChain(c *Chain) {
data := cc.marshalAttr([]netlink.Attribute{
{Type: unix.NFTA_RULE_TABLE, Data: []byte(c.Table.Name + "\x00")},
{Type: unix.NFTA_RULE_CHAIN, Data: []byte(c.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(c.Table.Family), 0), data...),
})
}
// ListChains returns currently configured chains in the kernel // ListChains returns currently configured chains in the kernel
func (cc *Conn) ListChains() ([]*Chain, error) { func (cc *Conn) ListChains() ([]*Chain, error) {
conn, err := cc.dialNetlink() conn, err := cc.dialNetlink()