Commit Graph

24 Commits

Author SHA1 Message Date
Zeling Feng 611e6e1247 Handle all codes for ICMPv4 destination unreachable message for TCP
Some hosts use iptables and are configured to respond an ICMP destination
unreachable message with a {host/net/admin}prohibited code instead of a RST.
Linux handles these codes correctly by aborting the handshake. This commit
adds handling of all possible codes of an ICMPv4 destination unreachable message
to bring gVisor to parity.

PiperOrigin-RevId: 496703813
2022-12-20 11:07:27 -08:00
Bruno Dal Bo c40f8e3651 Rename ErrNoRoute to ErrHostUnreachable
ErrNoRoute gets translated to EHOSTUNREACH which causes some code paths to
produce different errors unexpectedly. Rename the error so we can clean up some
sites to return ENETUNREACH more clearly where needed.

Updates #8105

PiperOrigin-RevId: 482355099
2022-10-19 18:29:13 -07:00
Nate Hurley 006bbe78ca Implement IPv4 multicast forwarding.
This change implements AddMulticastRoute and the requisite routing logic.
Subsequent changes will still be needed to:

1. Emit events for missing route or unexpected input interface
2. Implement DelRoute
3. Implement GetRouteStats

Updates #7338.

PiperOrigin-RevId: 451026594
2022-05-25 15:18:13 -07:00
Kevin Krakauer ce194f2c1c Automated rollback of changelist 407638912
PiperOrigin-RevId: 410665707
2021-11-17 17:07:05 -08:00
Zach Koopmans 23a115dae8 [syserr] Reverse dependency for tcpip.Error
PiperOrigin-RevId: 407638912
2021-11-04 12:11:41 -07:00
Zach Koopmans 63b4f6e296 [syserror] Refactor linuxerr and error package.
Move Error struct to pkg/errors package for use in multiple places.
Move linuxerr static definitions under pkg/errors/linuxerr.
Add a lookup list for quick lookup of *errors.Error by errno. This is useful
when converting syserror errors and unix.Errno/syscall.Errrno values to
*errors.Error.
Update benchmarks routines to include conversions.

The below benchmarks show *errors.Error usage to be comparable to using
unix.Errno.

BenchmarkAssignUnix
BenchmarkAssignUnix-32                 	787875022	         1.284 ns/op
BenchmarkAssignLinuxerr
BenchmarkAssignLinuxerr-32             	1000000000	         1.209 ns/op
BenchmarkAssignSyserror
BenchmarkAssignSyserror-32             	759269229	         1.429 ns/op
BenchmarkCompareUnix
BenchmarkCompareUnix-32                	1000000000	         1.310 ns/op
BenchmarkCompareLinuxerr
BenchmarkCompareLinuxerr-32            	1000000000	         1.241 ns/op
BenchmarkCompareSyserror
BenchmarkCompareSyserror-32            	147196165	         8.248 ns/op
BenchmarkSwitchUnix
BenchmarkSwitchUnix-32                 	373233556	         3.664 ns/op
BenchmarkSwitchLinuxerr
BenchmarkSwitchLinuxerr-32             	476323929	         3.294 ns/op
BenchmarkSwitchSyserror
BenchmarkSwitchSyserror-32             	39293408	        29.62 ns/op
BenchmarkReturnUnix
BenchmarkReturnUnix-32                 	1000000000	         0.5042 ns/op
BenchmarkReturnLinuxerr
BenchmarkReturnLinuxerr-32             	1000000000	         0.8152 ns/op
BenchmarkConvertUnixLinuxerr
BenchmarkConvertUnixLinuxerr-32        	739948875	         1.547 ns/op
BenchmarkConvertUnixLinuxerrZero
BenchmarkConvertUnixLinuxerrZero-32    	977733974	         1.489 ns/op

PiperOrigin-RevId: 379806801
2021-06-16 14:08:52 -07:00
Zach Koopmans 49eb3da98a [syserror] Refactor abi/linux.Errno
PiperOrigin-RevId: 373265454
2021-05-11 17:23:08 -07:00
Kevin Krakauer abbdcebc54 Implement /proc/sys/net/ipv4/ip_local_port_range
Speeds up the socket stress tests by a couple orders of magnitude.

PiperOrigin-RevId: 361721050
2021-03-08 20:40:34 -08:00
Kevin Krakauer c39284f457 Let sentry understand tcpip.ErrMalformedHeader
Added a LINT IfChange/ThenChange check to catch this in the future.

PiperOrigin-RevId: 357077564
2021-02-11 16:01:43 -08:00
Tamir Duberstein 8d1afb4185 Change tcpip.Error to an interface
This makes it possible to add data to types that implement tcpip.Error.
ErrBadLinkEndpoint is removed as it is unused.

