From d3a46b8e1ff1f2cfd5b73535a04a00d455e9b177 Mon Sep 17 00:00:00 2001 From: Rastislav Szabo Date: Fri, 28 Jul 2023 22:05:11 +0200 Subject: [PATCH] Fix SRv6 prefix SID unmarshalling During SRv6 prefix SID unmarshalling, wrong Path Attribute length was applied (4B instead of 3B). This was causing a 1 byte difference in PA length after marshalling & unmarshalling. Signed-off-by: Rastislav Szabo --- pkg/apiutil/attribute.go | 6 +++--- pkg/apiutil/attribute_test.go | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/apiutil/attribute.go b/pkg/apiutil/attribute.go index 9c4e1adf9..6f5d74170 100644 --- a/pkg/apiutil/attribute.go +++ b/pkg/apiutil/attribute.go @@ -2768,8 +2768,8 @@ func UnmarshalPrefixSID(psid *api.PrefixSID) (*bgp.PathAttributePrefixSID, error return nil, fmt.Errorf("unknown or not implemented Prefix SID type: %+v", v) } } - // Final Path Attribute Length is 3 bytes of the header and 1 byte Reserved1 - s.PathAttribute.Length += (3 + 1) + // Final Path Attribute Length is 3 bytes of the Path Attribute header longer + s.PathAttribute.Length += 3 return s, nil } @@ -2813,7 +2813,7 @@ func UnmarshalSubTLVs(stlvs map[uint32]*api.SRv6TLV) (uint16, []bgp.PrefixSIDTLV // SRv6 Information Sub TLV length consists 1 byte Resrved2, 16 bytes SID, 1 byte flags, 2 bytes Endpoint Behavior // 1 byte Reserved3 and length of Sub Sub TLVs info.SubTLV.Length = 1 + 16 + 1 + 2 + 1 + sstlvslength - // For total Srv6 Information Sub TLV length, adding 3 bytes of the Sub TLV header + // For total Prefix SID TLV length, adding 3 bytes of the TLV header + 1 byte of Reserved1 l += info.SubTLV.Length + 4 p = append(p, info) } diff --git a/pkg/apiutil/attribute_test.go b/pkg/apiutil/attribute_test.go index e2bf05700..e7b45945a 100644 --- a/pkg/apiutil/attribute_test.go +++ b/pkg/apiutil/attribute_test.go @@ -1849,6 +1849,9 @@ func TestFullCyclePrefixSID(t *testing.T) { if err != nil { t.Fatalf("test failed with error: %+v", err) } + if recoveredPrefixSID.Len() != attribute.Len() { + t.Fatalf("recovered attribute length (%d) is not matching original attribute length (%d)", recoveredPrefixSID.Len(), attribute.Len()) + } recovered, err := recoveredPrefixSID.Serialize() if err != nil { t.Fatalf("test failed with error: %+v", err)