summaryrefslogtreecommitdiffhomepage
path: root/pkg
diff options
context:
space:
mode:
authorZeling Feng <zeling@google.com>2021-02-08 20:10:54 -0800
committergVisor bot <gvisor-bot@google.com>2021-02-08 20:13:17 -0800
commit95500ece56f2acf34fcdc74e420f91beea888ada (patch)
treeb49879185b622de9e330607275b3d9b3876abaaa /pkg
parentbf4968e17d7d08299493835a34af1a6d8551c375 (diff)
Allow UDP sockets connect()ing to port 0
We previously return EINVAL when connecting to port 0, however this is not the observed behavior on Linux. One of the observable effects after connecting to port 0 on Linux is that getpeername() will fail with ENOTCONN. PiperOrigin-RevId: 356413451
Diffstat (limited to 'pkg')
-rw-r--r--pkg/tcpip/transport/udp/endpoint.go7
1 files changed, 1 insertions, 6 deletions
diff --git a/pkg/tcpip/transport/udp/endpoint.go b/pkg/tcpip/transport/udp/endpoint.go
index afd8f4d39..807df2bb5 100644
--- a/pkg/tcpip/transport/udp/endpoint.go
+++ b/pkg/tcpip/transport/udp/endpoint.go
@@ -938,11 +938,6 @@ func (e *endpoint) Disconnect() tcpip.Error {
// Connect connects the endpoint to its peer. Specifying a NIC is optional.
func (e *endpoint) Connect(addr tcpip.FullAddress) tcpip.Error {
- if addr.Port == 0 {
- // We don't support connecting to port zero.
- return &tcpip.ErrInvalidEndpointState{}
- }
-
e.mu.Lock()
defer e.mu.Unlock()
@@ -1188,7 +1183,7 @@ func (e *endpoint) GetRemoteAddress() (tcpip.FullAddress, tcpip.Error) {
e.mu.RLock()
defer e.mu.RUnlock()
- if e.EndpointState() != StateConnected {
+ if e.EndpointState() != StateConnected || e.dstPort == 0 {
return tcpip.FullAddress{}, &tcpip.ErrNotConnected{}
}