Skip to content

Commit 8075689

Browse files
committed
libn/d/overlay: inline secMapWalk into only caller
func (*driver) secMapWalk is a curious beast. It is named walk, yet it also mutates the collection being iterated over. It returns an error, but that error is always nil. It takes a callback that can break iteration, yet the only caller makes no use of that affordance. Its utility is limited and the abstraction hinders readability more than it helps. Open-code the d.secMap.nodes loop into func (*driver) updateKeys(), the only caller. Signed-off-by: Cory Snider <[email protected]> (cherry picked from commit a1d2997) Signed-off-by: Cory Snider <[email protected]>
1 parent 480dfae commit 8075689

1 file changed

Lines changed: 8 additions & 18 deletions

File tree

libnetwork/drivers/overlay/encryption.go

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -450,21 +450,6 @@ func buildAeadAlgo(k *key, s int) *netlink.XfrmStateAlgo {
450450
}
451451
}
452452

453-
func (d *driver) secMapWalk(f func(netip.Addr, []spi) ([]spi, bool)) error {
454-
d.secMap.mu.Lock()
455-
for rIP, node := range d.secMap.nodes {
456-
idxs, stop := f(rIP, node.spi)
457-
if idxs != nil {
458-
d.secMap.nodes[rIP] = encrNode{idxs, node.count}
459-
}
460-
if stop {
461-
break
462-
}
463-
}
464-
d.secMap.mu.Unlock()
465-
return nil
466-
}
467-
468453
func (d *driver) setKeys(keys []*key) error {
469454
// Remove any stale policy, state
470455
clearEncryptionStates()
@@ -520,9 +505,14 @@ func (d *driver) updateKeys(newKey, primary, pruneKey *key) error {
520505
return types.InvalidParameterErrorf("attempting to both make a key (index %d) primary and delete it", priIdx)
521506
}
522507

523-
d.secMapWalk(func(rIP netip.Addr, spis []spi) ([]spi, bool) {
524-
return updateNodeKey(lIP.AsSlice(), aIP.AsSlice(), rIP.AsSlice(), spis, d.keys, newIdx, priIdx, delIdx), false
525-
})
508+
d.secMap.mu.Lock()
509+
for rIP, node := range d.secMap.nodes {
510+
idxs := updateNodeKey(lIP.AsSlice(), aIP.AsSlice(), rIP.AsSlice(), node.spi, d.keys, newIdx, priIdx, delIdx)
511+
if idxs != nil {
512+
d.secMap.nodes[rIP] = encrNode{idxs, node.count}
513+
}
514+
}
515+
d.secMap.mu.Unlock()
526516

527517
// swap primary
528518
if priIdx != -1 {

0 commit comments

Comments
 (0)