96 Commits
Author SHA1 Message Date
gVisor bot a9b7b616c3 Merge pull request #14478 from EtiennePerot:socket-test-fix
PiperOrigin-RevId: 972884938
2026-08-28 18:05:59 -07:00
Etienne Perot 054f876575 Fix //test/syscalls:tcp_socket_test_native failing on newer kernels.
As of Linux commit 5d39580f68e6, SO_ATTACH_FILTER requires
CAP_NET_ADMIN for TCP sockets.

Skip in tests if we don't have it, and update Netstack to require it
too.
2026-08-28 13:16:50 -07:00
gVisor bot 975eb8e83f Internal change.
PiperOrigin-RevId: 957694371
2026-08-01 12:58:40 -07:00
gVisor bot a098767915 Merge pull request #13017 from tanyifeng:net-small-buffer-getsockopt
PiperOrigin-RevId: 907104383
2026-04-28 12:00:56 -07:00
Tan Yifeng 45596a2399 net: Support getsockopt with small buffer for int TCP options
Linux's do_tcp_getsockopt() clamps the user-supplied buflen via
len = min_t(unsigned int, len, sizeof(int)) and copies that many
bytes of the integer value, so a sub-int (or zero-length) buffer
returns a truncated result rather than EINVAL. gVisor instead
rejects any outLen < 4 with EINVAL, which breaks real callers:
python-trio probes TCP_NODELAY with buflen=1 to detect its
availability and fails with OSError(EINVAL).

Route all 12 integer TCP options (TCP_NODELAY, TCP_CORK,
TCP_QUICKACK, TCP_MAXSEG, TCP_KEEPIDLE, TCP_KEEPINTVL,
TCP_KEEPCNT, TCP_USER_TIMEOUT, TCP_LINGER2, TCP_DEFER_ACCEPT,
TCP_SYNCNT, TCP_WINDOW_CLAMP) through a shared helper that
truncates the value to outLen bytes, matching Linux. outLen == 0
is a valid (zero-byte) read and must not be rejected.

Reference: net/ipv4/tcp.c:do_tcp_getsockopt()
Signed-off-by: Tan Yifeng <[email protected]>
2026-04-27 16:40:25 +08:00
gVisor bot 38d62f734a Merge pull request #12852 from tanyifeng:net-ip-mtu-discover
PiperOrigin-RevId: 894240043
2026-04-03 14:06:21 -07:00
Tan Yifeng 5c258bd415 net: Support all valid IP_MTU_DISCOVER values for UDP and TCP
The UDP endpoint only accepted PMTUDiscoveryDont and the TCP endpoint
rejected PMTUDiscoveryProbe, causing QUIC libraries (quic-go) to fail
when setting IP_PMTUDISC_DO or IP_PMTUDISC_PROBE on UDP sockets.

Accept all valid PMTUD strategies (DONT/WANT/DO/PROBE) for both UDP
and TCP, since gVisor does not implement ICMP-based PMTU feedback,
`PROBE` and `DO` are functionally equivalent — both set DF but neither
updates a cached route PMTU.

Test: UdpSocketTest.SetPMTUD, TcpSocketTest.SetPMTUD

Signed-off-by: Tan Yifeng <[email protected]>
2026-04-02 16:47:35 +08:00
Ayush RanjanandgVisor bot 5803432c81 Fix SO_TIMESTAMP generation and control buffer sizing in TcpSocketTest
This change fixes two issues in the TcpSCMPriority test that caused failures on
Linux:

1. Fix Control Buffer Size Calculation: The control buffer size was previously
   calculated using nested macros: CMSG_SPACE(sizeof(timeval) +
   CMSG_SPACE(sizeof(int))). This is incorrect as it fails to account for the
   total alignment padding required for multiple distinct messages. The
   calculation is updated to the correct additive form:
   CMSG_SPACE(sizeof(timeval)) + CMSG_SPACE(sizeof(int)).

2. Fix Race Condition in SO_TIMESTAMP Generation: Previously,
   setsockopt(SO_TIMESTAMP) was called after the client had already written
   data to the socket. Because the kernel generates timestamps at the moment of
   packet ingress, the data in the receive queue did not have timestamps
   attached, resulting in a missing control message. This caused the test to
   fail assertions expecting SO_TIMESTAMP to be the first message received. The
   socket options are now enabled before the client writes data.

Together, these fixes ensure the control messages are correctly generated and
received without truncation.

