mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
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 <csnider@mirantis.com>
This commit is contained in:
@@ -451,21 +451,6 @@ func buildAeadAlgo(k *key, s int) *netlink.XfrmStateAlgo {
|
||||
}
|
||||
}
|
||||
|
||||
func (d *driver) secMapWalk(f func(netip.Addr, []spi) ([]spi, bool)) error {
|
||||
d.secMap.mu.Lock()
|
||||
for rIP, node := range d.secMap.nodes {
|
||||
idxs, stop := f(rIP, node.spi)
|
||||
if idxs != nil {
|
||||
d.secMap.nodes[rIP] = encrNode{idxs, node.count}
|
||||
}
|
||||
if stop {
|
||||
break
|
||||
}
|
||||
}
|
||||
d.secMap.mu.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *driver) setKeys(keys []*key) error {
|
||||
// Remove any stale policy, state
|
||||
clearEncryptionStates()
|
||||
@@ -521,9 +506,14 @@ func (d *driver) updateKeys(newKey, primary, pruneKey *key) error {
|
||||
return types.InvalidParameterErrorf("attempting to both make a key (index %d) primary and delete it", priIdx)
|
||||
}
|
||||
|
||||
d.secMapWalk(func(rIP netip.Addr, spis []spi) ([]spi, bool) {
|
||||
return updateNodeKey(lIP.AsSlice(), aIP.AsSlice(), rIP.AsSlice(), spis, d.keys, newIdx, priIdx, delIdx), false
|
||||
})
|
||||
d.secMap.mu.Lock()
|
||||
for rIP, node := range d.secMap.nodes {
|
||||
idxs := updateNodeKey(lIP.AsSlice(), aIP.AsSlice(), rIP.AsSlice(), node.spi, d.keys, newIdx, priIdx, delIdx)
|
||||
if idxs != nil {
|
||||
d.secMap.nodes[rIP] = encrNode{idxs, node.count}
|
||||
}
|
||||
}
|
||||
d.secMap.mu.Unlock()
|
||||
|
||||
// swap primary
|
||||
if priIdx != -1 {
|
||||
|
||||
Reference in New Issue
Block a user