Skip to content

Commit

Permalink
Chain: add 'device' as hook attribute
Browse files Browse the repository at this point in the history
NETDEV tables can specify a device the apply to.
Add support for this by augmenting the `Chain` struct.
  • Loading branch information
zonque authored and stapelberg committed Apr 1, 2024
1 parent 4dbe06f commit 8ffcbc2
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ type Chain struct {
Priority *ChainPriority
Type ChainType
Policy *ChainPolicy
Device string
}

// AddChain adds the specified Chain. See also
Expand All @@ -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)},
})...)
Expand Down

0 comments on commit 8ffcbc2

Please sign in to comment.