Skip to content

Commit

Permalink
add nil check to avoid panic
Browse files Browse the repository at this point in the history
  • Loading branch information
severindellsperger committed Jun 20, 2024
1 parent 4175f43 commit 528c494
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
19 changes: 18 additions & 1 deletion pkg/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,18 @@ func ConvertSrv6EndXSid(srv6EndXSID []*srv6.EndXSIDTLV) []*jagw.Srv6EndXSidTlv {
}

func convertLocatorFlags(flags *srv6.LocatorFlags) *jagw.Srv6LocatorFlags {
if flags == nil {
return nil
}
return &jagw.Srv6LocatorFlags{
DFlag: proto.Bool(flags.DFlag),
}
}

func ConvertSrv6Locator(srv6Locator *srv6.LocatorTLV) *jagw.Srv6LocatorTlv {
if srv6Locator == nil {
return nil
}
return &jagw.Srv6LocatorTlv{
Flags: convertLocatorFlags(srv6Locator.Flag),
Algo: proto.Uint32(uint32(srv6Locator.Algorithm)),
Expand All @@ -114,6 +120,9 @@ func ConvertSrv6Locator(srv6Locator *srv6.LocatorTLV) *jagw.Srv6LocatorTlv {
}

func ConvertSrv6EndpointBehavior(srv6EndpointBehavior *srv6.EndpointBehavior) *jagw.Srv6EndpointBehavior {
if srv6EndpointBehavior == nil {
return nil
}
return &jagw.Srv6EndpointBehavior{
EndpointBehavior: proto.Uint32(uint32(srv6EndpointBehavior.EndpointBehavior)),
Flag: proto.Uint32(uint32(srv6EndpointBehavior.Flag)),
Expand All @@ -122,6 +131,9 @@ func ConvertSrv6EndpointBehavior(srv6EndpointBehavior *srv6.EndpointBehavior) *j
}

func ConvertSrv6SidStructure(srv6SidStructure *srv6.SIDStructure) *jagw.Srv6SidStructure {
if srv6SidStructure == nil {
return nil
}
return &jagw.Srv6SidStructure{
Type: proto.Uint32(uint32(srv6SidStructure.Type)),
Length: proto.Uint32(uint32(srv6SidStructure.Length)),
Expand All @@ -135,12 +147,17 @@ func ConvertSrv6SidStructure(srv6SidStructure *srv6.SIDStructure) *jagw.Srv6SidS
func ConvertMtidSlice(documents []*base.MultiTopologyIdentifier) []*jagw.MultiTopologyIdentifier {
mtids := make([]*jagw.MultiTopologyIdentifier, len(documents))
for index, doc := range documents {
mtids[index] = ConvertMtid(doc)
if doc != nil {
mtids[index] = ConvertMtid(doc)
}
}
return mtids
}

func ConvertMtid(doc *base.MultiTopologyIdentifier) *jagw.MultiTopologyIdentifier {
if doc == nil {
return nil
}
return &jagw.MultiTopologyIdentifier{
OFlag: proto.Bool(doc.OFlag),
AFlag: proto.Bool(doc.AFlag),
Expand Down
6 changes: 6 additions & 0 deletions pkg/requestservice/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ func convertLsSrv6Sid(doc interface{}, properties []string) *jagw.LsSrv6Sid {
lsSRv6SID.IgpFlags = proto.Uint32(uint32(document.IGPFlags))
case property.Srv6Sid:
lsSRv6SID.Srv6Sid = proto.String(document.SRv6SID)
case property.Rev:
lsSRv6SID.Rev = proto.String(document.Rev)
case property.PeerType:
lsSRv6SID.PeerType = proto.Uint32(uint32(document.PeerType))
case property.ProtocolId:
lsSRv6SID.ProtocolId = proto.Uint32(uint32(document.ProtocolID))
case property.Srv6EndpointBehavior:
lsSRv6SID.Srv6EndpointBehavior = helpers.ConvertSrv6EndpointBehavior(document.SRv6EndpointBehavior)
case property.Srv6SidStructure:
Expand Down

0 comments on commit 528c494

Please sign in to comment.