Addressing unit test failure
Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
This commit is contained in:
parent
802c2a18ab
commit
8093f4aecc
|
@ -38,7 +38,9 @@ func (e *Dynset) marshal() ([]byte, error) {
|
||||||
// See: https://git.netfilter.org/libnftnl/tree/src/expr/dynset.c
|
// See: https://git.netfilter.org/libnftnl/tree/src/expr/dynset.c
|
||||||
var opAttrs []netlink.Attribute
|
var opAttrs []netlink.Attribute
|
||||||
opAttrs = append(opAttrs, netlink.Attribute{Type: unix.NFTA_DYNSET_SREG_KEY, Data: binaryutil.BigEndian.PutUint32(e.SrcRegKey)})
|
opAttrs = append(opAttrs, netlink.Attribute{Type: unix.NFTA_DYNSET_SREG_KEY, Data: binaryutil.BigEndian.PutUint32(e.SrcRegKey)})
|
||||||
|
if e.SrcRegData != 0 {
|
||||||
opAttrs = append(opAttrs, netlink.Attribute{Type: unix.NFTA_DYNSET_SREG_DATA, Data: binaryutil.BigEndian.PutUint32(e.SrcRegData)})
|
opAttrs = append(opAttrs, netlink.Attribute{Type: unix.NFTA_DYNSET_SREG_DATA, Data: binaryutil.BigEndian.PutUint32(e.SrcRegData)})
|
||||||
|
}
|
||||||
opAttrs = append(opAttrs, netlink.Attribute{Type: unix.NFTA_DYNSET_OP, Data: binaryutil.BigEndian.PutUint32(e.Operation)})
|
opAttrs = append(opAttrs, netlink.Attribute{Type: unix.NFTA_DYNSET_OP, Data: binaryutil.BigEndian.PutUint32(e.Operation)})
|
||||||
if e.Timeout != 0 {
|
if e.Timeout != 0 {
|
||||||
opAttrs = append(opAttrs, netlink.Attribute{Type: unix.NFTA_DYNSET_TIMEOUT, Data: binaryutil.BigEndian.PutUint64(uint64(e.Timeout.Milliseconds()))})
|
opAttrs = append(opAttrs, netlink.Attribute{Type: unix.NFTA_DYNSET_TIMEOUT, Data: binaryutil.BigEndian.PutUint64(uint64(e.Timeout.Milliseconds()))})
|
||||||
|
@ -76,6 +78,8 @@ func (e *Dynset) unmarshal(data []byte) error {
|
||||||
e.SrcRegKey = ad.Uint32()
|
e.SrcRegKey = ad.Uint32()
|
||||||
case unix.NFTA_DYNSET_SREG_DATA:
|
case unix.NFTA_DYNSET_SREG_DATA:
|
||||||
e.SrcRegData = ad.Uint32()
|
e.SrcRegData = ad.Uint32()
|
||||||
|
case unix.NFTA_DYNSET_OP:
|
||||||
|
e.Operation = ad.Uint32()
|
||||||
case unix.NFTA_DYNSET_TIMEOUT:
|
case unix.NFTA_DYNSET_TIMEOUT:
|
||||||
e.Timeout = time.Duration(ad.Uint64() * 1000)
|
e.Timeout = time.Duration(ad.Uint64() * 1000)
|
||||||
case unix.NFTA_DYNSET_FLAGS:
|
case unix.NFTA_DYNSET_FLAGS:
|
||||||
|
|
|
@ -2530,16 +2530,11 @@ func TestDynset(t *testing.T) {
|
||||||
&expr.Payload{
|
&expr.Payload{
|
||||||
DestRegister: 1,
|
DestRegister: 1,
|
||||||
Base: expr.PayloadBaseNetworkHeader,
|
Base: expr.PayloadBaseNetworkHeader,
|
||||||
Offset: 12,
|
Offset: uint32(12),
|
||||||
Len: 4,
|
Len: uint32(4),
|
||||||
},
|
|
||||||
&expr.Immediate{
|
|
||||||
Register: 2,
|
|
||||||
Data: []byte{0x0, 0x0, 0x0, 0x2},
|
|
||||||
},
|
},
|
||||||
&expr.Dynset{
|
&expr.Dynset{
|
||||||
SrcRegKey: 1,
|
SrcRegKey: 1,
|
||||||
SrcRegData: 2,
|
|
||||||
SetName: set.Name,
|
SetName: set.Name,
|
||||||
SetID: set.ID,
|
SetID: set.ID,
|
||||||
Operation: uint32(unix.NFT_DYNSET_OP_UPDATE),
|
Operation: uint32(unix.NFT_DYNSET_OP_UPDATE),
|
||||||
|
@ -2567,19 +2562,17 @@ func TestDynset(t *testing.T) {
|
||||||
if got, want := len(rules), 1; got != want {
|
if got, want := len(rules), 1; got != want {
|
||||||
t.Fatalf("unexpected number of rules: got %d, want %d", got, want)
|
t.Fatalf("unexpected number of rules: got %d, want %d", got, want)
|
||||||
}
|
}
|
||||||
if got, want := len(rules[0].Exprs), 3; got != want {
|
if got, want := len(rules[0].Exprs), 2; got != want {
|
||||||
t.Fatalf("unexpected number of exprs: got %d, want %d", got, want)
|
t.Fatalf("unexpected number of exprs: got %d, want %d", got, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
dynset, dynsetOk := rules[0].Exprs[2].(*expr.Dynset)
|
dynset, dynsetOk := rules[0].Exprs[1].(*expr.Dynset)
|
||||||
if !dynsetOk {
|
if !dynsetOk {
|
||||||
t.Fatalf("Exprs[3] is type %T, want *expr.Dynset", rules[0].Exprs[2])
|
t.Fatalf("Exprs[0] is type %T, want *expr.Dynset", rules[0].Exprs[1])
|
||||||
}
|
}
|
||||||
if want := (&expr.Dynset{
|
if want := (&expr.Dynset{
|
||||||
SrcRegKey: 1,
|
SrcRegKey: 1,
|
||||||
SrcRegData: 2,
|
|
||||||
SetName: set.Name,
|
SetName: set.Name,
|
||||||
SetID: set.ID,
|
|
||||||
Operation: uint32(unix.NFT_DYNSET_OP_UPDATE),
|
Operation: uint32(unix.NFT_DYNSET_OP_UPDATE),
|
||||||
}); !reflect.DeepEqual(dynset, want) {
|
}); !reflect.DeepEqual(dynset, want) {
|
||||||
t.Errorf("dynset expr = %+v, wanted %+v", dynset, want)
|
t.Errorf("dynset expr = %+v, wanted %+v", dynset, want)
|
||||||
|
|
2
rule.go
2
rule.go
|
@ -240,6 +240,8 @@ func exprsFromMsg(b []byte) ([]expr.Any, error) {
|
||||||
e = &expr.Redir{}
|
e = &expr.Redir{}
|
||||||
case "nat":
|
case "nat":
|
||||||
e = &expr.NAT{}
|
e = &expr.NAT{}
|
||||||
|
case "dynset":
|
||||||
|
e = &expr.Dynset{}
|
||||||
}
|
}
|
||||||
if e == nil {
|
if e == nil {
|
||||||
// TODO: introduce an opaque expression type so that users know
|
// TODO: introduce an opaque expression type so that users know
|
||||||
|
|
Loading…
Reference in New Issue