12 Commits
Author SHA1 Message Date
Ayush RanjanandgVisor bot b6d0f8496a Update Have[RawIP/Packet]SocketCapability() to open raw/packet sockets.
As described in the comments, this is the only feasible way of really
checking CAP_NET_RAW properly. This is what Fuchsia
(test/util/fuchsia_capability_util.cc) uses as well.

This also allows us to more granularly check raw socket capabilities. For
example, it is possible to have caps for socket(AF_INET, SOCK_RAW, IPPROTO_RAW)
but *not* for socket(AF_INET, SOCK_RAW, IPPROTO_UDP).

Fixes test failures where the test was being run in a new userns but
the netns had the initial userns. So the test effectively could
open raw sockets.

Cleanup:
- Cleaned up some redundant SKIP_IF(Have[RawIP/Packet]SocketCapability())
  from various TEST_P/TEST_F tests whose test class's SetUp() was already
  calling GTEST_SKIP() when the capability was not available.
- Removed redundant EPERM checks after Have[RawIP/Packet]SocketCapability()
  returned false. Now the implementation only returns false if socket creation
  results in EPERM. So the EPERM check again was redundant.
PiperOrigin-RevId: 881067665
2026-03-09 15:35:11 -07:00
Jeff MartinandgVisor bot ab713a3a54 Internal change.
PiperOrigin-RevId: 827961623
2025-11-04 07:24:42 -08:00
Nayana BidariandgVisor bot 7e315057ba Release port for non listening sockets which are bound with any address.
When a TCP client socket uses the wildcard("any") address for binding, the port
is reserved across both the IPv4 and IPv6 protocol families. During close() or
abort() calls we were only releasing the port reservation corresponding to the
established IPv6 connection tuple, failing to release the IPv4 reservation and
thus blocking future IPv4 bindings to that port.

The fix implements a mechanism to track if a socket was bound to the "any"
address. This is used during socket connect to release IPv4 relevant port
reservations and will allow the IPv4 socket to bind in future. A syscall test
has been added to verify the behavior.

PiperOrigin-RevId: 752385613
2025-04-28 11:38:48 -07:00
Andrei VaginandgVisor bot 2e1da28c78 tests: Deflake socket_inet_loopback_isolated_test
This test case creates one connection, then it closes one end of it. After that
it waits for a linger timeout and tries to create the second connection with
the same client source port. The test is flaky if the second half of the fist
connection isn't closed before creating the second connection.

PiperOrigin-RevId: 715924851
2025-01-15 13:38:00 -08:00
Zeling FengandgVisor bot 3e93853db1 Improve TCPFinWait2Test syscall test
This test was under specified in that it does not try to bind to same
local address before the second connect. This is problematic as we
may see unexpected passes because the second connect can just use any
other port to succeed, while the true intention for this test is to
reuse the exact same port as the first connect.

PiperOrigin-RevId: 612666475
2024-03-04 19:12:46 -08:00
Zeling FengandgVisor bot 4fd153dc89 Increase timeout for TCPLinger2TimeoutAfterClose
There have been some timing issues with this test, bump up the margin
to decrease flake rate but also decrease the expected sleeping time
to not increase the overall test run time.

PiperOrigin-RevId: 605385820
2024-02-08 12:00:59 -08:00
Zeling FengandgVisor bot 3bcc2c5cef Add a syscall test to test address conflicts during connect
When SO_REUSEADDR is enabled, it is possible to create two connections with the
same 4-tuple, the error is only reported when `connect` instead of `bind`, also
the reported errno is `EADDRNOTAVAIL` instead of `EADDRINUSE`.

PiperOrigin-RevId: 532593923
2023-05-16 15:41:24 -07:00
Nicolas LacasseandgVisor bot 2689cb155e Require CAP_NET_RAW to call setsockopt(SO_BINDTODEVICE) in
This causes socket_inet_loopback_isolated_test to fail with hostnet on
buildkite (but curiously only on oldkernel).

PiperOrigin-RevId: 523528229
2023-04-11 15:59:19 -07:00
Andrei Vagin 61dd004b97 Move BindToDeviceReusePort to socket_inet_loopback_isolated
SO_BINDTODEVICE required CAP_NET_RAW beofre the 5.7 kernel. This was
fixed in the kernel by c427bfec18f2 ("net: core: enable SO_BINDTODEVICE
for non-root users").
2022-05-25 13:01:34 -07:00
Ghanan GowripalanandgVisor bot 129cc47c63 Move socket_test_util to //test/util
...and rename the library to socket_util.

PiperOrigin-RevId: 386348306
2021-07-22 16:37:15 -07:00
Etienne PerotandgVisor bot 9ca099678a Run :socket_inet_loopback_isolated_test_linux tests in a container.
This creates new user and network namespaces for all tests in
`:socket_inet_loopback_isolated_test_linux`.

PiperOrigin-RevId: 381374120
2021-06-24 17:49:09 -07:00
Etienne PerotandgVisor bot cdae8b8820 socket_inet_loopback: Split off tests that need isolation in their own file.
This allows these tests, which can cause flakiness when run in the same network
namespace as the other `socket_inet_loopback` tests, to run as separate tests
in their own environment. It also means that all of the shards of those tests
can be more isolated from each other as well.

PiperOrigin-RevId: 380930198
2021-06-22 17:53:37 -07:00