diff --git a/cmd/core/pdr_creation_context.go b/cmd/core/pdr_creation_context.go index 33e44c76..f646e23f 100644 --- a/cmd/core/pdr_creation_context.go +++ b/cmd/core/pdr_creation_context.go @@ -100,36 +100,45 @@ func (pdrContext *PDRCreationContext) extractPDR(pdr *ie.IE, spdrInfo *SPDRInfo) } } - if teidPdiId := findIEindex(pdi, 21); teidPdiId != -1 { // IE Type F-TEID - if fteid, err := pdi[teidPdiId].FTEID(); err == nil { - var teid = fteid.TEID - if fteid.HasCh() { - var allocate = true - if fteid.HasChID() { - if teidFromCache, ok := pdrContext.hasTEIDCache(fteid.ChooseID); ok { - allocate = false - teid = teidFromCache - spdrInfo.Allocated = true - } - } - if allocate { - allocatedTeid, err := pdrContext.getFTEID(pdrContext.Session.RemoteSEID, spdrInfo.PdrID) - if err != nil { - log.Error().Msgf("AllocateTEID err: %v", err) - return fmt.Errorf("can't allocate TEID: %s", causeToString(ie.CauseNoResourcesAvailable)) - } - teid = allocatedTeid + if teidPdiId := findIEindex(pdi, ie.FTEID); teidPdiId != -1 { + fteid, err := pdi[teidPdiId].FTEID() + if err != nil { + return fmt.Errorf("F-TEID IE is missing") + } + + var teid = fteid.TEID + if fteid.HasCh() { + var allocate = true + if fteid.HasChID() { + if teidFromCache, ok := pdrContext.hasTEIDCache(fteid.ChooseID); ok { + allocate = false + teid = teidFromCache spdrInfo.Allocated = true - if fteid.HasChID() { - pdrContext.setTEIDCache(fteid.ChooseID, teid) - } } } - spdrInfo.Teid = teid - return nil + if allocate { + allocatedTeid, err := pdrContext.getFTEID(pdrContext.Session.RemoteSEID, spdrInfo.PdrID) + if err != nil { + log.Error().Msgf("AllocateTEID err: %v", err) + return fmt.Errorf("can't allocate TEID: %s", causeToString(ie.CauseNoResourcesAvailable)) + } + teid = allocatedTeid + spdrInfo.Allocated = true + if fteid.HasChID() { + pdrContext.setTEIDCache(fteid.ChooseID, teid) + } + } } - return fmt.Errorf("F-TEID IE is missing") - } else if ueIP, err := pdr.UEIPAddress(); err == nil { + spdrInfo.Teid = teid + return nil + } + + if ueipPdiId := findIEindex(pdi, ie.UEIPAddress); ueipPdiId != -1 { + ueIP, err := pdi[ueipPdiId].UEIPAddress() + if err != nil { + return fmt.Errorf("UE IP Address IE is missing") + } + if config.Conf.FeatureUEIP && hasCHV4(ueIP.Flags) { if ip, err := pdrContext.getIP(); err == nil { ueIP.IPv4Address = cloneIP(ip) @@ -147,10 +156,10 @@ func (pdrContext *PDRCreationContext) extractPDR(pdr *ie.IE, spdrInfo *SPDRInfo) } return nil - } else { - log.Info().Msg("Both F-TEID IE and UE IP Address IE are missing") - return err } + + log.Info().Msg("Both F-TEID IE and UE IP Address IE are missing") + return err } func (pdrContext *PDRCreationContext) deletePDR(spdrInfo SPDRInfo, mapOperations ebpf.ForwardingPlaneController) error { diff --git a/cmd/core/pdr_creation_context_test.go b/cmd/core/pdr_creation_context_test.go index 6b995da3..78d56c5e 100644 --- a/cmd/core/pdr_creation_context_test.go +++ b/cmd/core/pdr_creation_context_test.go @@ -103,6 +103,23 @@ func TestPDRCreationContext_extractPDR(t *testing.T) { }, wantErr: false, }, + { + name: "UpdatePDR with UEIPAddress", + fields: fields{}, + args: args{ + pdr: ie.NewUpdatePDR( + ie.NewPDRID(2), + ie.NewPrecedence(255), + ie.NewPDI( + ie.NewSourceInterface(ie.SrcInterfaceCore), + ie.NewNetworkInstance("a00"), + ie.NewUEIPAddress(0x06, "10.128.0.1", "", 0, 0), + ), + ), + spdrInfo: &SPDRInfo{}, + }, + wantErr: false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {