[expr] Add SourceRegister field and modify marshal function to work with it.
This commit is contained in:
parent
3c7d959797
commit
71337b220c
37
expr/ct.go
37
expr/ct.go
|
@ -51,21 +51,42 @@ const (
|
|||
|
||||
// Ct defines type for NFT connection tracking
|
||||
type Ct struct {
|
||||
Register uint32
|
||||
Key CtKey
|
||||
Register uint32
|
||||
SourceRegister bool
|
||||
Key CtKey
|
||||
}
|
||||
|
||||
func (e *Ct) marshal() ([]byte, error) {
|
||||
data, err := netlink.MarshalAttributes([]netlink.Attribute{
|
||||
{Type: unix.NFTA_CT_KEY, Data: binaryutil.BigEndian.PutUint32(uint32(e.Key))},
|
||||
{Type: unix.NFTA_CT_DREG, Data: binaryutil.BigEndian.PutUint32(e.Register)},
|
||||
})
|
||||
regData := []byte{}
|
||||
exprData, err := netlink.MarshalAttributes(
|
||||
[]netlink.Attribute{
|
||||
{Type: unix.NFTA_CT_KEY, Data: binaryutil.BigEndian.PutUint32(uint32(e.Key))},
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if e.SourceRegister {
|
||||
regData, err = netlink.MarshalAttributes(
|
||||
[]netlink.Attribute{
|
||||
{Type: unix.NFTA_CT_SREG, Data: binaryutil.BigEndian.PutUint32(e.Register)},
|
||||
},
|
||||
)
|
||||
} else {
|
||||
regData, err = netlink.MarshalAttributes(
|
||||
[]netlink.Attribute{
|
||||
{Type: unix.NFTA_CT_DREG, Data: binaryutil.BigEndian.PutUint32(e.Register)},
|
||||
},
|
||||
)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
exprData = append(exprData, regData...)
|
||||
|
||||
return netlink.MarshalAttributes([]netlink.Attribute{
|
||||
{Type: unix.NFTA_EXPR_NAME, Data: []byte("ct\x00")},
|
||||
{Type: unix.NLA_F_NESTED | unix.NFTA_EXPR_DATA, Data: data},
|
||||
{Type: unix.NLA_F_NESTED | unix.NFTA_EXPR_DATA, Data: exprData},
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -78,7 +99,7 @@ func (e *Ct) unmarshal(data []byte) error {
|
|||
for ad.Next() {
|
||||
switch ad.Type() {
|
||||
case unix.NFTA_CT_KEY:
|
||||
e.Key = ad.Uint32()
|
||||
e.Key = CtKey(ad.Uint32())
|
||||
case unix.NFTA_CT_DREG:
|
||||
e.Register = ad.Uint32()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue