31 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
Ayush RanjanandgVisor bot 909944c262 Accept EMSGSIZE in native run for RawPacketMsgSizeTest.SpliceTooLong.
This behavior was fixed in 2dc334f1a63a8 ("splice, net: Use
sendmsg(MSG_SPLICE_PAGES) rather than ->sendpage()"), Linux 6.5.

PiperOrigin-RevId: 762121005
2025-05-22 14:17:10 -07:00
Jesse RosenstockandgVisor bot 0f6f64e4b5 Internal change.
PiperOrigin-RevId: 752401526
2025-04-28 12:21:07 -07:00
Andrei Vagin 67266e9403 Fix a few typos 2025-01-29 21:16:51 -08:00
Kevin KrakauerandgVisor bot eea991ba9a testing: disable flakey root tests to unblock submission
I'm looking into these, but it's not worth blocking everyone.

PiperOrigin-RevId: 698464058
2024-11-20 11:42:36 -08:00
Bruno Dal BoandgVisor bot ec0e6f435e Update Fuchsia bug TODOS
PiperOrigin-RevId: 605027094
2024-02-07 10:31:34 -08:00
Ghanan GowripalanandgVisor bot ce71f3cf3b Automated rollback of changelist 536743330
PiperOrigin-RevId: 563224104
2023-09-06 14:58:03 -07:00
Nick BrownandgVisor bot 2f3b6c4408 Add a test for receiving UDP packet from INADDR_ANY
Add a test that validates that when a UDP packet is received with an
unspecified source address, it is delivered to a listening socket.

PiperOrigin-RevId: 538240044
2023-06-06 11:22:40 -07:00
Alex KonradiandgVisor bot dc453d3a5a Don't require buffer size doubling on Fuchsia
For packet sockets, don't expect that reading the buffer size set via
SO_RCVBUF or SO_SNDBUF returns exactly twice the value that was set
(assuming no min/max clipping) on Fuchsia. The doubling is a Linux-ism,
and is not required by POSIX.

PiperOrigin-RevId: 521816820
2023-04-04 11:23:27 -07:00
Nicolas LacasseandgVisor bot 94a97f1941 hostinet: Implement packet sockets.
Two of the tests are still disabled for now. There is an existing issue with
poll in hostinet that I need to look into.

PiperOrigin-RevId: 513936838
2023-03-04 00:48:57 -08:00
Arthur SfezandgVisor bot 02aba2b7e4 Allow martian packets on packet socket dgram tests
Before this change, this test fixture expected it to be enabled already
instead of updating the config.

The Teardown method also restore the initial configuration, so that
these tests do not permanently change the config of the machines that
run the tests.

PiperOrigin-RevId: 447814273
2022-05-10 13:38:26 -07:00
Ghanan GowripalanandgVisor bot efedb242d1 Use a shared method to get loopback index
Code to get the loopback interface's index is scattered throughout the
syscall tests. Implement the code once and use that in tests (where
applicable).

While I am here, trim the dependencies/includes for network namespace
tests.

PiperOrigin-RevId: 396718124
2021-09-14 17:20:30 -07:00
Ghanan GowripalanandgVisor bot 8e9d6f9c82 Support sending with packet sockets
...through the loopback interface, only.

This change only supports sending on packet sockets through the loopback
interface as the loopback interface is the only interface used in packet
socket syscall tests - the other link endpoints are not excercised with
the existing test infrastructure.

Support for sending on packet sockets through the other interfaces will
be added as needed.

BUG: https://fxbug.dev/81592
PiperOrigin-RevId: 394368899
2021-09-01 19:44:22 -07:00
Ghanan GowripalanandgVisor bot a880bb4049 Run packet socket tests on Fuchsia
+ Do not check for CAP_NET_RAW on Fuchsia

  Fuchsia does not support capabilities the same way Linux does. Instead
  emulate the check for CAP_NET_RAW by checking if a packet socket may
  be created.

Bug: https://fxbug.dev/79016, https://fxbug.dev/81592
PiperOrigin-RevId: 390263666
2021-08-11 18:21:40 -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
Kevin KrakauerandgVisor bot 6aa41bac3e check explicitly that AF_PACKET sockets can't write in gVisor
PiperOrigin-RevId: 381896875
2021-06-28 10:40:55 -07:00
Kevin KrakauerandgVisor bot bd3942cae6 clean up tcpdump TODOs
tcpdump is largely supported. We've also chose not to implement writeable
AF_PACKET sockets, and there's a bug specifically for promiscuous mode (#3333).

Fixes #173.

PiperOrigin-RevId: 380733686
2021-06-21 22:16:11 -07:00
Nayana BidariandgVisor bot f1de34234a Move SO_RCVBUF to socketops.
Fixes #2926, #674

PiperOrigin-RevId: 369457123
2021-04-20 09:32:54 -07:00
Nayana BidariandgVisor bot 996dec11eb Move SO_SNDBUF to socketops.
This CL moves {S,G}etsockopt of SO_SNDBUF from all endpoints to socketops. For
unix sockets, we do not support setting of this option.

PiperOrigin-RevId: 353871484
2021-01-26 08:25:34 -08:00
Ting-Yu WangandgVisor bot bb67838fc9 Correctly return EMSGSIZE when packet is too big in raw socket.
IPv4 previously accepts the packet, while IPv6 panics. Neither is the behavior
in Linux.

splice() in Linux has different behavior than in gVisor. This change documents
it in the SpliceTooLong test.

Reported-by: [email protected]
PiperOrigin-RevId: 352091286
2021-01-15 15:10:27 -08:00
Nayana BidariandgVisor bot 11edffc221 Support getsockopt for SO_ACCEPTCONN.
The SO_ACCEPTCONN option is used only on getsockopt(). When this option is
specified, getsockopt() indicates whether socket listening is enabled for
the socket. A value of zero indicates that socket listening is disabled;
non-zero that it is enabled.

PiperOrigin-RevId: 338703206
2020-10-23 10:48:24 -07:00
Nayana BidariandgVisor bot 67cfac7dc7 {Set,Get} SO_LINGER on all endpoints.
SO_LINGER is a socket level option and should be stored on all endpoints even
though it is used to linger only for TCP endpoints.

PiperOrigin-RevId: 332369252
2020-09-17 20:00:33 -07:00
Tamir DubersteinandgVisor bot 63c7c97b2e Remove __fuchsia__ defines
These mostly guard linux-only headers; check for linux instead.

PiperOrigin-RevId: 329362762
2020-08-31 13:10:56 -07:00
Fabricio VoznikaandgVisor bot 560091c177 Redirect TODO to GitHub issues
PiperOrigin-RevId: 323715260
2020-07-28 21:24:26 -07:00
Bhasker HariharanandgVisor bot 267249b783 Add support to return protocol in recvmsg for AF_PACKET.
Updates #173

PiperOrigin-RevId: 321690756
2020-07-16 18:40:32 -07:00
Bhasker HariharanandgVisor bot 34373521d4 Add support for SO_ERROR to packet sockets.
Packet sockets also seem to allow double binding and do not return an error on
linux. This was tested by running the syscall test in a linux namespace as root
and the current test DoubleBind fails@HEAD.

Passes after this change.

Updates #173

PiperOrigin-RevId: 321445137
2020-07-15 14:56:39 -07:00
Bhasker HariharanandgVisor bot 0812cae4d1 Stub out SO_DETACH_FILTER.
Updates #2746

PiperOrigin-RevId: 320757963
2020-07-11 06:22:47 -07:00
Bhasker HariharanandgVisor bot 32acfe2935 Add support for SO_RCVBUF/SO_SNDBUF for AF_PACKET sockets.
Updates #2746

PiperOrigin-RevId: 319887810
2020-07-06 17:22:54 -07:00
Kevin KrakauerandgVisor bot 5230b2cfcf AF_PACKET support for netstack (aka epsocket).
Like (AF_INET, SOCK_RAW) sockets, AF_PACKET sockets require CAP_NET_RAW. With
runsc, you'll need to pass `--net-raw=true` to enable them.

Binding isn't supported yet.

PiperOrigin-RevId: 275909366
2019-10-21 13:23:18 -07:00
Kevin KrakauerandgVisor bot 8de4371f4d Make raw socket tests pass in environments with or without CAP_NET_RAW.
PiperOrigin-RevId: 271442321
2019-09-26 15:09:20 -07:00
Kevin KrakauerandgVisor bot f9331dc681 Add tests for raw AF_PACKET sockets.
PiperOrigin-RevId: 264494359
2019-08-20 16:36:06 -07:00