Chain: add 'device' as hook attribute

NETDEV tables can specify a device the apply to.
Add support for this by augmenting the `Chain` struct.
This commit is contained in:
Daniel Mack 2024-03-12 15:14:24 +01:00 committed by Michael Stapelberg
parent 4dbe06f125
commit 8ffcbc2d36
1 changed files with 6 additions and 0 deletions

View File

@ -102,6 +102,7 @@ type Chain struct {
Priority *ChainPriority
Type ChainType
Policy *ChainPolicy
Device string
}
// AddChain adds the specified Chain. See also
@ -119,6 +120,11 @@ func (cc *Conn) AddChain(c *Chain) *Chain {
{Type: unix.NFTA_HOOK_HOOKNUM, Data: binaryutil.BigEndian.PutUint32(uint32(*c.Hooknum))},
{Type: unix.NFTA_HOOK_PRIORITY, Data: binaryutil.BigEndian.PutUint32(uint32(*c.Priority))},
}
if c.Device != "" {
hookAttr = append(hookAttr, netlink.Attribute{Type: unix.NFTA_HOOK_DEV, Data: []byte(c.Device + "\x00")})
}
data = append(data, cc.marshalAttr([]netlink.Attribute{
{Type: unix.NLA_F_NESTED | unix.NFTA_CHAIN_HOOK, Data: cc.marshalAttr(hookAttr)},
})...)