29 Commits
Author SHA1 Message Date
Parth SarthiandgVisor bot 8832ee45a6 udp: Trim packet to header.length.
PiperOrigin-RevId: 958816031
2026-08-03 23:27:57 -07:00
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
Shailend ChandandgVisor bot 888c8f0a3a Deny SOL_IP socket options for raw AF_INET6 sockets
PiperOrigin-RevId: 813907049
2025-10-01 14:13:01 -07:00
Ayush RanjanandgVisor bot 160fba469d Ensure RST TCP flag is set in raw socket tests.
Without this flag, the TCP stack will generate RST packets which will lead to
unexpected results.

PiperOrigin-RevId: 574936122
2023-10-19 11:06:43 -07:00
Ayush RanjanandgVisor bot 8efec607d2 Additionally expect the custom tos/tclass in TOS_TCLASS_EXPECT_DEFAULT case.
PiperOrigin-RevId: 565458888
2023-09-14 13:25:12 -07:00
Nicolas LacasseandgVisor bot 704b8d9ee8 hostinet: Support ping and raw sockets.
PiperOrigin-RevId: 513902015
2023-03-04 00:40:01 -08:00
Arthur SfezandgVisor bot 4dbf587b07 Support sending TTL and HopLimit
PiperOrigin-RevId: 430554985
2022-02-23 15:40:37 -08:00
Arthur SfezandgVisor bot 1d2822917b Support receiving ttl/hoplimit control message
PiperOrigin-RevId: 429096959
2022-02-16 11:27:21 -08:00
Arthur SfezandgVisor bot 7ea73a6830 Support receiving PKTINFO on icmp endpoints
PiperOrigin-RevId: 428599075
2022-02-14 13:51:49 -08:00
Ghanan GowripalanandgVisor bot 2917892679 Support SO_BINDTODEVICE on raw endpoints
PiperOrigin-RevId: 428056402
2022-02-11 11:59:05 -08:00
Arthur SfezandgVisor bot 60f5caa026 Add TOS control message for ICMP & RAW sockets
PiperOrigin-RevId: 426208980
2022-02-03 12:19:06 -08:00
Ghanan GowripalanandgVisor bot d70f047d3c Support SOL_IPV6 -> IPV6_CHECKSUM
PiperOrigin-RevId: 419164074
2021-12-31 21:33:15 -08:00
Ghanan GowripalanandgVisor bot 144857e87b Support IP_PKTINFO and IPV6_RECVPKTINFO on raw sockets
Updates #1584, #3556.

PiperOrigin-RevId: 402354066
2021-10-11 11:46:54 -07:00
Ghanan GowripalanandgVisor bot d153bfee9f Don't use SOL_UDP when creating sockets
SOL_UDP is used when get/set-ing socket options to specify the socket
level. When creating normal UDP sockets, the protocol need not be
specified. When creating RAW IP sockets for UDP, use IPPROTO_UDP.

PiperOrigin-RevId: 396675986
2021-09-14 14:03:53 -07:00
Ghanan GowripalanandgVisor bot 516f91a497 Accept packets destined to bound address
...if bound to an address.

We previously checked the source of a packet instead of the destination
of a packet when bound to an address.

PiperOrigin-RevId: 396497647
2021-09-13 19:42:55 -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 ce9e1f795a Run raw IP socket syscall 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 raw IP sockets may
  be created.

PiperOrigin-RevId: 389663218
2021-08-09 10:20:21 -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
Ghanan GowripalanandgVisor bot c326f23d5b Expose local address from raw sockets
PiperOrigin-RevId: 385940836
2021-07-20 22:50:16 -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
Nayana BidariandgVisor bot 83448813a5 Fix error code for connect in raw sockets.
PiperOrigin-RevId: 347650354
2020-12-15 11:07:48 -08:00
Nayana BidariandgVisor bot df60ee40d3 Fix panic when IPv4 address is used in sendmsg for IPv6 sockets
We do not rely on error for getsockopt options(which have boolean values)
anymore. This will cause issue in sendmsg where we used to return error
for IPV6_V6Only option. Fix the panic by returning error (for sockets other
than TCP and UDP) if the address does not match the type(AF_INET/AF_INET6) of
the socket.

PiperOrigin-RevId: 347063838
2020-12-11 13:31:28 -08: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
Bhasker HariharanandgVisor bot febf9e38f7 Fix wildcard bind for raw socket.
Fixes #3334

PiperOrigin-RevId: 322846384
2020-07-23 12:54:12 -07:00
Bhasker HariharanandgVisor bot 0812cae4d1 Stub out SO_DETACH_FILTER.
Updates #2746

PiperOrigin-RevId: 320757963
2020-07-11 06:22:47 -07:00
Kevin KrakauerandgVisor bot 0fb512e986 IPv6 raw sockets. Needed for ip6tables.
IPv6 raw sockets never include the IPv6 header.

PiperOrigin-RevId: 318582989
2020-06-26 19:07:02 -07:00