PiperOrigin-RevId: 858770547
2026-01-20 15:10:13 -08:00
Andrei VaginandgVisor bot 8d664cfa92 Automated rollback of changelist 854268804
PiperOrigin-RevId: 855304585
2026-01-12 11:18:07 -08:00
Constantine Peresypkin 8bf693a31e tcpip: fix IP_MTU_DISCOVER flag for tcp and udp 2025-12-21 12:21:49 -08:00
Andrei Vagin 67266e9403 Fix a few typos 2025-01-29 21:16:51 -08:00
Nayana BidariandgVisor bot 40296833dd Enable netstack save/restore in cloud/gvisor by default.
PiperOrigin-RevId: 712978128
2025-01-07 11:19:26 -08:00
Ayush RanjanandgVisor bot d394cf49cd Reduce timeout in TcpSocketTest.Closed{Read/Write}BlockingSocket.
The timeout was set to 10 seconds, which is too long. Should be sufficient to
timeout in 3 seconds to ensure read()/send() is blocked.

These tests have multiple variants too. Together, they take too long to run.

PiperOrigin-RevId: 687411356
2024-10-18 13:47:57 -07:00
Ayush RanjanandgVisor bot dd1dc0ff15 Deflake TcpSocketTest.ClosedWriteBlockingSocket in hostnet mode.
Bump sleep in FillSocketBuffers() so that host netstack gets a chance to move
data from send -> receive buffer.

PiperOrigin-RevId: 687144890
2024-10-17 20:45:37 -07:00
Kevin KrakauerandgVisor bot e85e82f436 noop upon IP_PMTUDISC_INTERFACE and IP_PMTUDISC_OMIT
This is what we did previously, and doing so avoids breaking some users.

Fixes #10760.

PiperOrigin-RevId: 663358270
2024-08-15 10:35:00 -07:00
Bruno Dal BoandgVisor bot 673bff8222 Use infinite timeouts for Fuchsia
PiperOrigin-RevId: 655601638
2024-07-24 09:52:27 -07:00
Kevin KrakauerandgVisor bot 5a7de6a798 make PMTUD on by default and settable via sockopt
We've supported PMTUD for a long time and just never turned it on.

Addresses #10344.

PiperOrigin-RevId: 634003508
2024-05-15 10:44:02 -07:00
Jeff MartinandgVisor bot 2d8b67b4ec Increase timeout when observing TCP connection failures
Give the Netstack additional time to reject incoming connections for which
there are no listening sockets. This prevents flakes in test environments with
CPU contention, where the Netstack may be descheduled for multiple seconds.

PiperOrigin-RevId: 623165285
2024-04-09 07:51:59 -07:00
Nayana BidariandgVisor bot a89e5b656b Fix panic while setting TCP_CORK off.
TCP sender is initialized only in established state, check if sender is
available before disabling the TCP_CORK timer.

Reported-by: [email protected]
PiperOrigin-RevId: 616879762
2024-03-18 10:51:33 -07:00
Bruno Dal BoandgVisor bot ec0e6f435e Update Fuchsia bug TODOS
PiperOrigin-RevId: 605027094
2024-02-07 10:31:34 -08:00
gVisor bot 3f4696b0f9 Add a syscall test exercising getsockname on unbound TCP sockets
Verify that getsockname on a TCP socket that is not bound or connected still
succeeds.

