Commit Graph
245 Commits
Author SHA1 Message Date
Ghanan GowripalanandgVisor bot 964f2676b4 Set LinkHeader for pkts sent by raw packet socket
Previously, when a packet was sent from a raw packet socket, the packet
buffer's link header was left unpopulated and the link header was only
found in the packet buffer's payload. This breaks the expectations of
LinkEndpoints which expect the link layer header to always be populated
when the link requires a header.

PiperOrigin-RevId: 542349445
2023-06-21 13:41:22 -07:00
Kevin KrakauerandgVisor bot 8a2b1df3f6 have gVisor use renamed buffer package
PiperOrigin-RevId: 537209194
2023-06-01 21:27:49 -07:00
Kevin KrakauerandgVisor bot 5cdebeb73d 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 KrakauerandgVisor bot ef88b30bff 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 GowripalanandgVisor bot 3173a75072 Use tcpip.NICID when get/set-ing GRO timeout
PiperOrigin-RevId: 529535113
2023-05-04 15:47:28 -07:00
Ghanan GowripalanandgVisor bot f16fea9441 Don't lock before accessing nic.networkEndpoints
nic.networkEndpoints is never modified after the NIC is created so there
is no need to hold a lock while accessing it.

We keep `n.mu` (renamed to `n.enableDisableMu`) to synchronize attempts
to enable and disable the device as interleaving of these operations may
result in inconsistent state.

PiperOrigin-RevId: 525288865
2023-04-18 16:55:08 -07:00
Nicolas LacasseandgVisor bot cfb0f3e522 Lock nic.networkEndpoints with nic.mu.
PiperOrigin-RevId: 495141130
2022-12-13 15:28:12 -08:00
Andrei VaginandgVisor bot 7d66029df0 Fix reference leaks
PiperOrigin-RevId: 494027351
2022-12-08 16:38:26 -08:00
Ghanan GowripalanandgVisor bot 3ebe155d12 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
Andrei VaginandgVisor bot 46bdcf574e tcpip/stack: use lockdep mutexes
PiperOrigin-RevId: 493749454
2022-12-07 17:14:03 -08:00
Kevin KrakauerandgVisor bot 12a30fa602 netstack: add GRO flag
This allows for configuration of the GRO interval without modifying
gro_flush_timeout. In some setups, e.g. docker, sysfs is mounted as RO and thus
a flag is easier to work with.

PiperOrigin-RevId: 487096047
2022-11-08 17:36:38 -08:00
Kevin KrakauerandgVisor bot 60b0f76f7f 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 KrakauerandgVisor bot 3a76efe831 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 KonradiandgVisor bot e651635266 Hold lock while accessing Stack.nics
Fix some occurrences of Stack.nics being read without holding the Stack.mu lock.
This can result (and has resulted) in crashes at runtime due to concurrent map
read and write operations.

Fixes #8134.

PiperOrigin-RevId: 485750713
2022-11-02 18:55:36 -07:00
Bruno Dal BoandgVisor bot 681f42f1b3 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
Kevin KrakauerandgVisor bot fedffe9ca6 netstack: introduce PacketBufferPtr
PiperOrigin-RevId: 479437464
2022-10-06 16:16:54 -07:00
Lucas ManningandgVisor bot 83ef662bb8 Fix IP_ADD_MEMBERSHIP address checking to match linux.
When handling a call to setsockopt for IP_ADD_MEMBERSHIP with an ip_mreqn
struct with a non-zero interface IP address and interface index, Linux
checks the interface index first and, if it matches a device, ignores the
address.

Linux: https://github.com/torvalds/linux/blob/15205c2829ca2cbb5ece5ceaafe1171a8470e62b/net/ipv4/igmp.c#L1829-L1837

Fixes #7880

PiperOrigin-RevId: 467787302
2022-08-15 16:22:01 -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
Tony GongandgVisor bot 9e6140d108 Introduce and Implement AddressDispatcher
Introduce the AddressDispatcher interface which integrators can
provide an implementation at the time of adding an address
to receive callbacks when address properties change and when the
address is removed. Modify `NDPDispatcher`'s callback when a SLAAC
address is added to receive an implementation of `AddressDispatcher`.

Added informational preferred and valid lifetime fields to
`AddressProperties` so they can be set when adding the address; and a
way to update said lifetimes.

