Commit Graph

237 Commits

Author SHA1 Message Date
Andrei Vagin 46115504ec Implement the setns syscall
This change introduces the nsfs file system. Each new namespace allocates
a new nsfs inode.

Here are reasons why we need these inodes:
* each namespace has to have an unique id.
* proc/pid/ns/ contains one entry for each namespace. Bind mounting one of
  the files in this directory to somewhere else in the filesystem keeps the
  corresponding namespace alive even if all processes currently in
  the namespace terminate.
* setns() allows the calling process to join an existing namespace specified
  by a file descriptor.

PiperOrigin-RevId: 550694515
2023-07-24 15:45:08 -07:00
gVisor bot 1ba123fff2 Merge pull request #9007 from andrew-d:andrew/tcp-forwarder-on-ignored
PiperOrigin-RevId: 549727271
2023-07-20 13:44:41 -07:00
Andrew Dunham 057e0b7eae pkg/tcpip/transport/tcp: add statistics for dropped connections
When the TCP forwarder ignores a connection due to having too many
in-flight connections, it's not easy to log a message or update a metric
for later debugging. Add a metric that will be incremented in this case
so that the user of the Forwarder can observe this.

Signed-off-by: Andrew Dunham <andrew@du.nham.ca>
2023-07-17 15:07:55 -04: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 792ebbff8e netstack: make tcpip.Address hold a []byte
tcp_benchmark throughput increase 2-3%, but allocations go down (25% in the
download benchmark, only 2% in the upload path).

PiperOrigin-RevId: 532523146
2023-05-16 11:40:49 -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
Ghanan Gowripalan 8b0c4c6408 Use tcpip.NICID when get/set-ing GRO timeout
PiperOrigin-RevId: 529535113
2023-05-04 15:47:28 -07:00
Etienne Perot a938259779 gVisor metric library: Change interface for passing in field values.
This introduces a `metric.FieldValue` struct type that wraps a string.
All metric interfaces that deal with field values have been updated to use
pointers to this type instead of strings.

The intent of this change is to make it more obvious that field values must
be passed using references. Prior to this change, this was done using string
pointer comparisons. Now this must be done by using a pointer to the same
`metric.FieldValue` struct.

The struct type still externally exposes its string so that it can be referred
to in value function callbacks by "custom" metrics. (Though there are no
current uses of callback metrics with fields.)

PiperOrigin-RevId: 527030738
2023-04-25 11:49:02 -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
Etienne Perot f8b9824813 Update unimpl.EmitUnimplementedEvent interface to add the syscall number.
This catches up the interface to the `EmitUnimplementedEvent` method signature
on `kernel.Kernel`.

Also add build-time test to verify that `kernel.Kernel` implements this
interface, in order to catch such breakages at build time in the future.

PiperOrigin-RevId: 519000411
2023-03-23 17:01:37 -07:00
Adin Scannell 1ceb814544 Add default_applicable_licenses rules to packages.
PiperOrigin-RevId: 513581243
2023-03-02 10:50:04 -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
Andrei Vagin e08f204299 inet: each socket has to hold a reference to its network namespace
Otherwise a network namespace can be destroyed before sockets.

Reported-by: syzbot+78dcf6a117cd41dcb84e@syzkaller.appspotmail.com
PiperOrigin-RevId: 503552997
2023-01-20 17:10:58 -08:00
Andrei Vagin 1338761211 Fix reference leaks
PiperOrigin-RevId: 494027351
2022-12-08 16:38:26 -08:00
Ghanan Gowripalan d947422655 Don't prevent removing loopback in core netstack
Implement this check in netstack integration (in sentry) so that the
core netstack does not prevent an integrator from removing loopback.

PiperOrigin-RevId: 493992707
2022-12-08 14:23: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
Kevin Krakauer 901d9a75d3 netstack: add gro_flush_timeout
Makes a per-interface file available to configure the GRO timeout, e.g.
/sys/class/net/eth0/gro_flush_timeout

PiperOrigin-RevId: 487082821
2022-11-08 16:34:55 -08:00
Kevin Krakauer d8aa09e04c convert uses of interface{} to any
Done via:
  find . -name "*.go" | xargs sed -i -E 's/interface\{\}/any/g'

PiperOrigin-RevId: 487033228
2022-11-08 13:14:06 -08:00
Alex Konradi 5c9476aa87 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 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
Lucas Manning 1f2b30d70c 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
Kevin Krakauer c54948f3c1 notify users of common reasons for failing to create a raw socket
Fixes #199

PiperOrigin-RevId: 455018292
2022-06-14 20:04:54 -07:00
Andrei Vagin 5ffcc1f799 Don't leak network namespaces
PiperOrigin-RevId: 454707336
2022-06-13 15:05:21 -07:00
Ghanan Gowripalan ae508f4064 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 Gowripalan da0c67b92a Use different flags for IPV6_RECVERR and IP_RECVERR
PiperOrigin-RevId: 446361103
2022-05-03 21:17:40 -07:00