Commit Graph
177 Commits
Author SHA1 Message Date
Andrei VaginandgVisor bot d92524febd inet: each socket has to hold a reference to its network namespace
Otherwise a network namespace can be destroyed before sockets.

Reported-by: [email protected]
PiperOrigin-RevId: 503552997
2023-01-20 17:10:58 -08:00
Ayush RanjanandgVisor bot 1003ae8e93 Delete VFS1 completely.
- Delete pkg/sentry/fs/*.
- Move pkg/sentry/fs/fsutil out of VFS1 directory and remove VFS1 components.
- Remove remaining unused references to VFS1 from remaining codebase.
- Rename/refactor code to avoid even referencing VFS2, unless necessary.
- Rewrite VFS1-only tests to VFS2.

Updates #1624

PiperOrigin-RevId: 490064269
2022-11-21 13:57:52 -08:00
Alex KonradiandgVisor bot 64ec9af8de Add counters for dropped neighbor advertisements
Add counters for when neighbor advertisements are ignored, either because they
don't correspond to a known neighbor cache entry or because they contain an
unexpected source address.

Fixes #8053

PiperOrigin-RevId: 479428582
2022-10-06 15:36:32 -07:00
Nicolas LacasseandgVisor bot 67a6a781b9 Stop emitting unimplemented events from get/setsockopt.
These are of dubious value, and can often flood user's console with errors.

Fixes #8011

PiperOrigin-RevId: 478537513
2022-10-03 10:18:41 -07:00
Lucas ManningandgVisor bot 57f173fcec Refactor netstack to use bufferv2 instead of buffer.
This change has significant performance implications. bufferv2 is reference
counted and pooled, which alleviates heap/GC pressure. Below are the results
from running the iperf benchmark.

HEAD:
BenchmarkIperf/operation.Upload-16    1552  ns/op   46.6GiB total allocations
BenchmarkIperf/operation.Download-16  1114  ns/op   68.6GiB total allocations

w/ change:
BenchmarkIperf/operation.Upload-16    1139  ns/op (-27%)   1.41GiB total allocations (-97%)
BenchmarkIperf/operation.Download-16  753.2 ns/op (-33%)   706MiB  total allocations (-99%)

PiperOrigin-RevId: 462453185
2022-07-21 13:09:31 -07:00
Ghanan GowripalanandgVisor bot 264384ae47 Track packets dropped by full device TX queue
QDisc/LinkEndpoint may drop packets if the device's send/transmit queue
is full.

BUG: https://fxbug.dev/98974
PiperOrigin-RevId: 448570489
2022-05-13 13:54:14 -07:00
Ghanan GowripalanandgVisor bot d2a2d74aa9 Use different flags for IPV6_RECVERR and IP_RECVERR
PiperOrigin-RevId: 446361103
2022-05-03 21:17:40 -07:00
Nayana BidariandgVisor bot b1efed29d0 Silence the error log message for SO_RCVLOWAT option.
Removed the unimplemented syscall message for SO_RCVLOWAT option and added a
test for {g,s}etsockopt.

PiperOrigin-RevId: 438145815
2022-03-29 15:48:33 -07:00
Arthur SfezandgVisor bot 4dbf587b07 Support sending TTL and HopLimit
PiperOrigin-RevId: 430554985
2022-02-23 15:40:37 -08:00
Arthur SfezandgVisor bot e86854ee93 Rename ControlMessages type to indicate the cmsg direction
With the introduction of sendable control messages, the original cmsg type
is now renamed to ReceivableControlMessages.

PiperOrigin-RevId: 430319598
2022-02-22 16:18:16 -08:00
Arthur SfezandgVisor bot 1d2822917b Support receiving ttl/hoplimit control message
PiperOrigin-RevId: 429096959
2022-02-16 11:27:21 -08:00
Jing ChenandgVisor bot 39c266c680 Use network protocol default ttl instead of a hardcoded one.
PiperOrigin-RevId: 423886874
2022-01-24 12:46:25 -08:00
Ghanan GowripalanandgVisor bot d70f047d3c Support SOL_IPV6 -> IPV6_CHECKSUM
PiperOrigin-RevId: 419164074
2021-12-31 21:33:15 -08:00
Arthur SfezandgVisor bot 775e87ded0 Use protocol-specific options for TTL/HopLimit
The new HopLimit matches the IPV6_UNICAST_HOPS socket option.

Updates #6389

PiperOrigin-RevId: 418831844
2021-12-29 12:33:48 -08:00
Ghanan GowripalanandgVisor bot f8a4c41088 Support SOL_ICMPV6 -> ICMPV6_FILTER
PiperOrigin-RevId: 417696519
2021-12-21 15:04:13 -08:00
Ghanan GowripalanandgVisor bot 413428659d Fix error getting IPv6 option on IPv4 socket
Previously returned ENOPROTOOPT but should return EOPNOTSUPP to match
Linux.

PiperOrigin-RevId: 416680620
2021-12-15 17:12:04 -08:00
Fabricio VoznikaandgVisor bot cecd7315bc Don't eat error from epoll_ctl EPOLL_CTL_ADD
Docker maps stdin to `/dev/null` which doesn't support epoll. Host FD
was ignoring the error and suceeding the epoll_ctl call from the
container, giving false impressing that epoll would be notified.

This required plumbing failure to all waiter.Waitable.EventRegister
callers and implementers.

Closes #6795

PiperOrigin-RevId: 414797621
2021-12-07 12:36:00 -08:00
Nayana BidariandgVisor bot 0a880cb66a Increment spurious recovery metric only for RTO.
PiperOrigin-RevId: 413504208
2021-12-01 14:00:10 -08:00
Kevin KrakauerandgVisor bot ab738852bf Automated rollback of changelist 407638912
PiperOrigin-RevId: 410665707
2021-11-17 17:07:05 -08:00
Adin ScannellandgVisor bot 4967b16af9 Update Waitable API.
Instead of passing the event mask at registratrion time, pass the mask as part
of the waiter. This makes the mask immutable and simplifies the architecture of
waiters. This is also necessary for a future fix that will allow the fdnotifier
to keep persistent entries, as opposed to requiring constant updates.

This change is intended to be a no-op in terms of function. The only exception
is signalfd, where this mask was abused. To handle this case, the operation of
signalfd changed to allow one layer of indirection.

PiperOrigin-RevId: 409702998
2021-11-13 12:54:39 -08:00
Ayush RanjanandgVisor bot c7f074fc3b Make {Un}Marshal{Bytes/Unsafe} return remaining buffer.
Change marshal.Marshallable method signatures to return the remaining buffer.
This makes it easier to implement these method manually. Without this, we would
have to manually do buffer shifting which is error prone.

tools/go_marshal/test:benchmark test does not show change in performance.
Additionally fixed some marshalling bugs in fsimpl/fuse.

Updated multiple callpoints to get rid of redundant slice indexing work and
simplified code using this new signature.

Updates #6450

PiperOrigin-RevId: 407857019
2021-11-05 10:43:49 -07:00
Zach KoopmansandgVisor bot de731b1d1a [syserr] Reverse dependency for tcpip.Error
PiperOrigin-RevId: 407638912
2021-11-04 12:11:41 -07:00
Nick BrownandgVisor bot e5fd6b7f1e Record counts of packets with unknown L3/L4 numbers
Previously, we recorded a single aggregated count. These per-protocol counts
can help us debug field issues when frames are dropped for this reason.

PiperOrigin-RevId: 405913911
2021-10-27 10:06:55 -07:00
Nayana BidariandgVisor bot 8e2a604cbb Add a new metric to detect the number of spurious loss recoveries.
- Implements RFC 3522 (Eifel detection algorithm) to detect if the connection
entered loss recovery unnecessarily.
- Added a new metric to count the total number of spurious loss recoveries.
- Added tests to verify the new metric.

PiperOrigin-RevId: 401637359
2021-10-07 16:51:06 -07:00
Tamir DubersteinandgVisor bot 6808bf0c45 Store timestamps as time.Time
Rather than boiling down to an integer eagerly, do it as late as possible.

PiperOrigin-RevId: 401599308
2021-10-07 14:04:55 -07:00
Ghanan GowripalanandgVisor bot 44f496d24f Support IPV6_RECVPKTINFO on UDP sockets
PiperOrigin-RevId: 397631833
2021-09-19 13:15:28 -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 cd0623bfd5 [bind] Return EINVAL for under sized address
...and EAFNOSUPPORT for unexpected address family.

To comply with Linux.

Updates #6021, #6575.

PiperOrigin-RevId: 396893590
2021-09-15 12:20:51 -07:00
Ghanan GowripalanandgVisor bot aac9bf4df7 Extract network datagram endpoint common facilities
...from the UDP endpoint.

Datagram-based transport endpoints (e.g. UDP, RAW IP) can share a lot
of their write path due to the datagram-based nature of these endpoints.
Extract the common facilities from UDP so they can be shared with other
transport endpoints (in a later change).

Test: UDP syscall tests.
PiperOrigin-RevId: 394347774
2021-09-01 17:12:24 -07:00
Zach KoopmansandgVisor bot 83bf514e27 [syserror] Remove pkg syserror.
Removes package syserror and moves still relevant code to either linuxerr
or to syserr (to be later removed).

Internal errors are converted from random types to *errors.Error types used
in linuxerr. Internal errors are in linuxerr/internal.go.

PiperOrigin-RevId: 390724202
2021-08-13 17:16:52 -07:00
Zach KoopmansandgVisor bot f26a93e634 [syserror] Convert remaining syserror definitions to linuxerr.
Convert remaining public errors (e.g. EINTR) from syserror to linuxerr.

PiperOrigin-RevId: 390471763
2021-08-12 15:19:12 -07:00
Nayana BidariandgVisor bot 4c2ada7a36 Add metric to count number of segments acknowledged by DSACK.
- Creates new metric "/tcp/segments_acked_with_dsack" to count the number of
segments acked with DSACK.
- Added check to verify the metric is getting incremented when a DSACK is sent
in the unit tests.

PiperOrigin-RevId: 386135949
2021-07-21 18:06:31 -07:00
Kevin KrakauerandgVisor bot 2b42259663 netstack: support SO_RCVBUFFORCE
TCP is fully supported. As with SO_RCVBUF, other transport protocols perform
no-ops per DefaultSocketOptionsHandler.OnSetReceiveBufferSize.

PiperOrigin-RevId: 385023239
2021-07-15 15:34:34 -07:00
Kevin KrakauerandgVisor bot acbc1a1ab9 netstack: move SO_SNDBUF/RCVBUF clamping logic out of //pkg/tcpip
- Keeps Linux-specific behavior out of //pkg/tcpip
- Makes it clearer that clamping is done only for setsockopt calls from users
- Removes code duplication

PiperOrigin-RevId: 384389809
2021-07-12 22:37:11 -07:00
Zach KoopmansandgVisor bot 5e6d494c2f [syserror] Update syserror to linuxerr for more errors.
Update the following from syserror to the linuxerr equivalent:
EEXIST
EFAULT
ENOTDIR
ENOTTY
EOPNOTSUPP
ERANGE
ESRCH

PiperOrigin-RevId: 384329869
2021-07-12 15:26:20 -07:00
Zach KoopmansandgVisor bot 45b64220cb [syserror] Add conversions to linuxerr with temporary Equals method.
Add Equals method to compare syserror and unix.Errno errors to linuxerr errors.
This will facilitate removal of syserror definitions in a followup, and
finding needed conversions from unix.Errno to linuxerr.

PiperOrigin-RevId: 380909667
2021-06-22 15:53:32 -07:00
Zach KoopmansandgVisor bot 3b0fa805bb [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
Kevin KrakauerandgVisor bot 3f4848e039 Cleanup iptables bug TODOs
There are many references to unimplemented iptables features that link to #170,
but that bug is about Istio support specifically. Istio is supported, so the
references should change.

Some TODOs are addressed, some removed because they are not features requested
by users, and some are left as implementation notes.

Fixes #170.

PiperOrigin-RevId: 379328488
2021-06-14 12:26:29 -07:00
Nicolas LacasseandgVisor bot fe75eba8f9 Remove unsupported syscall event for setsockopt(*, SOL_SOCKET, SO_OOBINLINE).
Netstack behaves as if SO_OOBINLINE is always set, and was logging an
unsupported syscall event if the app tries to disable it. We don't have a real
use case for TCP urgent mechanisms (and RFC6093 says apps SHOULD NOT use it).

This CL keeps the current behavior, but removes the unsupported syscall event.

Fixes #6123

PiperOrigin-RevId: 378026059
2021-06-07 16:01:48 -07:00
Arthur SfezandgVisor bot 2add8baf49 Add aggregated NIC stats
This change also includes miscellaneous improvements:
* UnknownProtocolRcvdPackets has been separated into two stats, to
specify at which layer the unknown protocol was found (L3 or L4)
* MalformedRcvdPacket is not aggregated across every endpoint anymore.
Doing it this way did not add useful information, and it was also error-prone
(example: ipv6 forgot to increment this aggregated stat, it only
incremented its own ipv6.MalformedPacketsReceived). It is now only incremented
 the NIC.
* Removed TestStatsString test which was outdated and had no real
utility.

PiperOrigin-RevId: 375057472
2021-05-21 04:27:41 -07:00
Arthur SfezandgVisor bot 7de24c4aed Clean-up netstack metrics descriptions
PiperOrigin-RevId: 375051638
2021-05-21 03:31:28 -07:00
Mithun IyerandgVisor bot 6f5e12ccc0 Add protocol state to TCPINFO
Add missing protocol state to TCPINFO struct and update packetimpact.
This re-arranges the TCP state definitions to align with Linux.

Fixes #478

PiperOrigin-RevId: 374996751
2021-05-20 19:15:49 -07:00
Nick BrownandgVisor bot 2d8f175f0d Send ICMP errors when link address resolution fails
Before this change, we would silently drop packets when link resolution
failed. This change brings us into line with RFC 792 (IPv4) and RFC 4443 (IPv6),
both of which specify that gateways should return an ICMP error to the sender
when link resolution fails.

PiperOrigin-RevId: 374699789
2021-05-19 12:13:09 -07:00
Nick BrownandgVisor bot a8d8fdefa9 Send ICMP errors when unable to forward fragmented packets
Before this change, we would silently drop packets when the packet was too
big to be sent out through the NIC (and, for IPv4 packets, if DF was set).
This change brings us into line with RFC 792 (IPv4) and RFC 4443 (IPv6),
both of which specify that gateways should return an ICMP error to the sender
when the packet can't be fragmented.

PiperOrigin-RevId: 373480078
2021-05-12 16:53:43 -07:00
Zach KoopmansandgVisor bot 6aff7402c9 [syserror] Refactor abi/linux.Errno
PiperOrigin-RevId: 373265454
2021-05-11 17:23:08 -07:00
Nick BrownandgVisor bot d8b01e5404 Process Hop-by-Hop header when forwarding IPv6 packets
Currently, we process IPv6 extension headers when receiving packets
but not when forwarding them. This is fine for the most part, with
with one exception: RFC 8200 requires that we process the
Hop-by-Hop headers even while forwarding packets.

This CL adds that support by invoking the Hop-by-hop logic performed
when receiving packets during forwarding as well.

PiperOrigin-RevId: 373145478
2021-05-11 07:25:56 -07:00
Nick BrownandgVisor bot 2c72733e19 Send ICMP errors when the network is unreachable
Before this change, we would silently drop packets when unable to determine a
route to the destination host. This change brings us into line with RFC 792
(IPv4) and RFC 4443 (IPv6), both of which specify that gateways should return
an ICMP error to the sender when unable to reach the destination.

Startblock:
  has LGTM from asfez
  and then
  add reviewer ghanan
PiperOrigin-RevId: 372214051
2021-05-05 14:58:42 -07:00
Rahat MahmoodandgVisor bot 3246444f6f Remove uses of the binary package from networking code.
Co-Author: ayushranjan
PiperOrigin-RevId: 370785009
2021-04-27 16:20:01 -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
Kevin KrakauerandgVisor bot 191ec0ca3a Enlarge port range and fix integer overflow
Also count failed TCP port allocations

PiperOrigin-RevId: 368939619
2021-04-16 16:28:56 -07:00