Added a means to disable an `AddressableEndpointState` and each
individual `addressState`, so that the `AddressDisabled` assignment
state can be reported to integrators.

Added a configurable option to `AddressableEndpointState` which
determines whether addresses of kind `PermanentDisabled` are included
in the return value of `PrimaryAddresses` and `PermanentAddresses`. This
option is set such that IPv4 addresses are returned, while IPv6
addresses are hidden, when the NIC is disabled. This is a change in
behavior for IPv6, but is consistent with behavior on Linux.

Modified tests in `ndp_test` to use the new AddressDispatcher. Fixed
some bugs along the way.

PiperOrigin-RevId: 459658009
2022-07-07 19:58:25 -07:00
Ayush RanjanandgVisor bot 7054987fb3 Fix remaining comments to adhere to gofmt.
PiperOrigin-RevId: 456544446
2022-06-22 10:20:08 -07:00
Nate HurleyandgVisor bot b63c4b3348 Enable multicast forwarding per protocol.
After this change, multicast packets will only be forwarded if
multicast forwarding is enabled on the relevant NIC AND it is
enabled for the relevant protocol (IPv4 or IPv6).

Multicast forwarding at the protocol level will be tied to the lifetime
of the IPv4/IPv6RoutingTableControllers. In particular, this change
enables us to satisfy the following requirements:

https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.net.multicast.admin/ipv4.fidl;l=20-21;drc=acd6519f50c92e30f18cc1816bd1c400759b533c

Updates #7338.

PiperOrigin-RevId: 455155793
2022-06-15 10:00:49 -07:00
Kevin KrakauerandgVisor bot a1f19dde5b 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
Lucas ManningandgVisor bot c8207270b3 Remove VectorisedView everywhere.
PiperOrigin-RevId: 453471156
2022-06-07 10:36:23 -07:00
Nate HurleyandgVisor bot ae264d7836 Implement GetMulticastRouteLastUsedTime.
Updates #7338.

PiperOrigin-RevId: 451172827
2022-05-26 08:59:42 -07:00
Nate HurleyandgVisor bot 39a0834a5e Implement remove multicast route.
Updates #7338.

PiperOrigin-RevId: 451162886
2022-05-26 08:06:06 -07:00
Nate HurleyandgVisor bot fbdfc990c9 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
Ayush RanjanandgVisor bot 2026e1f078 Reformat codebase.
PiperOrigin-RevId: 449358041
2022-05-17 17:48:35 -07:00
Bhasker HariharanandgVisor bot b3a5701e19 Remove TCP endpoint goroutines.
This change removes all endpoint goroutines and all TCP processing is now done
inline in the TCP processor loop. TCP timers directly invoke handlers as
required rather than assert a waker.

UnlockUser is also simplified to just queue the endpoint to the processor
instead of trying to process segments inline. This allows us to centralize logic
for TCP state handling in the processor. This potentially could involve an extra
wakeup but now that endpoint goroutines do not exist this is not such a big
concern as in case of busy servers the processor goroutines will already be
running anyway.

This change also allows us to clean up S/R as now restoring a TCP endpoint does
not require restarting a goroutine and moving it to the right logical point but
only requires that we restart any timers that may have been running when the
save was done and restore any port bindings as required.

Endpoint.Release is now removed in favor of Endpoint.Abort by using Abort in
places where we use Endpoint.Release.

Updates #231

PiperOrigin-RevId: 442673015
2022-04-18 17:35:36 -07:00
Kevin KrakauerandgVisor bot b8dd528b97 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
Nate HurleyandgVisor bot 49812a53f9 Add option to enable multicast forwarding
Setting this newly added option to "true" will currently be a no-op. Full
support for multicast routing will be added in subsequent CLs.

Updates #7338.

PiperOrigin-RevId: 439356271
2022-04-04 10:48:26 -07:00
Ghanan GowripalanandgVisor bot 3721f70dff Return previous config when setting NIC forwarding
...so that callers can determine if forwarding changed as a consequence
of their call.

PiperOrigin-RevId: 431069840
2022-02-25 18:05:40 -08:00
Tony GongandgVisor bot 04c8729e32 Expose address deprecation on Stack
Add a method for setting an address to be deprecated/preferred to
AddressableEndpoint, so that addresses added from outside the stack
can be deprecated/renewed respectively, e.g. by a DHCPv6 client.

