Commit Graph

20 Commits

Author SHA1 Message Date
Ting-Yu Wang e5f58e89bb Make AsSockAddr() to replace reinterpret_cast<sockaddr*>
It's a common pattern in test code to reinterpret_cast<sockaddr*> from
sockaddr_* structs. Make AsSockAddr() for them so code looks better.

Note: Why not a wrapper type for `sockaddr_storage` and etc?
It's also a common need to have a local in-out variable of socklen_t.
Creating a wrapper type may however lead to this wrong code:
  Wrapper addr;
  socklen_t addrlen = sizeof(addr);
where sizeof(Wrapper) may not equal to sizeof(sockaddr_storage).
PiperOrigin-RevId: 368126229
2021-04-12 18:35:09 -07:00
Ting-Yu Wang ec9e263f21 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: syzbot+b550e78e5c24d1d521f2@syzkaller.appspotmail.com
PiperOrigin-RevId: 352091286
2021-01-15 15:10:27 -08:00
Ghanan Gowripalan abe9d9f67f Support add/remove IPv6 multicast group sock opt
IPv4 was always supported but UDP never supported joining/leaving IPv6
multicast groups via socket options.

Add: IPPROTO_IPV6, IPV6_JOIN_GROUP/IPV6_ADD_MEMBERSHIP
Remove: IPPROTO_IPV6, IPV6_LEAVE_GROUP/IPV6_DROP_MEMBERSHIP

Test: integration_test.TestUDPAddRemoveMembershipSocketOption
PiperOrigin-RevId: 350396072
2021-01-06 11:41:42 -08:00
Zach Koopmans 634e14a094 Fix socket_ipv4_udp_unbound_loopback_test_linux
Handle "Resource temporarily unavailable" EAGAIN errors with a select
call before calling recvmsg.

Also rename similar helper call from "RecvMsgTimeout" to "RecvTimeout",
because it calls "recv".

PiperOrigin-RevId: 338761695
2020-10-23 16:13:46 -07:00
Zach Koopmans 06dbd5b7bc Fix socket_ipv4_udp_unbound_test_native in opensource.
Calls to recv sometimes fail with EAGAIN, so call select beforehand.

PiperOrigin-RevId: 332943156
2020-09-21 15:06:05 -07:00
Zach Koopmans 5ce5882951 Fix flakes in UdpSocketTest
`recv` calls with MSG_DONTWAIT can fail with EAGAIN randomly
in tests. Fix this by calling `select` on sockets with a timeout
prior to attempting a `recv`.

PiperOrigin-RevId: 332873735
2020-09-21 10:05:45 -07:00
Andrei Vagin 935007937c test: remove 1s delay after non-blocking socket pair accept
It was added in cl/201419897 to deflake
socket_ip_tcp_loopback_non_blocking_test_gvisor.
It seems we don't need this hack, because the origin issue isn't
reproducible without this hack.

PiperOrigin-RevId: 305871748
2020-04-10 07:14:35 -07:00
Jay Zhuang 6de49546cb Refactor syscall tests
- Move shared helpers V4Multicast and V4Broadcast to socket_test_util
- Add unnamed namespace so socket_ipv4_tcp_unbound_external_networking_test.cc
  and socket_ipv4_udp_unbound_external_networking_test.cc can be compiled
  together
- Add test files to "exports_files" so they can be included by Fuchsia's syscall
  test setup

PiperOrigin-RevId: 293880429
2020-02-07 13:19:18 -08:00
Ian Gudger a26a954946 Add socket connection stress test.
Tests 65k connection attempts on common types of sockets to check for port
leaks.

Also fixes a bug where dual-stack sockets wouldn't properly re-queue
segments received while closing.

PiperOrigin-RevId: 293241166
2020-02-04 15:54:49 -08:00
Adin Scannell 2296b47344 Change to standard types.
PiperOrigin-RevId: 290846481
2020-01-21 17:28:57 -08:00
gVisor bot 45a8edbd5a Merge pull request #1492 from majek:err_typo_in_netstack_tests
PiperOrigin-RevId: 290840370
2020-01-21 16:32:49 -08:00
gVisor bot baf4d8aaca Internal change.
PiperOrigin-RevId: 265535438
2019-08-26 14:07:17 -07:00
Kevin Krakauer ef045b914b Add tests for "cooked" AF_PACKET sockets.
PiperOrigin-RevId: 263666789
2019-08-15 16:31:35 -07:00
Rahat Mahmood 05ff1ffaad Implement getsockopt() SO_DOMAIN, SO_PROTOCOL and SO_TYPE.
SO_TYPE was already implemented for everything but netlink sockets.

PiperOrigin-RevId: 253138157
2019-06-13 17:24:51 -07:00
Michael Pratt 4d52a55201 Change copyright notice to "The gVisor Authors"
Based on the guidelines at
https://opensource.google.com/docs/releasing/authors/.

1. $ rg -l "Google LLC" | xargs sed -i 's/Google LLC.*/The gVisor Authors./'
2. Manual fixup of "Google Inc" references.
3. Add AUTHORS file. Authors may request to be added to this file.
4. Point netstack AUTHORS to gVisor AUTHORS. Drop CONTRIBUTORS.

Fixes #209

PiperOrigin-RevId: 245823212
Change-Id: I64530b24ad021a7d683137459cafc510f5ee1de9
2019-04-29 14:26:23 -07:00
Nicolas Lacasse f4ce43e1f4 Allow and document bug ids in gVisor codebase.
PiperOrigin-RevId: 245818639
Change-Id: I03703ef0fb9b6675955637b9fe2776204c545789
2019-04-29 14:04:14 -07:00
Amanda Tait ea070b9d5f Implement Broadcast support
This change adds support for the SO_BROADCAST socket option in gVisor Netstack.
This support includes getsockopt()/setsockopt() functionality for both UDP and
TCP endpoints (the latter being a NOOP), dispatching broadcast messages up and
down the stack, and route finding/creation for broadcast packets. Finally, a
suite of tests have been implemented, exercising this functionality through the
Linux syscall API.

PiperOrigin-RevId: 234850781
Change-Id: If3e666666917d39f55083741c78314a06defb26c
2019-02-20 12:54:13 -08:00
Ian Gudger 85d53d81d9 Use socket address functions in unbound IPv4 UDP tests.
Also switch to the correct casing style for local address variables.

PiperOrigin-RevId: 233161128
Change-Id: Ibc4a10a5d3ab04c40907aa885e8237b255c65a79
2019-02-08 18:23:38 -08:00
Ian Gudger 80f901b16b Plumb IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP to netstack.
Also includes a few fixes for IPv4 multicast support. IPv6 support is coming in
a followup CL.

PiperOrigin-RevId: 233008638
Change-Id: If7dae6222fef43fda48033f0292af77832d95e82
2019-02-07 23:15:23 -08:00
Brian Geffon d3bc79bc84 Open source system call tests.
PiperOrigin-RevId: 224886231
Change-Id: I0fccb4d994601739d8b16b1d4e6b31f40297fb22
2018-12-10 14:42:34 -08:00