diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-05-04 18:27:04 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-05-04 18:27:04 +0000 |
commit | 72392231ba7daaa5ce21e78cc251e707cd88437c (patch) | |
tree | 781983bafcda0c54f27355757c87480d435618c3 /pkg/tcpip/stack/stack.go | |
parent | 23c3b58f2d7ade5f9aa1e8c545223941ded690e4 (diff) | |
parent | 711439b1c3560b916dd5ffcbf906452d1ac960b0 (diff) |
Merge release-20200422.0-18-g711439b (automated)
Diffstat (limited to 'pkg/tcpip/stack/stack.go')
-rw-r--r-- | pkg/tcpip/stack/stack.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/pkg/tcpip/stack/stack.go b/pkg/tcpip/stack/stack.go index 4a2dc3dc6..e33fae4eb 100644 --- a/pkg/tcpip/stack/stack.go +++ b/pkg/tcpip/stack/stack.go @@ -1885,3 +1885,22 @@ func generateRandInt64() int64 { } return v } + +// FindNetworkEndpoint returns the network endpoint for the given address. +func (s *Stack) FindNetworkEndpoint(netProto tcpip.NetworkProtocolNumber, address tcpip.Address) (NetworkEndpoint, *tcpip.Error) { + s.mu.Lock() + defer s.mu.Unlock() + + for _, nic := range s.nics { + id := NetworkEndpointID{address} + + if ref, ok := nic.mu.endpoints[id]; ok { + nic.mu.RLock() + defer nic.mu.RUnlock() + + // An endpoint with this id exists, check if it can be used and return it. + return ref.ep, nil + } + } + return nil, tcpip.ErrBadAddress +} |