From 8ffcbc2d360c941349ee7162cb04e855ac0ec28b Mon Sep 17 00:00:00 2001 From: Daniel Mack Date: Tue, 12 Mar 2024 15:14:24 +0100 Subject: [PATCH] Chain: add 'device' as hook attribute NETDEV tables can specify a device the apply to. Add support for this by augmenting the `Chain` struct. --- chain.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/chain.go b/chain.go index 5bc0e49..8d797be 100644 --- a/chain.go +++ b/chain.go @@ -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)}, })...)