From 95500ece56f2acf34fcdc74e420f91beea888ada Mon Sep 17 00:00:00 2001 From: Zeling Feng Date: Mon, 8 Feb 2021 20:10:54 -0800 Subject: 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 --- pkg/tcpip/transport/udp/endpoint.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'pkg/tcpip/transport') 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{} } -- cgit v1.2.3