53 Commits

Author SHA1 Message Date
Nayana Bidari 8cfc543a3f Fix reconnect of UDP socket.
The reconnect for UDP sockets was failing because we were not removing the old
registration before attempting to register again. Fix this issue by
removing the old registration and then registering the endpoint.

Updates #8998

PiperOrigin-RevId: 582007411
2023-11-13 10:24:31 -08:00
gVisor bot ae1294b435 Internal change.
PiperOrigin-RevId: 567370524
2023-09-21 11:42:16 -07:00
Nayana Bidari 7a74c8319b Return error while calling shutdown on a bound unconnected UDP socket.
PiperOrigin-RevId: 542057418
2023-06-20 14:57:45 -07:00
Alex Konradi 9a2f1d041a Add a test for receiving UDP packet with src port 0
Add a test that validates that when a UDP packet is received with a source port
value of 0, it is delivered to a listening socket.

PiperOrigin-RevId: 536773375
2023-05-31 11:31:05 -07:00
Nayana Bidari 6a4840efff Enable socket option SO_NO_CHECK tests on hostinet.
- Enables the test to set/get SO_NO_CHECK option on hostinet as this option is
already supported on hostinet.
- Enables all the other UDP hostinet tests except the flaky test to set/get
IP_RECVTOS option.

PiperOrigin-RevId: 525792961
2023-04-20 10:57:06 -07:00
Nick Brown 1063b2a08e Connect to bound addr before closing socket
The `ConnectAndSendNoReceiver` test tries to setup a scenario in which a socket
sends to an address with no listener, asserting on the returned ICMP error.
In the existing code, this is done by closing a socket and then
connecting/sending to its bound address with another socket. This is flaky
because sometimes the system will coincidentally bind the sender to the bound
address of the receiver, in which case we won't get the ICMP error. The fix is
to connect before the socket is closed (that way the sender will get a
different port than the boudn address).

PiperOrigin-RevId: 518612786
2023-03-22 10:48:33 -07:00
Nick Brown cc1f80913f Defer poll timeout to Fuchsia's CI infra
Set the ICMP poll timeout to a negative value so the poll will block
indefinitely. This effectively delegates the timeout to the overall test
timeout imposed by Fuchsia's CI/CQ.

PiperOrigin-RevId: 516863038
2023-03-15 10:28:20 -07:00
Nick Brown 2be9de7ea1 Increase ICMP poll timeout on Fuchsia
We are still seeing flakes in Fuchsia's CQ. Increase the poll timeout by a
factor of 10.

PiperOrigin-RevId: 516659576
2023-03-14 16:10:08 -07:00
Nick Brown 76057e7c63 Increase ICMP timeout
We are still hitting the occasional flake in Fuchsia's CQ when polling for an
ICMP error. Increase the timeout from 2s => 5s.

PiperOrigin-RevId: 509655650
2023-02-14 15:34:12 -08:00
Alex Konradi 9e2b411a50 Connect before closing the destination socket to acquire different port
In the ConnectWriteToInvalidPort test case, the target socket is closed before
the source socket sends data to generate and then verify reception of an ICMP
error packet. If the target socket is closed before an outgoing port number is
picked for the source socket, the source socket might be assigned the same
port number for sending as its destination. The result is that the source
socket receives the packet it sends and so no error is generated. This results
in test flakiness, though with very low probability.

Fixes #8338

PiperOrigin-RevId: 499244574
2023-01-03 09:46:19 -08:00
Alex Konradi fdeab8650a Fix more UDP port number rollovers
Some of the UDP tests bind a socket with port 0, read the bound port number,
then connect using 1+bound port as the port number. This can roll over if the
originally bound port is 2^16-1, which makes for test cases that are very
infrequently flaky on systems with an ephemeral port range that includes
2^16-1. Fix this by using bound port-1, which should never underflow since the
bound port isn't 0, and should always be in a usable range, even if it is
below the ephemeral port range.

PiperOrigin-RevId: 496996446
2022-12-21 13:43:37 -08:00
Alex Konradi e1a2d79020 Don't hardcode ports when binding udp sockets
The existing logic constructs a loopback address for binding by incrementing
the port number of an existing address. This can lead to failures in the event
that the original address had port=65535 (the maximum port). Resolve this
failure case by using the same port number instead of incrementing.

PiperOrigin-RevId: 488934780
2022-11-16 07:31:56 -08:00
Nick Brown 21b9d59950 Increase timeout when polling for ICMP errors
We're seeing occasional flakes in CQ in which the ICMP error isn't received in
time. Double the timeout from 1s to 2s.

PiperOrigin-RevId: 487035507
2022-11-08 13:24:33 -08:00
Nick Brown fbddf039b2 Don't hardcode ports when binding udp sockets
The existing logic constructs a loopback address for binding by incrementing
the port number of an existing address. This can lead to failures in the event
that the original address had port=65535 (the maximum port). Resolve this
failure case by just binding to a new loopback address and letting the system
pick the port.

Also, fix a bug in `ReceiveFromNotConnected` in which the test was asserting on
the wrong socket.

PiperOrigin-RevId: 482260609
2022-10-19 11:41:07 -07:00
Nick Brown 983800eee5 Run syscall tests against Fast UDP
Includes the following diffs:

