32 Commits
Author SHA1 Message Date
Jeff MartinandgVisor bot a06dd585f5 [tests] Remove direct dependency on linux_capability_util
Instead, rely on the indirection through "capability_util", which is platform
agnostic. This ensures tests can be run against Linux and Fuchsia.

PiperOrigin-RevId: 884457389
2026-03-16 08:47:31 -07:00
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
Shailend ChandandgVisor bot 3860ef4de3 socket(): Check for CAP_NET_RAW in the netns-owning userns
And not the userns of the calling Task. Analogous to Linux's
`ns_capable(net->user_ns, CAP_NET_RAW)`.

PiperOrigin-RevId: 843929192
2025-12-12 20:09:51 -08:00
Jeff MartinandgVisor bot 92e6f29ad2 Run "SendWithoutTargetDevice" test on Fuchsia
This test is expected to pass for Fuchsia, but not gVisor.

PiperOrigin-RevId: 628090196
2024-04-25 08:58:12 -07:00
Jeff MartinandgVisor bot d38d96227f Add Syscall tests for invalid sendto arguments on packet socket.
Verify that packet sockets require the destination address specify an
interface.

PiperOrigin-RevId: 627865233
2024-04-24 15:14:39 -07:00
Bruno Dal BoandgVisor bot d046117f27 Use infinite timeouts for Fuchsia in syscall test
PiperOrigin-RevId: 592592906
2023-12-20 10:17:09 -08:00
Alex KonradiandgVisor bot 6f08b9a49d Add a test for double RX on socket with ETH_P_ALL
Add a syscall test that asserts that a packet socket bound with protocol
ETH_P_ALL will receive outgoing and incoming frames, even for frames sent over
the loopback interface.

PiperOrigin-RevId: 529436921
2023-05-04 09:53:54 -07:00
Nick BrownandgVisor bot 2152501c3f Align stack variables in RebindProtocol test
Previously, this test read packets directly into the stack memory of a packed
struct. Since the ethernet header is not 8-byte aligned, this can cause UB on
CPUs requiring 8-byte alignment. Resolve this issue by copying each segment of
the packet into separate stack variables.

PiperOrigin-RevId: 477996715
2022-09-30 08:16:04 -07:00
Nick BrownandgVisor bot 6527b6e865 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 GowripalanandgVisor bot 1e07f9fa87 Run packet socket tests on Fuchsia
Bug: https://fxbug.dev/81592
PiperOrigin-RevId: 405710156
2021-10-26 12:41:16 -07:00
Ghanan GowripalanandgVisor bot 40c92574f7 Support getsockname for packet sockets
Updates #6621

PiperOrigin-RevId: 397898852
2021-09-20 19:37:57 -07:00
Ghanan GowripalanandgVisor bot aa6a3a3fc2 Do not allow unbinding network protocol
Once a packet socket is bound to a network protocol, it cannot be
unbound from that protocol; the network protocol binding may only be
updated to a different network protocol.

To comply with Linux.

PiperOrigin-RevId: 397810878
2021-09-20 12:17:13 -07:00
Ghanan GowripalanandgVisor bot 968697b374 Allow rebinding packet socket protocol
...to change the network protocol a packet socket may receive packets
from.

This CL is a portion of an originally larger CL that was split with
https://github.com/google/gvisor/commit/ce7fd9a651c6f8ad81db3fbb654d6aed227a9b77
being the dependent CL. That CL (accidentally) included the change in
the endpoint's `afterLoad` method to take the required lock when
accessing the endpoint's netProto field. That change should have been in
this CL.

The CL that made the change mentioned in the commit message is
cl/396946187.

PiperOrigin-RevId: 397412582
2021-09-17 15:37:08 -07:00
Ghanan GowripalanandgVisor bot aa715a7e77 Allow creating packet socket bound to any protocol
...even protocols the stack is unaware of.

While I am here, annotate checklocks on stack.packetEndpointList.

PiperOrigin-RevId: 397226754
2021-09-16 20:06:26 -07:00
Ghanan GowripalanandgVisor bot f48fd50d8d Rename packet_socket to packet_socket_dgram
...so that a later change can add a new packet_socket syscall test
target that holds raw/dgram packet socket generic common tests. The
current packet_socket syscall test target holds tests specific to
dgram packet sockets.

While I am here, remove the defines for the packet_socket_raw_test
target as no code is guarded with `__linux__` in the target's sources.

PiperOrigin-RevId: 397217761
2021-09-16 18:56:08 -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
Fabricio VoznikaandgVisor bot 560091c177 Redirect TODO to GitHub issues
PiperOrigin-RevId: 323715260
2020-07-28 21:24:26 -07:00
Bhasker HariharanandgVisor bot 0c2660fe24 Support for receiving outbound packets in AF_PACKET.
Updates #173

PiperOrigin-RevId: 322665518
2020-07-22 15:33:33 -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
gVisor bot 8e01fc6fda Merge pull request #1975 from nybidari:iptables
PiperOrigin-RevId: 300362789
2020-03-11 11:02:04 -07:00
Nayana BidariandgVisor bot da9d0e2734 Fix panic caused by invalid address for Bind in packet sockets.
PiperOrigin-RevId: 298476533
2020-03-02 16:31:52 -08:00
Nayana BidariandgVisor bot 7ced923c9a Internal change.
PiperOrigin-RevId: 297638665
2020-02-27 11:00:41 -08:00
Kevin KrakauerandgVisor bot 10d3ab4965 Add check for proper settings to AF_PACKET tests.
As in packet_socket_raw.cc, we should check that certain proc files are set
correctly.

PiperOrigin-RevId: 276384534
2019-10-23 17:21:12 -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 1f0a095a56 Add tests for "cooked" AF_PACKET sockets.
PiperOrigin-RevId: 263666789
2019-08-15 16:31:35 -07:00