summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/stack/stack.go
diff options
context:
space:
mode:
authorGhanan Gowripalan <ghanan@google.com>2021-01-19 16:54:48 -0800
committergVisor bot <gvisor-bot@google.com>2021-01-19 16:56:49 -0800
commit7ff5ceaeae66303ed6a2199963c00cb08b2fe7ca (patch)
tree5b2ab07f55394c2106a4cbd71046cc069b681f23 /pkg/tcpip/stack/stack.go
parent48ea2c34d1d3dead7727d9e2760b587c7609b14b (diff)
Do not have a stack-wide linkAddressCache
Link addresses are cached on a per NIC basis so instead of having a single cache that includes the NIC ID for neighbor entry lookups, use a single cache per NIC. PiperOrigin-RevId: 352684111
Diffstat (limited to 'pkg/tcpip/stack/stack.go')
-rw-r--r--pkg/tcpip/stack/stack.go21
1 files changed, 12 insertions, 9 deletions
diff --git a/pkg/tcpip/stack/stack.go b/pkg/tcpip/stack/stack.go
index b4878669c..4685fa4cf 100644
--- a/pkg/tcpip/stack/stack.go
+++ b/pkg/tcpip/stack/stack.go
@@ -382,8 +382,6 @@ type Stack struct {
stats tcpip.Stats
- linkAddrCache *linkAddrCache
-
mu sync.RWMutex
nics map[tcpip.NICID]*NIC
@@ -636,7 +634,6 @@ func New(opts Options) *Stack {
linkAddrResolvers: make(map[tcpip.NetworkProtocolNumber]LinkAddressResolver),
nics: make(map[tcpip.NICID]*NIC),
cleanupEndpoints: make(map[TransportEndpoint]struct{}),
- linkAddrCache: newLinkAddrCache(ageLimit, resolutionTimeout, resolutionAttempts),
PortManager: ports.NewPortManager(),
clock: clock,
stats: opts.Stats.FillIn(),
@@ -1516,12 +1513,18 @@ func (s *Stack) SetSpoofing(nicID tcpip.NICID, enable bool) *tcpip.Error {
return nil
}
-// AddLinkAddress adds a link address to the stack link cache.
-func (s *Stack) AddLinkAddress(nicID tcpip.NICID, addr tcpip.Address, linkAddr tcpip.LinkAddress) {
- fullAddr := tcpip.FullAddress{NIC: nicID, Addr: addr}
- s.linkAddrCache.add(fullAddr, linkAddr)
- // TODO: provide a way for a transport endpoint to receive a signal
- // that AddLinkAddress for a particular address has been called.
+// AddLinkAddress adds a link address for the neighbor on the specified NIC.
+func (s *Stack) AddLinkAddress(nicID tcpip.NICID, neighbor tcpip.Address, linkAddr tcpip.LinkAddress) *tcpip.Error {
+ s.mu.RLock()
+ defer s.mu.RUnlock()
+
+ nic, ok := s.nics[nicID]
+ if !ok {
+ return tcpip.ErrUnknownNICID
+ }
+
+ nic.linkAddrCache.AddLinkAddress(neighbor, linkAddr)
+ return nil
}
// GetLinkAddress finds the link address corresponding to a neighbor's address.