Skip to content

Commit a1b6f6a

Browse files
yoursunnypirog-spb
andauthored
feat: recognize UEIPAddress in UpdatePDR (#591)
Co-authored-by: Alex Rozhkevich <[email protected]>
1 parent 43021b6 commit a1b6f6a

2 files changed

Lines changed: 55 additions & 29 deletions

File tree

‎cmd/core/pdr_creation_context.go‎

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -100,36 +100,45 @@ func (pdrContext *PDRCreationContext) extractPDR(pdr *ie.IE, spdrInfo *SPDRInfo)
100100
}
101101
}
102102

103-
if teidPdiId := findIEindex(pdi, 21); teidPdiId != -1 { // IE Type F-TEID
104-
if fteid, err := pdi[teidPdiId].FTEID(); err == nil {
105-
var teid = fteid.TEID
106-
if fteid.HasCh() {
107-
var allocate = true
108-
if fteid.HasChID() {
109-
if teidFromCache, ok := pdrContext.hasTEIDCache(fteid.ChooseID); ok {
110-
allocate = false
111-
teid = teidFromCache
112-
spdrInfo.Allocated = true
113-
}
114-
}
115-
if allocate {
116-
allocatedTeid, err := pdrContext.getFTEID(pdrContext.Session.RemoteSEID, spdrInfo.PdrID)
117-
if err != nil {
118-
log.Error().Msgf("AllocateTEID err: %v", err)
119-
return fmt.Errorf("can't allocate TEID: %s", causeToString(ie.CauseNoResourcesAvailable))
120-
}
121-
teid = allocatedTeid
103+
if teidPdiId := findIEindex(pdi, ie.FTEID); teidPdiId != -1 {
104+
fteid, err := pdi[teidPdiId].FTEID()
105+
if err != nil {
106+
return fmt.Errorf("F-TEID IE is missing")
107+
}
108+
109+
var teid = fteid.TEID
110+
if fteid.HasCh() {
111+
var allocate = true
112+
if fteid.HasChID() {
113+
if teidFromCache, ok := pdrContext.hasTEIDCache(fteid.ChooseID); ok {
114+
allocate = false
115+
teid = teidFromCache
122116
spdrInfo.Allocated = true
123-
if fteid.HasChID() {
124-
pdrContext.setTEIDCache(fteid.ChooseID, teid)
125-
}
126117
}
127118
}
128-
spdrInfo.Teid = teid
129-
return nil
119+
if allocate {
120+
allocatedTeid, err := pdrContext.getFTEID(pdrContext.Session.RemoteSEID, spdrInfo.PdrID)
121+
if err != nil {
122+
log.Error().Msgf("AllocateTEID err: %v", err)
123+
return fmt.Errorf("can't allocate TEID: %s", causeToString(ie.CauseNoResourcesAvailable))
124+
}
125+
teid = allocatedTeid
126+
spdrInfo.Allocated = true
127+
if fteid.HasChID() {
128+
pdrContext.setTEIDCache(fteid.ChooseID, teid)
129+
}
130+
}
130131
}
131-
return fmt.Errorf("F-TEID IE is missing")
132-
} else if ueIP, err := pdr.UEIPAddress(); err == nil {
132+
spdrInfo.Teid = teid
133+
return nil
134+
}
135+
136+
if ueipPdiId := findIEindex(pdi, ie.UEIPAddress); ueipPdiId != -1 {
137+
ueIP, err := pdi[ueipPdiId].UEIPAddress()
138+
if err != nil {
139+
return fmt.Errorf("UE IP Address IE is missing")
140+
}
141+
133142
if config.Conf.FeatureUEIP && hasCHV4(ueIP.Flags) {
134143
if ip, err := pdrContext.getIP(); err == nil {
135144
ueIP.IPv4Address = cloneIP(ip)
@@ -147,10 +156,10 @@ func (pdrContext *PDRCreationContext) extractPDR(pdr *ie.IE, spdrInfo *SPDRInfo)
147156
}
148157

149158
return nil
150-
} else {
151-
log.Info().Msg("Both F-TEID IE and UE IP Address IE are missing")
152-
return err
153159
}
160+
161+
log.Info().Msg("Both F-TEID IE and UE IP Address IE are missing")
162+
return err
154163
}
155164

156165
func (pdrContext *PDRCreationContext) deletePDR(spdrInfo SPDRInfo, mapOperations ebpf.ForwardingPlaneController) error {

‎cmd/core/pdr_creation_context_test.go‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,23 @@ func TestPDRCreationContext_extractPDR(t *testing.T) {
103103
},
104104
wantErr: false,
105105
},
106+
{
107+
name: "UpdatePDR with UEIPAddress",
108+
fields: fields{},
109+
args: args{
110+
pdr: ie.NewUpdatePDR(
111+
ie.NewPDRID(2),
112+
ie.NewPrecedence(255),
113+
ie.NewPDI(
114+
ie.NewSourceInterface(ie.SrcInterfaceCore),
115+
ie.NewNetworkInstance("a00"),
116+
ie.NewUEIPAddress(0x06, "10.128.0.1", "", 0, 0),
117+
),
118+
),
119+
spdrInfo: &SPDRInfo{},
120+
},
121+
wantErr: false,
122+
},
106123
}
107124
for _, tt := range tests {
108125
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)