summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip
diff options
context:
space:
mode:
authorGhanan Gowripalan <ghanan@google.com>2021-07-20 22:47:34 -0700
committergVisor bot <gvisor-bot@google.com>2021-07-20 22:50:16 -0700
commit9e805ce937ef2f2934e72f873ea4ae8451801c82 (patch)
treeb7f664411089449a91f0b874fa725c671b97f73d /pkg/tcpip
parent0184f1a662b893a1634e9b2cf3adff57971b668c (diff)
Expose local address from raw sockets
PiperOrigin-RevId: 385940836
Diffstat (limited to 'pkg/tcpip')
-rw-r--r--pkg/tcpip/transport/raw/endpoint.go17
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.