161 Commits

Author SHA1 Message Date
Nayana Bidari a3e5887415 Changes to support netstack save restore.
- Added a new Stats() method in inet.Stack to get the saved stats
during restore.
- Mark stack.nic, tcpip.Route and stack.addressState structs as "nosave".
These fields should not be saved because the IP addresses and routes can
change during restore and new configuration of routes and IP addresses will be
extracted from the restore spec and initialized in the saved stack.
- Changes in Restore() method in icmp, udp, tcp, packet and raw endpoint files
to support save restore of these endpoints. These changes are flag guarded by
the TESTONLY-save-restore-netstack flag.

PiperOrigin-RevId: 707639274
2024-12-18 12:52:22 -08:00
Nayana Bidari df9ba5fb67 Restore listening connections when netstack s/r is enabled.
This CL restores the listening connections when netstack s/r is enabled.
The changes include:
- New method as a workaround to replace the new routes and nics to the loaded
stack after restore.
- New Restore() for transport layer protocols to restore the protocol level
background workers.
- Adds afterLoad() method for fdbased processors.
- Adds a test to verify listening connection is restored after checkpointing
with netstack s/r enabled.
- Few other changes to save restore fields to enable netstack s/r.

PiperOrigin-RevId: 698453124
2024-11-20 11:13:57 -08:00
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
Koichi Shiraishi 0cf77c02f8 all: remove use io/ioutil deprecated package & fix some deprecated thing
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
2024-10-10 20:36:24 +09:00
Jing Chen f681bcc095 Implement RTM_DELROUTE in netstack.
PiperOrigin-RevId: 675711612
2024-09-17 14:33:41 -07:00
Nayana Bidari 740dc367db Mark netstack as save and use it only in tests
- Adds a new flag which will enable netstack s/r. When the flag is not enabled,
there is no change in the existing behavior. The flag will be enabled only in
tests to verify the s/r functionality of netstack.
- Some additional fields in netstack were causing panic when netstack is
save/restored. Such fields are marked as 'save'/'nosave' accordingly to resolve
the panic.

PiperOrigin-RevId: 668566657
2024-08-28 12:49:43 -07:00
Jing Chen 35309c96c0 Implement RTM_NEWROUTE in netstack to create/replace a route.
PiperOrigin-RevId: 650814137
2024-07-09 18:04:19 -07:00
Kevin Krakauer e367e0b134 make PMTUD on by default and settable via sockopt
We've supported PMTUD for a long time and just never turned it on.

Addresses #10344.

PiperOrigin-RevId: 634003508
2024-05-15 10:44:02 -07:00
Nicolas Lacasse dc5eed4f67 Fix check for IPPROTO_ICMP, since SocketType.proto it is not a bitmask.
And add a comment above the socket type check, since that *is* a bitmask.

This uncovered a bug in the hostnet handling of IP_MULTICAST_IF socket option.
The kernel allows different-sized structures to be passed, but we were only
forwarding the first 4 bytes.

PiperOrigin-RevId: 628115391
2024-04-25 10:25:05 -07:00
Andrei Vagin 129734a352 Pass NEWLINK netlink commands to network stacks
The NEWLINK commands contains many properties and here is no reason to have
another abstract interface between the Sentry and network stacks.

PiperOrigin-RevId: 627916629
2024-04-24 18:42:44 -07:00
Kevin Krakauer c9964aa985 netstack: remove GRO from ingress flow
GRO is getting moved and updated. This removes it in preparation for a
follow-up CL.

PiperOrigin-RevId: 621984030
2024-04-04 15:17:08 -07:00
Nayana Bidari d5f24ea92a Add Resume() method in netstack.
Resume method resumes the endpoints after save which is required for
save/resume. This method resumes the endpoint states which were frozen during
save.

PiperOrigin-RevId: 615467468
2024-03-13 10:36:29 -07:00
Nayana Bidari a76911efa9 Rename Resume() to Restore() in netstack.
The existing Resume method in netstack is doing the work of Restore. This
method does not resume endpoints as the resumable endpoints are only stored
during the Restore of the sandbox, rename the method appropriately.

