diff options
author | Ghanan Gowripalan <ghanan@google.com> | 2021-07-20 22:47:34 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-07-20 22:50:16 -0700 |
commit | 9e805ce937ef2f2934e72f873ea4ae8451801c82 (patch) | |
tree | b7f664411089449a91f0b874fa725c671b97f73d /pkg/tcpip/transport | |
parent | 0184f1a662b893a1634e9b2cf3adff57971b668c (diff) |
Expose local address from raw sockets
PiperOrigin-RevId: 385940836
Diffstat (limited to 'pkg/tcpip/transport')
-rw-r--r-- | pkg/tcpip/transport/raw/endpoint.go | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/pkg/tcpip/transport/raw/endpoint.go b/pkg/tcpip/transport/raw/endpoint.go index ab5da987a..b3d8951ff 100644 --- a/pkg/tcpip/transport/raw/endpoint.go +++ b/pkg/tcpip/transport/raw/endpoint.go @@ -455,8 +455,21 @@ func (e *endpoint) Bind(addr tcpip.FullAddress) tcpip.Error { } // GetLocalAddress implements tcpip.Endpoint.GetLocalAddress. -func (*endpoint) GetLocalAddress() (tcpip.FullAddress, tcpip.Error) { - return tcpip.FullAddress{}, &tcpip.ErrNotSupported{} +func (e *endpoint) GetLocalAddress() (tcpip.FullAddress, tcpip.Error) { + e.mu.RLock() + defer e.mu.RUnlock() + + addr := e.BindAddr + if e.connected { + addr = e.route.LocalAddress() + } + + return tcpip.FullAddress{ + NIC: e.RegisterNICID, + Addr: addr, + // Linux returns the protocol in the port field. + Port: uint16(e.TransProto), + }, nil } // GetRemoteAddress implements tcpip.Endpoint.GetRemoteAddress. |