PiperOrigin-RevId: 585977990
2023-11-28 08:01:18 -08:00
Ayush RanjanandgVisor bot 125b741d86 Return user_mss if user_mss is set and socket is unconnected.
Has the same effect as Linux commit 34dfde4ad87b ("tcp: Return user_mss for
TCP_MAXSEG in CLOSE/LISTEN state if user_mss set").

Updated test to accept both values (default and user set) so test works on
newer and older kernels.

PiperOrigin-RevId: 563844012
2023-09-08 13:57:42 -07:00
Nayana BidariandgVisor bot 3cea46826c Automated rollback of changelist 538202277
PiperOrigin-RevId: 538315796
2023-06-06 16:03:47 -07:00
Zeling FengandgVisor bot 8caec9445c Improve FillSocketBuffers test utility
The utility function used to interpret `EWOULDBLOCK` of a `write` call as
buffers being filled at both the receiver and the sender. This is not a valid
assumption even on Linux because it is possible that the test fills the sender
buffer faster than the socket is able to transfer the bytes, in that case,
EWOULDBLOCK will be observed even before the receiver side has a full buffer.
The fix to this is to inspect the buffer size at the receiver side, and discard
any error before the receiver buffer is full. Then we can use EWOULDBLOCK to
indicate the sender buffer is full.

PiperOrigin-RevId: 538202277
2023-06-06 09:14:26 -07:00
Kevin KrakauerandgVisor bot 94e2fc7ed6 save/restore: test epoll bug
Regression test for b/280313827. We also mark the specific still-failing S/R
tests with DisableSave so that tcp_socket_test can be run with S/R tests.

Tested with the pre-cl/528876775 code to ensure it failed.

PiperOrigin-RevId: 530747608
2023-05-09 16:51:11 -07:00
Nicolas LacasseandgVisor bot e75ff4f68c Enable socket_inet_loopback test on hostinet.
A few minor fixes. The biggest change is that the blocking implementation needs
to wait on POLLHUP and POLLERR events, in addition to readable/writable events.
We also need to track shutdown state in the socket.

PiperOrigin-RevId: 529816115
2023-05-05 14:35:57 -07:00
Kevin KrakauerandgVisor bot 391fb1543d testing: move test to other tests of same fixture
PiperOrigin-RevId: 528892706
2023-05-02 14:42:23 -07:00
Zeling FengandgVisor bot 866520ab7d Tune TCP syscall test
Change the parameters for filling the send buffer:
1. Use a larger buffer to account for the fact that the real send buffer is
larger than the size we set.
2. Use a longer sleep duration to reduce the chance of flakes.

PiperOrigin-RevId: 528562364
2023-05-01 13:42:05 -07:00
Nicolas LacasseandgVisor bot 8ee4c3bae7 Automated rollback of changelist 525849045
PiperOrigin-RevId: 526120544
2023-04-21 13:26:08 -07:00
Nicolas LacasseandgVisor bot 66fe1d19e0 Enable socket_inet_loopback test on hostinet.
The blocking implementation needs to wait on POLLHUP and POLLERR events, in
addition to readable/writable events. That fixed at least one test.

There's still two unresolved issues in the tests, but we can enable the rest
of the suite while we figure out those two.

PiperOrigin-RevId: 525849045
2023-04-20 14:25:27 -07:00
gVisor bot d034171d9c Merge pull request #8679 from avagin:cpp-warnings
PiperOrigin-RevId: 523157922
2023-04-10 10:59:51 -07:00
Alex KonradiandgVisor bot d6b85607f7 Connect to non-zero ports in TCP tests
When testing TCP behavior with connections that don't succeed, don't use
port 0 in the target address. Instead, reserve a port by binding but not
listening with a different socket, and try connecting to that.

Fixes #8749

PiperOrigin-RevId: 519776842
2023-03-27 11:18:54 -07:00
Alex KonradiandgVisor bot 54d8bc02f8 Add test for poll(POLLIN) on TCP around accept
Add a test that asserts that POLLIN is set on a TCP listener when a
new connection is available to be accepted and is unset after the
connection is actually accepted.

PiperOrigin-RevId: 518075095
2023-03-20 14:24:39 -07:00
Kevin KrakauerandgVisor bot 987b1af762 netstack: add context to test description
PiperOrigin-RevId: 516584185
2023-03-14 11:34:16 -07:00
Andrei Vagin 3445db339d Fix all c++ compile time warnings 2023-03-09 19:01:00 -08:00
Nicolas LacasseandgVisor bot 256cb0cd62 Fix (most of) tcp_socket_test on hostinet.
A few fixes in here:

* Linux does not transition the state of a non-blocking socket to SS_CONNECTED
  when the connect happens asynchronously. Instead, it leaves the state as
  SS_CONNECTING (seems like a Linux bug, but OK). This can introduce weird
  behavior for subsequent connect() calls. gVisor now forces the state to
  update to SS_CONNECTED by calling connect() twice.

* Socket shutdown events are slightly different between gVisor and linux. We
  already assert different behavior between the two environments, and now we
  also have to check for gVisor+hostinet instead of just gvisor.

* Handle send/recv timeouts, which fixes blocking for read()/write() syscalls.

* Handle cases like MSG_PEEK where the senderAddress is not returned.

* Pass through some more socketopts, and allow them in the syscall filters.

Something is still wrong with shutdown() and poll() calls, so those tests are
temporarily disabled. I'm looking at those next.

This also fixes a number of other syscall test suites, so those are enabled as
well.

PiperOrigin-RevId: 508397317
2023-02-09 09:39:26 -08:00
Ayush RanjanandgVisor bot 1ef17a9d7e Consistently RetryEINTR(connect) in tcp_socket_test.
connect(2) can block and is susceptible to being interrupted by a signal.

This is to prevents flakes like
https://buildkite.com/gvisor/pipeline/builds/19195#01862e07-a7b6-4a5e-8822-690512569abe.

PiperOrigin-RevId: 508102460
2023-02-08 09:34:33 -08:00
Alex KonradiandgVisor bot e8991ae06f Fix formatting
Apply existing format rules against all files under gvisor/test/syscalls

PiperOrigin-RevId: 503229233
2023-01-19 12:07:31 -08:00
Alex KonradiandgVisor bot 3d82223d70 Retry ioctl when checking TCP socket receive queue len
When checking how much data is left in the receive queue, retry to allow
time for packets to propagate and the system to push data into the
socket's receive queue.

PiperOrigin-RevId: 500257746
2023-01-06 15:29:27 -08:00
Nick BrownandgVisor bot d0696812d1 Store threads with unique_ptr in ListenConnectParallel
The existing implementation uses raw pointers, which means:

- Threads are joined at the end of each loop, and the test therefore doesn't
  actually exercise the syscalls in parallel.
- The later call to `Join` is undefined behavior.

PiperOrigin-RevId: 478845631
2022-10-04 11:49:26 -07:00
Nick BrownandgVisor bot d9db61fa15 Reduce poll timeouts
The 10s timeout eats up significant time when tests are expected to fail.

PiperOrigin-RevId: 478655369
2022-10-03 18:20:48 -07:00
Alex KonradiandgVisor bot 0221162a9c Use FileDescriptor for TcpSocketTest fixture members
Use the FileDescriptor helper class to manage the lifetime of file descriptors
held as TcpSocketTest members. This will help prevent leaks if some part of the
test setup fails.

Also rename `first_fd` and `second_fd` to be a) more meaningfully named and
b) conform to Google C++ naming conventions for class members.

