diff options
author | Andrei Vagin <avagin@google.com> | 2019-12-03 16:30:38 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2019-12-03 16:32:13 -0800 |
commit | cf7f27c16793eaa41743e96488dad2ddfd1f5d59 (patch) | |
tree | 0cc90510ef025577b9a9e806e3892f8e9c68e23c /pkg | |
parent | 035407153989b189a3ce42df43d6f528fa95444f (diff) |
net/udp: return a local route address as the bound-to address
If the socket is bound to ANY and connected to a loopback address,
getsockname() has to return the loopback address. Without this fix,
getsockname() returns ANY.
PiperOrigin-RevId: 283647781
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/tcpip/transport/udp/endpoint.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/pkg/tcpip/transport/udp/endpoint.go b/pkg/tcpip/transport/udp/endpoint.go index 24cb88c13..4b161e404 100644 --- a/pkg/tcpip/transport/udp/endpoint.go +++ b/pkg/tcpip/transport/udp/endpoint.go @@ -1134,9 +1134,14 @@ func (e *endpoint) GetLocalAddress() (tcpip.FullAddress, *tcpip.Error) { e.mu.RLock() defer e.mu.RUnlock() + addr := e.ID.LocalAddress + if e.state == StateConnected { + addr = e.route.LocalAddress + } + return tcpip.FullAddress{ NIC: e.RegisterNICID, - Addr: e.ID.LocalAddress, + Addr: addr, Port: e.ID.LocalPort, }, nil } |