mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Return error while calling shutdown on a bound unconnected UDP socket.
PiperOrigin-RevId: 542057418
This commit is contained in:
committed by
gVisor bot
parent
d02ba3a5fd
commit
7a74c8319b
@@ -745,6 +745,9 @@ func (e *endpoint) Shutdown(flags tcpip.ShutdownFlags) tcpip.Error {
|
||||
}
|
||||
}
|
||||
|
||||
if e.net.State() == transport.DatagramEndpointStateBound {
|
||||
return &tcpip.ErrNotConnected{}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1572,7 +1572,8 @@ TEST_P(SocketInetReusePortTest, UdpPortReuseMultiThread) {
|
||||
|
||||
// Shutdown all sockets to wake up other threads.
|
||||
for (int j = 0; j < kThreadCount; j++)
|
||||
shutdown(listener_fds[j].get(), SHUT_RD);
|
||||
EXPECT_THAT(shutdown(listener_fds[j].get(), SHUT_RD),
|
||||
SyscallFailsWithErrno(ENOTCONN));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -2432,6 +2432,21 @@ TEST_P(UdpSocketTest, SendPacketLargerThanSendBufOnNonBlockingSocket) {
|
||||
SyscallFailsWithErrno(EAGAIN)));
|
||||
}
|
||||
|
||||
TEST_P(UdpSocketTest, ReadShutdownOnBoundSocket) {
|
||||
ASSERT_NO_ERRNO(BindLoopback());
|
||||
|
||||
// Bind `sock_` to loopback.
|
||||
struct sockaddr_storage addr_storage = InetLoopbackAddr();
|
||||
struct sockaddr* addr = AsSockAddr(&addr_storage);
|
||||
ASSERT_NO_ERRNO(BindSocket(sock_.get(), addr));
|
||||
|
||||
int shut_opts[] = {SHUT_RD, SHUT_WR, SHUT_RDWR};
|
||||
for (int shut_opt : shut_opts) {
|
||||
EXPECT_THAT(shutdown(sock_.get(), shut_opt),
|
||||
SyscallFailsWithErrno(ENOTCONN));
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(AllInetTests, UdpSocketControlMessagesTest,
|
||||
::testing::Values(AddressFamily::kIpv4,
|
||||
AddressFamily::kIpv6,
|
||||
|
||||
Reference in New Issue
Block a user