diff --git a/chain.go b/chain.go index f98fbd5..39b192c 100644 --- a/chain.go +++ b/chain.go @@ -173,6 +173,13 @@ func (cc *Conn) FlushChain(c *Chain) { // ListChains returns currently configured chains in the kernel func (cc *Conn) ListChains() ([]*Chain, error) { + return cc.ListChainsOfTableFamily(TableFamilyUnspecified) +} + +// ListChainsOfTableFamily returns currently configured chains for the specified +// family in the kernel. It lists all chains ins all tables if family is +// TableFamilyUnspecified. +func (cc *Conn) ListChainsOfTableFamily(family TableFamily) ([]*Chain, error) { conn, closer, err := cc.netlinkConn() if err != nil { return nil, err @@ -184,7 +191,7 @@ func (cc *Conn) ListChains() ([]*Chain, error) { Type: netlink.HeaderType((unix.NFNL_SUBSYS_NFTABLES << 8) | unix.NFT_MSG_GETCHAIN), Flags: netlink.Request | netlink.Dump, }, - Data: extraHeader(uint8(TableFamilyUnspecified), 0), + Data: extraHeader(uint8(family), 0), } response, err := conn.Execute(msg) diff --git a/table.go b/table.go index 8019117..bf76df3 100644 --- a/table.go +++ b/table.go @@ -101,6 +101,12 @@ func (cc *Conn) FlushTable(t *Table) { // ListTables returns currently configured tables in the kernel func (cc *Conn) ListTables() ([]*Table, error) { + return cc.ListTablesOfFamily(TableFamilyUnspecified) +} + +// ListTables returns currently configured tables for the specified table family +// in the kernel. It lists all tables if family is TableFamilyUnspecified. +func (cc *Conn) ListTablesOfFamily(family TableFamily) ([]*Table, error) { conn, closer, err := cc.netlinkConn() if err != nil { return nil, err @@ -112,7 +118,7 @@ func (cc *Conn) ListTables() ([]*Table, error) { Type: netlink.HeaderType((unix.NFNL_SUBSYS_NFTABLES << 8) | unix.NFT_MSG_GETTABLE), Flags: netlink.Request | netlink.Dump, }, - Data: extraHeader(uint8(TableFamilyUnspecified), 0), + Data: extraHeader(uint8(family), 0), } response, err := conn.Execute(msg)