ct: Specify direction for saddr, daddr, proto-src, proto-dst

The CT keys require direction parameter.
This commit is contained in:
Aleksei Ilin 2024-07-22 02:35:01 +02:00
parent aa8348f790
commit 06c1ca210e
1 changed files with 16 additions and 0 deletions

View File

@ -61,6 +61,7 @@ type Ct struct {
Register uint32 Register uint32
SourceRegister bool SourceRegister bool
Key CtKey Key CtKey
Direction uint32
} }
func (e *Ct) marshal(fam byte) ([]byte, error) { func (e *Ct) marshal(fam byte) ([]byte, error) {
@ -91,6 +92,19 @@ func (e *Ct) marshal(fam byte) ([]byte, error) {
} }
exprData = append(exprData, regData...) exprData = append(exprData, regData...)
switch e.Key {
case CtKeySRC, CtKeyDST, CtKeyPROTOSRC, CtKeyPROTODST:
regData, err = netlink.MarshalAttributes(
[]netlink.Attribute{
{Type: unix.NFTA_CT_DIRECTION, Data: binaryutil.BigEndian.PutUint32(e.Direction)},
},
)
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: exprData}, {Type: unix.NLA_F_NESTED | unix.NFTA_EXPR_DATA, Data: exprData},
@ -109,6 +123,8 @@ func (e *Ct) unmarshal(fam byte, data []byte) error {
e.Key = CtKey(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()
case unix.NFTA_CT_DIRECTION:
e.Direction = ad.Uint32()
} }
} }
return ad.Err() return ad.Err()