PiperOrigin-RevId: 354437314
2021-01-28 17:59:58 -08:00
Ghanan Gowripalan 25b5ec7135 Do not resolve remote link address at transport layer
Link address resolution is performed at the link layer (if required) so
we can defer it from the transport layer. When link resolution is
required, packets will be queued and sent once link resolution
completes. If link resolution fails, the transport layer will receive a
control message indicating that the stack failed to route the packet.

tcpip.Endpoint.Write no longer returns a channel now that writes do not
wait for link resolution at the transport layer.

tcpip.ErrNoLinkAddress is no longer used so it is removed.

Removed calls to stack.Route.ResolveWith from the transport layer so
that link resolution is performed when a route is created in response
to an incoming packet (e.g. to complete TCP handshakes or send a RST).

Tests:
- integration_test.TestForwarding
- integration_test.TestTCPLinkResolutionFailure

Fixes #4458

RELNOTES: n/a
PiperOrigin-RevId: 351684158
2021-01-13 16:04:33 -08:00
Ting-Yu Wang b1de1da318 netstack: Refactor tcpip.Endpoint.Read
Read now takes a destination io.Writer, count, options. Keeping the method name
Read, in contrast to the Write method.

This enables:
* direct transfer of views under VV
* zero copy

It also eliminates the need for sentry to keep a slice of view because
userspace had requested a read that is smaller than the view returned, removing
the complexity there.

Read/Peek/ReadPacket are now consolidated together and some duplicate code is
removed.

PiperOrigin-RevId: 350636322
2021-01-07 14:17:18 -08:00
Ayush Ranjan 45619ded38 [netstack] Make tcpip.Error savable.
Earlier we could not save tcpip.Error objects in structs because upon restore
the constant's address changes in netstack's error translation map and
translating the error would panic because the map is based on the address of the
tcpip.Error instead of the error itself.

Now I made that translations map use the error message as key instead of the
address. Added relevant synchronization mechanisms to protect the structure
and initialize it upon restore.

PiperOrigin-RevId: 346590485
2020-12-09 15:55:12 -08:00
Bhasker Hariharan 857d03f258 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
Andrei Vagin 116cac053e netstack/udp: connect with the AF_UNSPEC address family means disconnect
PiperOrigin-RevId: 256433283
2019-07-03 14:19:02 -07:00
Adin Scannell add40fd6ad Update canonical repository.
This can be merged after:
https://github.com/google/gvisor-website/pull/77
  or
https://github.com/google/gvisor-website/pull/78

PiperOrigin-RevId: 253132620
2019-06-13 16:50:15 -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
Kevin Krakauer 43dff57b87 Make raw sockets a toggleable feature disabled by default.
PiperOrigin-RevId: 245511019
Change-Id: Ia9562a301b46458988a6a1f0bbd5f07cbfcb0615
2019-04-26 16:51:46 -07:00
Ian Gudger 56a6128295 Implement IP_MULTICAST_LOOP.
IP_MULTICAST_LOOP controls whether or not multicast packets sent on the default
route are looped back. In order to implement this switch, support for sending
and looping back multicast packets on the default route had to be implemented.

For now we only support IPv4 multicast.

PiperOrigin-RevId: 237534603
Change-Id: I490ac7ff8e8ebef417c7eb049a919c29d156ac1c
2019-03-08 15:49:17 -08: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 8fce67af24 Use correct company name in copyright header
PiperOrigin-RevId: 217951017
Change-Id: Ie08bf6987f98467d07457bcf35b5f1ff6e43c035
2018-10-19 16:35:11 -07:00
Michael Pratt ddb34b3690 Enforce message size limits and avoid host calls with too many iovecs
Currently, in the face of FileMem fragmentation and a large sendmsg or
recvmsg call, host sockets may pass > 1024 iovecs to the host, which
will immediately cause the host to return EMSGSIZE.

When we detect this case, use a single intermediate buffer to pass to
the kernel, copying to/from the src/dst buffer.

To avoid creating unbounded intermediate buffers, enforce message size
checks and truncation w.r.t. the send buffer size. The same
functionality is added to netstack unix sockets for feature parity.

PiperOrigin-RevId: 216590198
Change-Id: I719a32e71c7b1098d5097f35e6daf7dd5190eff7
2018-10-10 14:10:17 -07:00
Ian Gudger a8d7cee3e8 Fix sendto for dual stack UDP sockets
Previously, dual stack UDP sockets bound to an IPv4 address could not use
sendto to communicate with IPv4 addresses. Further, dual stack UDP sockets
bound to an IPv6 address could use sendto to communicate with IPv4 addresses.
Neither of these behaviors are consistent with Linux.

PiperOrigin-RevId: 197036024
Change-Id: Ic3713efc569f26196e35bb41e6ad63f23675fc90
2018-05-17 12:50:22 -07:00
Googler d02b74a5dc Check in gVisor.
PiperOrigin-RevId: 194583126
Change-Id: Ica1d8821a90f74e7e745962d71801c598c652463
2018-04-28 01:44:26 -04:00