Updates #8028

PiperOrigin-RevId: 478527874
2022-10-03 09:41:54 -07:00
Alex KonradiandgVisor bot edce3d338e Add test for TCP getpeername
This doesn't appear to be covered by any existing tests. Check that the peer
address for a connected TCP socket matches the local address for the
corresponding accepted socket, and vice-versa.

Fixes #8020

PiperOrigin-RevId: 477186443
2022-09-27 09:09:31 -07:00
Tamir DubersteinandgVisor bot 2b243fa4ba Work around missing signal in Fuchsia
Narrow the Fuchsia non-compliance rather than expecting the test to fail.

PiperOrigin-RevId: 460500478
2022-07-12 10:45:21 -07:00
Tamir DubersteinandgVisor bot d98a2a1f33 Add shutdown-while-synrcvd test
Updates #6666.

PiperOrigin-RevId: 460105271
2022-07-10 18:11:25 -07:00
Bhasker HariharanandgVisor bot 738c20b172 Fix race in listen.
Netstack has an internal StateBound state that a listening socket
transitions to before it actually transitions to StateListen. This
state is not handled by the dispatcher because normally a socket in
StateBound is never registered with the demuxer. But in case of listen
there is a small race window where the socket is in StateBound after
registering with dispatcher but before it transitions to Listen.

An incoming segment that hits the window causes the dispatcher to
panic. This change makes it so that we transition to Listen before
registering and if registration fails we now transition to a CLOSED
state same as what linux does.

See: https://github.com/google/gvisor/issues/7428

Fixes #7428

PiperOrigin-RevId: 443489134
2022-04-21 15:04:16 -07:00
gVisor bot eedbed0ae3 Internal change.
PiperOrigin-RevId: 434836427
2022-03-15 13:13:15 -07:00
Tamir DubersteinandgVisor bot 65c1b93863 Fix compiler warnings
PiperOrigin-RevId: 403241314
2021-10-14 18:36:09 -07:00
Arthur SfezandgVisor bot edd2b1c6b7 Handle Shutdown on connecting tcp socket
Fixes #6495

PiperOrigin-RevId: 398121921
2021-09-21 17:29:58 -07:00
Arthur SfezandgVisor bot 8e764ee90b Deliver endpoints to the accept queue synchronously when possible
Before this change, when a new connection was created after receiving
an ACK that matched a SYN-cookie, it was always delivered asynchronously
to the accept queue. There was a chance that the listening endpoint
would process a SYN from another client before the delivery happened,
and the listening endpoint would not know yet that the queue was about
to be full, once the delivery happened.

Now, when an ACK matching a SYN-cookie is received, the new endpoint is
created and moved to the accept queue synchronously, while holding the
accept lock.

Fixes #6545

PiperOrigin-RevId: 398107254
2021-09-21 16:13:18 -07:00