@@ -3,8 +3,10 @@ package ebpf
33import (
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+
1726type PdrInfo struct {
1827 OuterHeaderRemoval uint8
1928 FarId uint32
@@ -109,12 +118,18 @@ func (bpfObjects *BpfObjects) UpdatePdrDownlink(ipv4 net.IP, pdrInfo PdrInfo) er
109118
110119func (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
115127func (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
120135func (bpfObjects * BpfObjects ) PutDownlinkPdrIp6 (ipv6 net.IP , pdrInfo PdrInfo ) error {
@@ -147,7 +162,10 @@ func (bpfObjects *BpfObjects) UpdateDownlinkPdrIp6(ipv6 net.IP, pdrInfo PdrInfo)
147162
148163func (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
153171type FarInfo struct {
@@ -188,7 +206,10 @@ func (bpfObjects *BpfObjects) UpdateFar(internalId uint32, farInfo FarInfo) erro
188206func (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
194215type QerInfo struct {
@@ -218,7 +239,10 @@ func (bpfObjects *BpfObjects) UpdateQer(internalId uint32, qerInfo QerInfo) erro
218239func (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
258285type 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
279307func CombinePdrWithSdf (defaultPdr * IpEntrypointPdrInfo , sdfPdr PdrInfo ) IpEntrypointPdrInfo {
0 commit comments