From 3734c6b05cd0411493288405b6ccaf9011efebc3 Mon Sep 17 00:00:00 2001 From: Florian Lehner Date: Sat, 14 Dec 2024 08:59:04 +0100 Subject: [PATCH] add PCNT and PAD Signed-off-by: Florian Lehner --- f_basic.go | 9 ++++++++- f_basic_test.go | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/f_basic.go b/f_basic.go index 1c6a7b9..baa8754 100644 --- a/f_basic.go +++ b/f_basic.go @@ -13,6 +13,7 @@ const ( tcaBasicAct tcaBasicPolice tcaBasicPCNT + tcaBasicPad ) // Basic contains attributes of the basic discipline @@ -21,6 +22,7 @@ type Basic struct { Police *Police Ematch *Ematch Actions *[]*Action + Pcnt *uint64 } // unmarshalBasic parses the Basic-encoded data and stores the result in the value pointed to by info. @@ -50,7 +52,9 @@ func unmarshalBasic(data []byte, info *Basic) error { multiError = concatError(multiError, err) info.Actions = actions case tcaBasicPCNT: - continue + info.Pcnt = uint64Ptr(ad.Uint64()) + case tcaBasicPad: + // padding does not contain data, we just skip it default: return fmt.Errorf("unmarshalBasic()\t%d\n\t%v", ad.Type(), ad.Bytes()) } @@ -65,6 +69,9 @@ func marshalBasic(info *Basic) ([]byte, error) { if info == nil { return []byte{}, fmt.Errorf("Basic: %w", ErrNoArg) } + if info.Pcnt != nil { + return []byte{}, ErrNoArgAlter + } var multiError error // TODO: improve logic and check combinations diff --git a/f_basic_test.go b/f_basic_test.go index 7af6b2e..0cd043c 100644 --- a/f_basic_test.go +++ b/f_basic_test.go @@ -53,7 +53,7 @@ func TestBasic(t *testing.T) { } t.Fatalf("Unexpected error: %v", err1) } - newData := injectAttribute(t, data, []byte{}, tcaBasicPCNT) + newData := injectAttribute(t, data, []byte{}, tcaBasicPad) val := Basic{} err2 := unmarshalBasic(newData, &val) if err2 != nil { @@ -80,4 +80,10 @@ func TestBasic(t *testing.T) { t.Fatalf("expected error but got nil") } }) + t.Run("pcnt", func(t *testing.T) { + _, err := marshalBasic(&Basic{Pcnt: uint64Ptr(42)}) + if !errors.Is(err, ErrNoArgAlter) { + t.Fatalf("expected '%v' but got '%v'", ErrNoArgAlter, err) + } + }) }