PiperOrigin-RevId: 426435598
2022-02-04 10:29:52 -08:00
Ghanan GowripalanandgVisor bot 98c6d4c85c Drop LinkEndpoint.WriteRawPacket
PiperOrigin-RevId: 424490855
2022-01-26 18:33:55 -08:00
Bhasker HariharanandgVisor bot e4c885595b Remove NICs on stack shutdown to ensure qdisc cleanup.
PiperOrigin-RevId: 424149803
2022-01-25 12:28:57 -08:00
Adin ScannellandgVisor bot 67ecd8d451 Add checklocks annoations for stack/route.go.
PiperOrigin-RevId: 423973318
2022-01-24 19:54:22 -08:00
Ghanan GowripalanandgVisor bot 2f180880c2 Don't pass route info and net proto to write fns
...as the packet buffer already holds that information.

Updates #3810.
Fixes #6537.

PiperOrigin-RevId: 421898143
2022-01-14 13:23:22 -08:00
Bhasker HariharanandgVisor bot ecb192b0d7 Hoist Fifo QDisc to NIC layer.
This will in future allow us to easily replace qdisc implementations
at runtime for any given NIC.

PiperOrigin-RevId: 416183274
2021-12-13 18:31:19 -08:00
Ghanan GowripalanandgVisor bot 429c61eeef Handle source port conflicts
This change also updates the ConnTrack seed to be generated by the
stack's random generator instead of using the stack's seed.

Fixes #5773.

PiperOrigin-RevId: 409264463
2021-11-11 15:56:34 -08:00
Tamir DubersteinandgVisor bot 7e48473fd1 Remove Stack.NewJob
Use the static method instead; these methods encourage callers to retain
a pointer to the entire stack rather than only its clock which they
require.

PiperOrigin-RevId: 408651956
2021-11-09 10:57:11 -08:00
Lucas ManningandgVisor bot e100ee8c1f Add reference counting to packet buffers.
PiperOrigin-RevId: 408426639
2021-11-08 13:28:38 -08:00
Ghanan GowripalanandgVisor bot a2af8a5cf6 Always parse Transport headers
..including ICMP headers before delivering them to the
TransportDispatcher.

Updates #3810.

PiperOrigin-RevId: 404404002
2021-10-19 17:25:55 -07:00
Kevin KrakauerandgVisor bot 07c44ee397 conntrack: use tcpip.Clock instead of time.Time
- We should be using a monotonic clock
- This will make future testing easier

Updates #6748.

PiperOrigin-RevId: 404072318
2021-10-18 15:14:28 -07:00
Bruno Dal BoandgVisor bot cb912abd96 Avoid ambient clock on ICMP Rate Limiter
PiperOrigin-RevId: 397496920
2021-09-18 06:00:35 -07:00
Tony GongandgVisor bot 31f5add4b4 Pass address properties in a single struct
Replaced the current AddAddressWithOptions method with
AddAddressWithProperties which passes all address properties in
a single AddressProperties type. More properties that need to be
configured in the future are expected, so adding a type makes adding
them easier.

PiperOrigin-RevId: 396930729
2021-09-15 15:00:01 -07:00
Ghanan GowripalanandgVisor bot 8e9d6f9c82 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
Zeling FengandgVisor bot 531f65e5b5 Add Stack.Seed() back
... because it is still used by fuchsia.

PiperOrigin-RevId: 393246904
2021-08-26 17:44:25 -07:00
Zeling FengandgVisor bot a34d4a63fe Use a hash function to generate tcp timestamp offset
Also fix an option parsing error in checker.TCPTimestampChecker while I am here.

PiperOrigin-RevId: 391828329
2021-08-19 13:15:40 -07:00
Zeling FengandgVisor bot 0ccdb1789d Split TCP secrets from Stack to tcp.protocol
Use different secrets for different purposes (port picking,
ISN generation, tsOffset generation) and moved the secrets
from stack.Stack to tcp.protocol.

PiperOrigin-RevId: 391641238
2021-08-18 17:00:13 -07:00
Zeling FengandgVisor bot ccf06b3451 Support RTM_DELLINK
This change will allow us to remove the default link in a packetimpact test so
we can reduce indeterministic behaviors as required in https://fxbug.dev/78430.
This will also help with testing #1388.

Updates #578, #1388.

PiperOrigin-RevId: 387896847
2021-07-30 15:41:36 -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