- Use timeouts when reading immediately after sending.
- Poll for POLLIN before operations that assume data has arrived.
- Expect`SendMsgTooLarge` passes with Fast UDP (error code is correct now).
- Skip `RecvBufLimits` on Fast UDP (limits not enforced due to zircon socket).

Fuchsia Bug: 101888

PiperOrigin-RevId: 459857293
2022-07-08 16:32:59 -07:00
Ghanan Gowripalan bb36c43e97 Respect SO_SNDBUF for network datagram endpoints
Previously, SO_SNDBUF was effectively a no-op. The stack should make
sure that only SO_SNDBUF bytes are ever in-flight for any given
socket/endpoint.

Fuchsia Bug: https://fxbug.dev/99070

PiperOrigin-RevId: 446792223
2022-05-05 12:52:34 -07:00
Ghanan Gowripalan da0c67b92a Use different flags for IPV6_RECVERR and IP_RECVERR
PiperOrigin-RevId: 446361103
2022-05-03 21:17:40 -07:00
Andrei Vagin b286d1c1ba tests: fix compile time warnings
test/syscalls/linux/futex.cc:
In member function 'virtual void gvisor::testing::
{anonymous}::PrivateAndSharedFutexTest_PIWaiters_Test::TestBody()':

test/syscalls/linux/futex.cc:697:19:
warning: comparison of integer expressions of different signedness:
'std::__atomic_base<int>::__int_type' {aka 'int'} and 'unsigned int'
[-Wsign-compare]

  697 |   while (a.load() != (FUTEX_WAITERS | gettid())) {
      |          ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

test/syscalls/linux/proc_pid_uid_gid_map.cc:207:64:
warning: comparison of integer expressions of different signedness: 'size_t'
{aka 'long unsigned int'} and 'int' [-Wsign-compare]

  207 |         TEST_PCHECK((n = write(fd, line.c_str(), line.size())) != -1);
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
test/syscalls/linux/socket_inet_loopback.cc:964:21:
warning: comparison of integer expressions of different signedness: 'int' and
'std::array<gvisor::testing::FileDescriptor, 1>::size_type' {aka 'long
unsigned int'} [-Wsign-compare]

  964 |   for (int i = 0; i < std::size(established_clients); i++) {
      |                   ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

test/syscalls/linux/socket_inet_loopback.cc:974:21:
warning: comparison of integer expressions of different signedness: 'int' and
'std::array<gvisor::testing::FileDescriptor, 1>::size_type' {aka 'long
unsigned int'} [-Wsign-compare]

  974 |   for (int i = 0; i < std::size(waiting_clients); i++) {
      |                   ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~

test/syscalls/linux/udp_socket.cc:869:6:
warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]

  869 |if (!IsRunningWithHostinet() || GvisorPlatform() == Platform::kPtrace ||
      |   ^

test/syscalls/linux/socket_unix_unbound_abstract.cc:93:9:
warning: variable 'orig_opts' set but not used [-Wunused-but-set-variable]

   93 |     int orig_opts;
      |         ^~~~~~~~~

test/syscalls/linux/socket_unix_unbound_abstract.cc:107:9:
warning: variable 'orig_opts' set but not used [-Wunused-but-set-variable]

  107 |     int orig_opts;
      |         ^~~~~~~~~

PiperOrigin-RevId: 445545240
2022-04-29 17:59:14 -07:00
Nick Brown 438c84460d Poll for POLLERR before validating ICMP error
...since ICMP errors are returned asynchronously. This also matches the
behavior of existing tests.

PiperOrigin-RevId: 435484650
2022-03-17 16:50:09 -07:00
gVisor bot f255132aad Internal change.
PiperOrigin-RevId: 434836427
2022-03-15 13:13:15 -07:00
Arthur Sfez 21dffa8f4c Support sending TTL and HopLimit
PiperOrigin-RevId: 430554985
2022-02-23 15:40:37 -08:00
Arthur Sfez 86ad7d5b58 Support receiving ttl/hoplimit control message
PiperOrigin-RevId: 429096959
2022-02-16 11:27:21 -08:00
Arthur Sfez 4a94302baf Support receiving PKTINFO on icmp endpoints
PiperOrigin-RevId: 428599075
2022-02-14 13:51:49 -08:00
Arthur Sfez b8689e0586 Simplify TOS and TClass UDP tests
This adds helpers to send both of these control messages via sendmsg,
and most of the initialization is moved into the SetUp body.

The parametrization is now more meaningful. The kDualStack is actually
impactful, which means DifferentTOSAndTClass test has been removed. The
IPv4-mapped IPv6 scenario is now tested in the SetAndReceiveTOSOrTClass.

PiperOrigin-RevId: 426313619
2022-02-03 21:57:29 -08:00
Arthur Sfez 56de63a4cb Remove unused parameter in UDP tests instantiation
The variant kDualStack is never used by any test. It just duplicates
kIpv6 case. Because the parameters are now just kIpv4 and kIpv6, use
an int to encode the address family, instead of the enum.

PiperOrigin-RevId: 426224701
2022-02-03 13:31:10 -08:00