62 Commits

Author SHA1 Message Date
Jamie Liu e23347e5b5 Move //pkg/sentry/kernel/time to //pkg/sentry/ktime.
This avoids needing to rename it everywhere it's imported.

PiperOrigin-RevId: 693930089
2024-11-06 18:13:51 -08:00
Nicolas Lacasse 876de08e59 Fix strace logging for AF_UNIX sockets.
This was broken in commit 64268c8, which moved parsing of addresses for
AF_UNIX sockets to the socket/unix package.

While we're here, add strace support for AF_PACKET sockets, since
socket.AddressAndFamily can already decode their address.

PiperOrigin-RevId: 661391690
2024-08-09 13:54:10 -07:00
Ghanan Gowripalan a055645a79 Don't hold link address in tcpip.Address
All tcpip.Endpoints use a tcpip.FullAddress to hold addresses associated
with an outgoing or incoming packet, but the struct only had a field for
a tcpip.Address. This field was overloaded to also hold a link address
(which is normally held in a tcpip.LinkAddress). This worked relatively
fine until the change to make addresses opaque types.

commit 64268c8483 required the use of a
workaround to continue passing around link addresses through the
tcpip.Address field. This workaround requires assumptions about the
size of the hardware address and unncessary jumping-through-hoops.

This change just introduces a new field to tcpip.FullAddress with type
tcpip.LinkAddress that can hold link addresses and this new field will
be used by packet endpoints.

The change referenced above is cl/532284732.

PiperOrigin-RevId: 536561363
2023-05-30 18:14:32 -07:00
Kevin Krakauer 64268c8483 netstack: make tcpip.Address an opaque type
The important change here is in tcpip/tcpip.go, where tcpip.Address is defined.
The rest is updating uses of tcpip.Address.

This is preparation for netip.Addr or []byte based addresses, which should save
us a bunch of allocations. Currently, we allocate every time we want to, say,
get a tcpip.Address from a header. This is because the header is a byte slice,
but Address is a string. Strings are immutable, so Go allocates and copies.

PiperOrigin-RevId: 532284732
2023-05-15 18:07:03 -07:00
Kevin Krakauer 8478fe0a27 stop using tcpip.FullAddress with unix sockets
It's unnecessarily overloading the type, which makes it hard to change the type
in netstack.

PiperOrigin-RevId: 526168235
2023-04-21 16:48:37 -07:00
Nicolas Lacasse e4ece21634 hostinet: Implement packet sockets.
Two of the tests are still disabled for now. There is an existing issue with
poll in hostinet that I need to look into.

PiperOrigin-RevId: 513936838
2023-03-04 00:48:57 -08:00
Nicolas Lacasse c020e2de83 Move netstack's isTCP/UDP/ICMPSocket methods into socket package.
They are useful across other socket implementations.

PiperOrigin-RevId: 510699847
2023-02-18 13:27:45 -08:00
Ayush Ranjan 1fa3c06f1e 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
Nicolas Lacasse 4761bf4537 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
Kevin Krakauer 370672e989 prohibit direct use of sync/atomic (u)int64 functions
All atomic 64 bit ints are changed to atomicbitops.(Ui|I)nt64. A nogo checker
enforces that sync/atomic 64 bit functions are not called.

For reviewers: the interesting changes are in the atomicbitops and checkaligned
packages.

Why do this?
- It is very easy to accidentally use atomic values without sync/atomic funcs.
- We have checkatomics, but this is optional and is forgotten in several places.
  - Using a type+checker to enforce this seems less error prone and simpler.
- We get NoCopy protection.
- Use of 64 bit atomics can break 32 bit builds. We have types to handle this
  without any runtime cost, so we might as well use them.

PiperOrigin-RevId: 440473398
2022-04-08 16:06:26 -07:00
Nayana Bidari 007a91a911 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 Sfez 9d5239e714 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 Sfez 86ad7d5b58 Support receiving ttl/hoplimit control message
PiperOrigin-RevId: 429096959
2022-02-16 11:27:21 -08:00
Kevin Krakauer ce194f2c1c Automated rollback of changelist 407638912
PiperOrigin-RevId: 410665707
2021-11-17 17:07:05 -08:00
Ayush Ranjan ce4f4283ba 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 Koopmans 23a115dae8 [syserr] Reverse dependency for tcpip.Error
PiperOrigin-RevId: 407638912
2021-11-04 12:11:41 -07:00
Tamir Duberstein a7045f051f 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 Gowripalan 89a0011c10 Support IPV6_RECVPKTINFO on UDP sockets
PiperOrigin-RevId: 397631833
2021-09-19 13:15:28 -07:00
Ghanan Gowripalan 2572af3886 Remove linux-compat loopback hacks from packet endpoint
Previously, gVisor did not represent loopback devices as an ethernet
device as Linux does. To maintain Linux API compatibility for packet
sockets, a workaround was used to add an ethernet header if a link
header was not already present in the packet buffer delivered to a
packet endpoint.

However, this workaround is a bug for non-ethernet based interfaces; not
all links use an ethernet header (e.g. pure L3/TUN interfaces).

As of 3b4bb94751, gVisor represents
loopback devices as an ethernet-based device so this workaround can
now be removed.

BUG: https://fxbug.dev/81592
Updates #6530, #6531.
PiperOrigin-RevId: 395819151
2021-09-09 17:10:17 -07:00
Ghanan Gowripalan dfb3273f88 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
Kevin Krakauer cd45d7b6c8 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 Krakauer c6da1b0022 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
Zach Koopmans 49eb3da98a [syserror] Refactor abi/linux.Errno
PiperOrigin-RevId: 373265454
2021-05-11 17:23:08 -07:00
Rahat Mahmood f54d87b9ec Remove uses of the binary package from networking code.
Co-Author: ayushranjan
PiperOrigin-RevId: 370785009
2021-04-27 16:20:01 -07:00
Zach Koopmans 8a2f7e716d [syserror] Split usermem package
Split usermem package to help remove syserror dependency in go_marshal.
New hostarch package contains code not dependent on syserror.

PiperOrigin-RevId: 365651233
2021-03-29 13:30:21 -07:00