From 528c4940250739629573975239014aab276a8163 Mon Sep 17 00:00:00 2001 From: severindellsperger Date: Thu, 20 Jun 2024 17:06:26 +0200 Subject: [PATCH] add nil check to avoid panic --- pkg/helpers/helpers.go | 19 ++++++++++++++++++- pkg/requestservice/topology.go | 6 ++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pkg/helpers/helpers.go b/pkg/helpers/helpers.go index 90190771..5c91fbc9 100644 --- a/pkg/helpers/helpers.go +++ b/pkg/helpers/helpers.go @@ -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)), @@ -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)), @@ -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)), @@ -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), diff --git a/pkg/requestservice/topology.go b/pkg/requestservice/topology.go index ea151167..248853d0 100644 --- a/pkg/requestservice/topology.go +++ b/pkg/requestservice/topology.go @@ -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: