diff --git a/expr/payload.go b/expr/payload.go index 63805be..826b3cf 100644 --- a/expr/payload.go +++ b/expr/payload.go @@ -24,6 +24,7 @@ import ( type PayloadBase uint32 type PayloadCsumType uint32 +type PayloadOperationType uint32 // Possible PayloadBase values. const ( @@ -38,7 +39,14 @@ const ( CsumTypeInet PayloadCsumType = unix.NFT_PAYLOAD_CSUM_INET ) +// Possible PayloadType values. +const ( + PayloadLoad PayloadOperationType = iota + PayloadWrite +) + type Payload struct { + OperationType PayloadOperationType DestRegister uint32 SourceRegister uint32 Base PayloadBase @@ -53,7 +61,7 @@ func (e *Payload) marshal() ([]byte, error) { var attrs []netlink.Attribute - if e.SourceRegister > 0 { + if e.OperationType == PayloadWrite { attrs = []netlink.Attribute{ {Type: unix.NFTA_PAYLOAD_SREG, Data: binaryutil.BigEndian.PutUint32(e.SourceRegister)}, } diff --git a/nftables_test.go b/nftables_test.go index e66e846..e3337ef 100644 --- a/nftables_test.go +++ b/nftables_test.go @@ -3962,6 +3962,7 @@ func TestStatelessNAT(t *testing.T) { }, // [ payload write reg 1 => 4b @ network header + 16 csum_type 1 csum_off 10 csum_flags 0x1 ] &expr.Payload{ + OperationType: expr.PayloadWrite, SourceRegister: 1, Base: expr.PayloadBaseNetworkHeader, Offset: 16,