Skip to content

Commit bc686b3

Browse files
fix(core): always send PFCP responses; treat datapath delete ENOENT as success (#650)
Signed-off-by: frank <[email protected]>
1 parent 48f257e commit bc686b3

4 files changed

Lines changed: 67 additions & 21 deletions

File tree

‎cmd/core/ie_overwrite_test.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,14 @@ func (mapOps *MapOperationsMock) UpdateUrr(internalId uint32, urrInfo ebpf.UrrIn
6969
return nil
7070
}
7171

72-
func (mapOps *MapOperationsMock) DeleteUrr(internalId uint32) (ebpf.UrrInfo, error) {
72+
func (mapOps *MapOperationsMock) ReadUrr(internalId uint32) (ebpf.UrrInfo, error) {
7373
return mapOps.urr, nil
7474
}
7575

76+
func (mapOps *MapOperationsMock) DeleteUrr(internalId uint32) error {
77+
return nil
78+
}
79+
7680
func TestSessionOverwrite(t *testing.T) {
7781

7882
mapOps := MapOperationsMock{}

‎cmd/core/pfcp_handlers.go‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,25 @@ func (handlerMap PfcpHandlerMap) Handle(conn *PfcpConnection, buf []byte, addr *
2626
startTime := time.Now()
2727
// TODO: Trim port as a workaround for NAT changing the port. Explore proper solutions.
2828
stringIpAddr := addr.IP.String()
29-
outgoingMsg, err := handler(conn, incomingMsg, stringIpAddr)
30-
if err != nil {
31-
log.Warn().Msgf("Error handling PFCP message: %s", err.Error())
32-
return err
29+
outgoingMsg, handlerErr := handler(conn, incomingMsg, stringIpAddr)
30+
if handlerErr != nil {
31+
log.Warn().Msgf("Error handling PFCP message: %s", handlerErr.Error())
3332
}
3433
duration := time.Since(startTime)
3534
UpfMessageRxLatency.WithLabelValues(incomingMsg.MessageTypeName()).Observe(float64(duration.Microseconds()))
3635
// Now assumption that all handlers will return a message to send is not true.
36+
// Always transmit the handler's response when non-nil, even if the handler
37+
// reported an error: the response may carry the error cause the peer awaits.
3738
if outgoingMsg != nil {
3839
PfcpMessageTx.WithLabelValues(outgoingMsg.MessageTypeName()).Inc()
39-
return conn.SendMessage(outgoingMsg, addr)
40+
if sendErr := conn.SendMessage(outgoingMsg, addr); sendErr != nil {
41+
log.Warn().Msgf("Failed to send PFCP response: %s", sendErr.Error())
42+
if handlerErr == nil {
43+
return sendErr
44+
}
45+
}
4046
}
41-
return nil
47+
return handlerErr
4248
} else {
4349
log.Warn().Msgf("Got unexpected message %s: %s, from: %s", incomingMsg.MessageTypeName(), incomingMsg, addr)
4450
}

‎cmd/core/pfcp_session_handlers.go‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,12 @@ func HandlePfcpSessionDeletionRequest(conn *PfcpConnection, msg message.Message,
184184
}
185185
}
186186
for id, urr := range session.URRs {
187-
urrInfo, err := mapOperations.DeleteUrr(urr.GlobalId)
187+
urrInfo, err := mapOperations.ReadUrr(urr.GlobalId)
188188
if err != nil {
189+
log.Error().Msgf("WARN: mapOperations failed to read URR: %d, %s", id, err.Error())
190+
continue
191+
}
192+
if err := mapOperations.DeleteUrr(urr.GlobalId); err != nil {
189193
log.Error().Msgf("WARN: mapOperations failed to delete URR: %d, %s", id, err.Error())
190194
continue
191195
}
@@ -387,8 +391,12 @@ func HandlePfcpSessionModificationRequest(conn *PfcpConnection, msg message.Mess
387391
log.Info().Msgf("Removing URR ID: %d", urrId)
388392
sUrrInfo := session.RemoveUrr(urrId)
389393

390-
urrInfo, err := mapOperations.DeleteUrr(sUrrInfo.GlobalId)
394+
urrInfo, err := mapOperations.ReadUrr(sUrrInfo.GlobalId)
391395
if err != nil {
396+
log.Error().Err(err).Msg("Can't read URR")
397+
return err
398+
}
399+
if err := mapOperations.DeleteUrr(sUrrInfo.GlobalId); err != nil {
392400
log.Error().Err(err).Msg("Can't remove URR")
393401
return err
394402
}

‎cmd/ebpf/pdr.go‎

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package ebpf
33
import (
44
"encoding/binary"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"net"
9+
"syscall"
810
"unsafe"
911

1012
"github.com/cilium/ebpf"
@@ -14,6 +16,13 @@ import (
1416

1517
// The BPF_ARRAY map type has no delete operation. The only way to delete an element is to replace it with a new one.
1618

19+
// isKeyAbsent reports whether an eBPF map operation failed because the key
20+
// does not exist. Delete operations treat that as success: the desired end
21+
// state — the entry being absent — is already achieved.
22+
func isKeyAbsent(err error) bool {
23+
return err != nil && (errors.Is(err, ebpf.ErrKeyNotExist) || errors.Is(err, syscall.ENOENT))
24+
}
25+
1726
type PdrInfo struct {
1827
OuterHeaderRemoval uint8
1928
FarId uint32
@@ -109,12 +118,18 @@ func (bpfObjects *BpfObjects) UpdatePdrDownlink(ipv4 net.IP, pdrInfo PdrInfo) er
109118

110119
func (bpfObjects *BpfObjects) DeletePdrUplink(teid uint32) error {
111120
log.Debug().Msgf("EBPF: Delete PDR Uplink: teid=%d", teid)
112-
return bpfObjects.PdrMapTeidIp4.Delete(teid)
121+
if err := bpfObjects.PdrMapTeidIp4.Delete(teid); err != nil && !isKeyAbsent(err) {
122+
return err
123+
}
124+
return nil
113125
}
114126

115127
func (bpfObjects *BpfObjects) DeletePdrDownlink(ipv4 net.IP) error {
116128
log.Debug().Msgf("EBPF: Delete PDR Downlink: ipv4=%s", ipv4)
117-
return bpfObjects.PdrMapDownlinkIp4.Delete(ipv4)
129+
if err := bpfObjects.PdrMapDownlinkIp4.Delete(ipv4); err != nil && !isKeyAbsent(err) {
130+
return err
131+
}
132+
return nil
118133
}
119134

120135
func (bpfObjects *BpfObjects) PutDownlinkPdrIp6(ipv6 net.IP, pdrInfo PdrInfo) error {
@@ -147,7 +162,10 @@ func (bpfObjects *BpfObjects) UpdateDownlinkPdrIp6(ipv6 net.IP, pdrInfo PdrInfo)
147162

148163
func (bpfObjects *BpfObjects) DeleteDownlinkPdrIp6(ipv6 net.IP) error {
149164
log.Debug().Msgf("EBPF: Delete PDR Ipv6 Downlink: ipv6=%s", ipv6)
150-
return bpfObjects.PdrMapDownlinkIp6.Delete(ipv6)
165+
if err := bpfObjects.PdrMapDownlinkIp6.Delete(ipv6); err != nil && !isKeyAbsent(err) {
166+
return err
167+
}
168+
return nil
151169
}
152170

153171
type FarInfo struct {
@@ -188,7 +206,10 @@ func (bpfObjects *BpfObjects) UpdateFar(internalId uint32, farInfo FarInfo) erro
188206
func (bpfObjects *BpfObjects) DeleteFar(intenalId uint32) error {
189207
log.Debug().Msgf("EBPF: Delete FAR: intenalId=%d", intenalId)
190208
bpfObjects.ReleaseFAR(intenalId)
191-
return bpfObjects.FarMap.Update(intenalId, unsafe.Pointer(&FarInfo{}), ebpf.UpdateExist)
209+
if err := bpfObjects.FarMap.Update(intenalId, unsafe.Pointer(&FarInfo{}), ebpf.UpdateExist); err != nil && !isKeyAbsent(err) {
210+
return err
211+
}
212+
return nil
192213
}
193214

194215
type QerInfo struct {
@@ -218,7 +239,10 @@ func (bpfObjects *BpfObjects) UpdateQer(internalId uint32, qerInfo QerInfo) erro
218239
func (bpfObjects *BpfObjects) DeleteQer(internalId uint32) error {
219240
log.Debug().Msgf("EBPF: Delete QER: internalId=%d", internalId)
220241
bpfObjects.ReleaseQER(internalId)
221-
return bpfObjects.QerMap.Update(internalId, unsafe.Pointer(&QerInfo{}), ebpf.UpdateExist)
242+
if err := bpfObjects.QerMap.Update(internalId, unsafe.Pointer(&QerInfo{}), ebpf.UpdateExist); err != nil && !isKeyAbsent(err) {
243+
return err
244+
}
245+
return nil
222246
}
223247

224248
// TODO: add required fields and implement methods
@@ -241,18 +265,21 @@ func (bpfObjects *BpfObjects) UpdateUrr(internalId uint32, urrInfo UrrInfo) erro
241265
return bpfObjects.UrrMap.Update(internalId, unsafe.Pointer(&urrInfo), ebpf.UpdateExist)
242266
}
243267

244-
func (bpfObjects *BpfObjects) DeleteUrr(internalId uint32) (UrrInfo, error) {
245-
log.Debug().Msgf("EBPF: Delete URR: internalId=%d", internalId)
268+
func (bpfObjects *BpfObjects) ReadUrr(internalId uint32) (UrrInfo, error) {
246269
urrInfo := UrrInfo{}
247270
if err := bpfObjects.UrrMap.Lookup(internalId, unsafe.Pointer(&urrInfo)); err != nil {
248271
return UrrInfo{}, err
249272
}
273+
return urrInfo, nil
274+
}
275+
276+
func (bpfObjects *BpfObjects) DeleteUrr(internalId uint32) error {
277+
log.Debug().Msgf("EBPF: Delete URR: internalId=%d", internalId)
250278
bpfObjects.ReleaseURR(internalId)
251-
if err := bpfObjects.UrrMap.Update(internalId, unsafe.Pointer(&UrrInfo{}), ebpf.UpdateExist); err != nil {
252-
return UrrInfo{}, err
279+
if err := bpfObjects.UrrMap.Update(internalId, unsafe.Pointer(&UrrInfo{}), ebpf.UpdateExist); err != nil && !isKeyAbsent(err) {
280+
return err
253281
}
254-
255-
return urrInfo, nil
282+
return nil
256283
}
257284

258285
type ForwardingPlaneController interface {
@@ -273,7 +300,8 @@ type ForwardingPlaneController interface {
273300
DeleteQer(internalId uint32) error
274301
NewUrr(urrInfo UrrInfo) (uint32, error)
275302
UpdateUrr(internalId uint32, urrInfo UrrInfo) error
276-
DeleteUrr(internalId uint32) (UrrInfo, error)
303+
ReadUrr(internalId uint32) (UrrInfo, error)
304+
DeleteUrr(internalId uint32) error
277305
}
278306

279307
func CombinePdrWithSdf(defaultPdr *IpEntrypointPdrInfo, sdfPdr PdrInfo) IpEntrypointPdrInfo {

0 commit comments

Comments
 (0)