PiperOrigin-RevId: 613320887
2024-03-06 13:25:31 -08:00
Ayush Ranjan f62a4a77d5 Update go branch to Go 1.21.
Starting with Go 1.21, build tags select the language version. We currently
have several `go:build go1.1` tags, which were intended to act as "true" tags.
But that will break with 1.21. So replace them with "!false".

Fixes #9568.

PiperOrigin-RevId: 576020779
2023-10-23 22:09:47 -07:00
Jamie Liu ff81c0c639 Remove //pkg/sentry/device.
This package was used for VFS1 device number assignment.

PiperOrigin-RevId: 538918926
2023-06-08 16:21:04 -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
Nicolas Lacasse 4b35f1242d Enable socket_inet_loopback test on hostinet.
A few minor fixes. The biggest change is that the blocking implementation needs
to wait on POLLHUP and POLLERR events, in addition to readable/writable events.
We also need to track shutdown state in the socket.

PiperOrigin-RevId: 529816115
2023-05-05 14:35:57 -07:00
Nicolas Lacasse 77cf871eda hostinet: Disallow writes to AF_PACKET sockets.
PiperOrigin-RevId: 528831169
2023-05-02 10:58:18 -07:00
Nicolas Lacasse 81f644ddff Enable socket_stress_test with hostinet.
The min/max port ranges were broken.

PiperOrigin-RevId: 526137330
2023-04-21 14:35:51 -07:00
Nicolas Lacasse e9b8e1b74c Automated rollback of changelist 525849045
PiperOrigin-RevId: 526120544
2023-04-21 13:26:08 -07:00
Nicolas Lacasse 751906f40d Enable socket_inet_loopback test on hostinet.
The blocking implementation needs to wait on POLLHUP and POLLERR events, in
addition to readable/writable events. That fixed at least one test.

There's still two unresolved issues in the tests, but we can enable the rest
of the suite while we figure out those two.

PiperOrigin-RevId: 525849045
2023-04-20 14:25:27 -07:00
Nicolas Lacasse e64fa26613 Enable hostinet for netdevice tests.
This was just a matter of passing a few more IOCTL commands to the host.

PiperOrigin-RevId: 523540572
2023-04-11 16:46:35 -07:00
Nicolas Lacasse dadab01167 Implement hostinet.Stack methods that manipulate interfaces and addresses.
And enable all of the netlink tests that depend on this functionality.

Specifially, this CL implements hostinet.stack:
* .RemoveInterface()
* .AddInterfaceAddr()
* .RemoveInterfaceAddr()

Applications use netlink messages to call into these methods. For hostinet, we
use netlink messages to the host to implement these methods.

Note that the netlink messages are not simple passed from the application to
the host -- they are parsed first and only carefully crafted messages are sent
to the host.

This CL required a lot of refactoring to the existing netlink code in the
hostinet package, as well as a bunch of new functionality. All of that code has
been collected in hostinet/netlink.go

I also changed how we handle CAP_NET_ADMIN and CAP_NET_RAW in tests, since we
must drop those capabilities inside the sandbox if we don't have them on the
host. The new solution is cleaner and does not rely on google-specific env
variables.

PiperOrigin-RevId: 522685544
2023-04-07 14:33:21 -07:00
Nicolas Lacasse ebda75f504 Make hostinet get the interfaces/addr/routes dynamicallys.
Previously we were initializing these at startup and they could never change.
Now they are read dynamically every time they are requested. This is a
pre-requisite for implementing methods that mutate the interfaces
(stack.AddInterface()).

PiperOrigin-RevId: 522109098
2023-04-05 11:35:39 -07:00
Nicolas Lacasse f540010d1c Clean up netlink code in hostinet.
No functional changes. Refactored some methods into smaller chunks for easy
reuse. Got rid of some needlessly exported methods.

PiperOrigin-RevId: 520748526
2023-03-30 14:51:24 -07:00