Skip to content

Commit

Permalink
Fix SRv6 prefix SID unmarshalling
Browse files Browse the repository at this point in the history
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 <rastislav.szabo@isovalent.com>
  • Loading branch information
rastislavs authored and fujita committed Aug 3, 2023
1 parent cc8ee20 commit d3a46b8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/apiutil/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/apiutil/attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d3a46b8

Please sign in to comment.