From c5a0aed52add2af7cda1f52227e3e35ddd797326 Mon Sep 17 00:00:00 2001 From: Louis Royer Date: Thu, 5 Sep 2024 13:10:58 +0200 Subject: [PATCH] Fix bug with ForwardingParameters --- pfcp/api/far_interface.go | 2 +- pfcp/entity.go | 59 ++++++++++++++++++++++----------------- pfcp/far.go | 11 ++++++-- 3 files changed, 44 insertions(+), 28 deletions(-) diff --git a/pfcp/api/far_interface.go b/pfcp/api/far_interface.go index 471ea8b..bbe8702 100644 --- a/pfcp/api/far_interface.go +++ b/pfcp/api/far_interface.go @@ -12,6 +12,6 @@ type FARID = uint32 type FARInterface interface { ID() (FARID, error) ApplyAction() *ie.IE - ForwardingParameters() *ie.IE + ForwardingParameters() (*ie.IE, error) NewCreateFAR() *ie.IE } diff --git a/pfcp/entity.go b/pfcp/entity.go index 0d79760..38b0004 100644 --- a/pfcp/entity.go +++ b/pfcp/entity.go @@ -397,36 +397,45 @@ func (e *PFCPEntity) LogPFCPRules() { } } - ForwardingParametersIe := far.ForwardingParameters() + isFP := true + ForwardingParametersIe, err := far.ForwardingParameters() + if err != nil { + isFP = false + + } OuterHeaderCreationLabel := "No" - if ohc, err := ForwardingParametersIe.OuterHeaderCreation(); err == nil { - ohcb, _ := ohc.Marshal() - ohcIe := ie.New(ie.OuterHeaderCreation, ohcb) - switch { - case ohcIe.HasTEID() && ohcIe.HasIPv4(): - OuterHeaderCreationLabel = fmt.Sprintf("[%s (%d)]", ohc.IPv4Address.String(), ohc.TEID) - case ohcIe.HasTEID() && ohcIe.HasIPv6(): - OuterHeaderCreationLabel = fmt.Sprintf("[%s (%d)]", ohc.IPv6Address.String(), ohc.TEID) - default: - OuterHeaderCreationLabel = "Other" + if isFP { + if ohc, err := ForwardingParametersIe.OuterHeaderCreation(); err == nil { + ohcb, _ := ohc.Marshal() + ohcIe := ie.New(ie.OuterHeaderCreation, ohcb) + switch { + case ohcIe.HasTEID() && ohcIe.HasIPv4(): + OuterHeaderCreationLabel = fmt.Sprintf("[%s (%d)]", ohc.IPv4Address.String(), ohc.TEID) + case ohcIe.HasTEID() && ohcIe.HasIPv6(): + OuterHeaderCreationLabel = fmt.Sprintf("[%s (%d)]", ohc.IPv6Address.String(), ohc.TEID) + default: + OuterHeaderCreationLabel = "Other" + } } } DestinationInterfaceLabel := "Not defined" - if destination, err := ForwardingParametersIe.DestinationInterface(); err == nil { - switch destination { - case ie.DstInterfaceAccess: - DestinationInterfaceLabel = "Access" - case ie.DstInterfaceCore: - DestinationInterfaceLabel = "Core" - case ie.DstInterfaceSGiLANN6LAN: - DestinationInterfaceLabel = "SGi-LAN/N6-LAN" - case ie.DstInterfaceCPFunction: - DestinationInterfaceLabel = "CP Function" - case ie.DstInterfaceLIFunction: - DestinationInterfaceLabel = "LI Function" - case ie.DstInterface5GVNInternal: - DestinationInterfaceLabel = "5G VN Internal" + if isFP { + if destination, err := ForwardingParametersIe.DestinationInterface(); err == nil { + switch destination { + case ie.DstInterfaceAccess: + DestinationInterfaceLabel = "Access" + case ie.DstInterfaceCore: + DestinationInterfaceLabel = "Core" + case ie.DstInterfaceSGiLANN6LAN: + DestinationInterfaceLabel = "SGi-LAN/N6-LAN" + case ie.DstInterfaceCPFunction: + DestinationInterfaceLabel = "CP Function" + case ie.DstInterfaceLIFunction: + DestinationInterfaceLabel = "LI Function" + case ie.DstInterface5GVNInternal: + DestinationInterfaceLabel = "5G VN Internal" + } } } diff --git a/pfcp/far.go b/pfcp/far.go index 2aa8353..f603774 100644 --- a/pfcp/far.go +++ b/pfcp/far.go @@ -6,6 +6,7 @@ package pfcp_networking import ( + "fmt" "github.com/nextmn/go-pfcp-networking/pfcp/api" "github.com/wmnsk/go-pfcp/ie" ) @@ -32,8 +33,14 @@ func (far *FAR) ApplyAction() *ie.IE { return far.applyAction } -func (far *FAR) ForwardingParameters() *ie.IE { - return far.forwardingParameters +func (far *FAR) ForwardingParameters() (*ie.IE, error) { + // This IE shall be present when the Apply Action requests + // the packets to be forwarded. It may be present otherwise. + if far.ForwardingParameters == nil { + return nil, fmt.Errorf("No forwarding parameters ie") + } + return far.forwardingParameters, nil + } func (far *FAR) NewCreateFAR() *ie.IE {