list tables and chains optionally by specific table family (#168)
This commit is contained in:
parent
a9775fb167
commit
1f0380f5c7
9
chain.go
9
chain.go
|
@ -173,6 +173,13 @@ func (cc *Conn) FlushChain(c *Chain) {
|
||||||
|
|
||||||
// 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) {
|
||||||
|
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()
|
conn, closer, err := cc.netlinkConn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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),
|
Type: netlink.HeaderType((unix.NFNL_SUBSYS_NFTABLES << 8) | unix.NFT_MSG_GETCHAIN),
|
||||||
Flags: netlink.Request | netlink.Dump,
|
Flags: netlink.Request | netlink.Dump,
|
||||||
},
|
},
|
||||||
Data: extraHeader(uint8(TableFamilyUnspecified), 0),
|
Data: extraHeader(uint8(family), 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := conn.Execute(msg)
|
response, err := conn.Execute(msg)
|
||||||
|
|
8
table.go
8
table.go
|
@ -101,6 +101,12 @@ func (cc *Conn) FlushTable(t *Table) {
|
||||||
|
|
||||||
// ListTables returns currently configured tables in the kernel
|
// ListTables returns currently configured tables in the kernel
|
||||||
func (cc *Conn) ListTables() ([]*Table, error) {
|
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()
|
conn, closer, err := cc.netlinkConn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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),
|
Type: netlink.HeaderType((unix.NFNL_SUBSYS_NFTABLES << 8) | unix.NFT_MSG_GETTABLE),
|
||||||
Flags: netlink.Request | netlink.Dump,
|
Flags: netlink.Request | netlink.Dump,
|
||||||
},
|
},
|
||||||
Data: extraHeader(uint8(TableFamilyUnspecified), 0),
|
Data: extraHeader(uint8(family), 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := conn.Execute(msg)
|
response, err := conn.Execute(msg)
|
||||||
|
|
Loading…
Reference in New Issue