Correctly lock when listing neighbor entries

PiperOrigin-RevId: 345162450
This commit is contained in:
Ghanan Gowripalan
2020-12-01 21:34:52 -08:00
committed by gVisor bot
parent 93d29719cc
commit 0c49739422
+3 -2
View File
@@ -182,14 +182,15 @@ func (n *neighborCache) removeWaker(addr tcpip.Address, waker *sleep.Waker) {
// entries returns all entries in the neighbor cache.
func (n *neighborCache) entries() []NeighborEntry {
entries := make([]NeighborEntry, 0, len(n.cache))
n.mu.RLock()
defer n.mu.RUnlock()
entries := make([]NeighborEntry, 0, len(n.cache))
for _, entry := range n.cache {
entry.mu.RLock()
entries = append(entries, entry.neigh)
entry.mu.RUnlock()
}
n.mu.RUnlock()
return entries
}