187 Commits

Author SHA1 Message Date
Jing Chen f681bcc095 Implement RTM_DELROUTE in netstack.
PiperOrigin-RevId: 675711612
2024-09-17 14:33:41 -07:00
Andrei Vagin 3546fab741 netstack: choose route by longest prefix
It has to return the most specific route.

PiperOrigin-RevId: 647421535
2024-06-27 13:12:45 -07:00
gVisor bot 26df9667ad netstack: support mtu in routes
PiperOrigin-RevId: 640919454
2024-06-06 09:16:11 -07:00
Konstantin Bogomolov 52f1d31378 Prevent using zero as NICID.
PiperOrigin-RevId: 629890469
2024-05-01 17:46:34 -07:00
Lucas Manning 52fc5b60f7 Add a method for inspecting assigned addresses.
This new method allows checking for the existence of assigned addresses without
taking an extra reference that needs to be DecRefed. DecRef takes exclusive
locks. Contention on the addressState lock causes performance issues when
multiple goroutines are processing IP packets simultaneously. This isn't the
case today since IP processing is single threaded, but will be eventually.

PiperOrigin-RevId: 623567408
2024-04-10 12:12:23 -07:00
Kevin Krakauer 3c75945fd6 netstack: remove PacketBuffer.IsNil()
The change was originally motivated by ticket references (cl/450976957), which
were never implemented.

PiperOrigin-RevId: 617480960
2024-03-20 05:31:48 -07:00
Kevin Krakauer 5b4fbd06d8 netstack: remove PacketBufferPtr
PacketBufferPtr is leftover from a dead experiment. Just use *PacketBuffer.

PiperOrigin-RevId: 611531815
2024-02-29 11:10:38 -08:00
Kevin Krakauer 289757e903 netstack: support source hints in routes
PiperOrigin-RevId: 587841841
2023-12-04 14:30:57 -08:00
Kevin Krakauer 925904e24e netstack: add IP source selection test that was rolled back
See cl/557941259 for the original.

PiperOrigin-RevId: 580624680
2023-11-08 12:52:08 -08:00
Andrei Vagin 5f4abad306 Fix a few typos
It is an idea of running codespell as part of our presubmit checks.
Before enabling it for new changes, let's fix what it has found.

Signed-off-by: Andrei Vagin <avagin@gmail.com>
2023-10-25 12:13:42 -07:00
Peter Johnston 289dc7ce1d Prefer routes with local addr on outgoing NIC only for local traffic
Currently gVisor's routing logic always prefers routes that use a local
address that is assigned to the outgoing interface. This preference is
applied even for forwarded traffic, where the local address is left
unspecified on route lookup because the source address of the packet
belongs to some other node as opposed to the stack itself. This means
that when forwarding incoming traffic, the netstack will prefer routes
that go through a NIC with a local address endpoint over those that do
not, even if a better route exists.

Change this logic such that the preference for routes with a local
address assigned to the outgoing interface only applies for locally-
generated traffic.

PiperOrigin-RevId: 573812452
2023-10-16 08:12:10 -07:00
Lucas Manning 4cd842b20a Automated rollback of changelist 557941259
PiperOrigin-RevId: 566749598
2023-09-19 14:51:59 -07:00
Lucas Manning 949461f2b3 Automated rollback of changelist 558922801
PiperOrigin-RevId: 566731014
2023-09-19 13:46:56 -07:00
Kevin Krakauer baf097a14d netstack: refactor IPv4 source address selection
This was in the wrong place. This CL just refactors it into package ipv4, just
as IPv6-specific logic is in package ipv6.

PiperOrigin-RevId: 558922801
2023-08-21 15:54:10 -07:00
Kevin Krakauer fd95313e83 netstack: use longest prefix match to choose IPs on a NIC
Once a NIC is chosen for a route, we currently just grab the first IP on the
NIC as the source address. We should choose the address with the longest
matching prefix instead.

This is a simple linear search of the route table. That's slow for large
tables, but large tables are exceedingly rare for use with gVisor and we can
always reimplement this with a trie if it becomes necessary.

PiperOrigin-RevId: 557941259
2023-08-17 14:45:53 -07:00
Kevin Krakauer 89d6bf18c8 have gVisor use renamed buffer package
PiperOrigin-RevId: 537209194
2023-06-01 21:27:49 -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 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
Bruno Dal Bo c40f8e3651 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 Krakauer 4eca206fa4 netstack: introduce PacketBufferPtr
PiperOrigin-RevId: 479437464
2022-10-06 16:16:54 -07:00
Bruno Dal Bo 4fc63e59f0 Use monotonic time for neighbor entries
PiperOrigin-RevId: 470832047
2022-08-29 15:41: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
Tony Gong be6ffa78e4 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
Nate Hurley 7d3a75fa60 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