[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
|
// Ct defines type for NFT connection tracking
|
||||||
type Ct struct {
|
type Ct struct {
|
||||||
Register uint32
|
Register uint32
|
||||||
Key CtKey
|
SourceRegister bool
|
||||||
|
Key CtKey
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Ct) marshal() ([]byte, error) {
|
func (e *Ct) marshal() ([]byte, error) {
|
||||||
data, err := netlink.MarshalAttributes([]netlink.Attribute{
|
regData := []byte{}
|
||||||
{Type: unix.NFTA_CT_KEY, Data: binaryutil.BigEndian.PutUint32(uint32(e.Key))},
|
exprData, err := netlink.MarshalAttributes(
|
||||||
{Type: unix.NFTA_CT_DREG, Data: binaryutil.BigEndian.PutUint32(e.Register)},
|
[]netlink.Attribute{
|
||||||
})
|
{Type: unix.NFTA_CT_KEY, Data: binaryutil.BigEndian.PutUint32(uint32(e.Key))},
|
||||||
|
},
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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{
|
return netlink.MarshalAttributes([]netlink.Attribute{
|
||||||
{Type: unix.NFTA_EXPR_NAME, Data: []byte("ct\x00")},
|
{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() {
|
for ad.Next() {
|
||||||
switch ad.Type() {
|
switch ad.Type() {
|
||||||
case unix.NFTA_CT_KEY:
|
case unix.NFTA_CT_KEY:
|
||||||
e.Key = ad.Uint32()
|
e.Key = CtKey(ad.Uint32())
|
||||||
case unix.NFTA_CT_DREG:
|
case unix.NFTA_CT_DREG:
|
||||||
e.Register = ad.Uint32()
|
e.Register = ad.Uint32()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue