Commit Graph
175 Commits
Author SHA1 Message Date
Lucas ManningandgVisor bot aa4e302c75 Automated rollback of changelist 558922801
PiperOrigin-RevId: 566731014
2023-09-19 13:46:56 -07:00
Kevin KrakauerandgVisor bot 64c7809b4d 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 KrakauerandgVisor bot e14c91efba 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 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 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
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
Bruno Dal BoandgVisor bot 6e9aca5d76 Use monotonic time for neighbor entries
PiperOrigin-RevId: 470832047
2022-08-29 15:41:41 -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
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
Lucas ManningandgVisor bot c8207270b3 Remove VectorisedView everywhere.
PiperOrigin-RevId: 453471156
2022-06-07 10:36:23 -07:00
Lucas ManningandgVisor bot 4b6229c992 Replace VectorisedView in network endpoints.
PiperOrigin-RevId: 451267391
2022-05-26 16:25:30 -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
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
bemascandgVisor bot 08140fb5ad Add reference counting for packets in channel.Endpoint
This reduces GC pressure when using a TUN device or similar link.

Updates #6910

PiperOrigin-RevId: 431441991
2022-02-28 08:33:36 -08: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
Tony GongandgVisor bot 788386f4ac Add temporary address property
Remove the AddressConfigSlaacTemp address configuration type
and add a boolean representing temporality. This enables support
for statically-configured temporary addresses (such as an address
configured by an out-of-stack DHCPv6 client). Like temporary addresses
generated via SLAAC, such addresses are preferred over addresses that
are not temporary during IPv6 source address selection.

Added a test case to the IPv6 source address selection tests which
asserts that an address with the static temporary config type is
preferred over a non-temporary address.

PiperOrigin-RevId: 426301838
2022-02-03 20:21:14 -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
Tamir DubersteinandgVisor bot 40aef5d553 Delete channel.PacketInfo
Updates #6537.

PiperOrigin-RevId: 417507096
2021-12-20 17:16:37 -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
Ayush RanjanandgVisor bot 469a4a5203 Prevent PacketData from being modified.
PacketData should not be modified and should be treated readonly because it
represents packet payload. The old DeleteFront method allowed callers to modify
the underlying buffer which should not be allowed.

Added a way to consume from the PacketData instead of deleting from it.
Updated call points to use that instead.

Reported-by: [email protected]
PiperOrigin-RevId: 399268473
2021-09-27 13:35:22 -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
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
Tamir DubersteinandgVisor bot beb1320c52 Use fake clocks in all tests
...except TCP tests and NDP tests that mutate globals. These will be
undertaken later.

Updates #5940.

PiperOrigin-RevId: 376145608
2021-05-27 05:06:04 -07:00
Tamir DubersteinandgVisor bot 40a19e38c1 Use opaque types to represent time
Introduce tcpip.MonotonicTime; replace int64 in tcpip.Clock method
returns with time.Time and MonotonicTime to improve type safety and
ensure that monotonic clock readings are never compared to wall clock
readings.

PiperOrigin-RevId: 375775907
2021-05-25 13:00:29 -07:00
Tamir DubersteinandgVisor bot 268f4262a4 Remove detritus
- Unused constants
- Unused functions
- Unused arguments
- Unkeyed literals
- Unnecessary conversions

PiperOrigin-RevId: 375253464
2021-05-22 05:49:34 -07:00
Arthur SfezandgVisor bot 2add8baf49 Add aggregated NIC stats
This change also includes miscellaneous improvements:
* UnknownProtocolRcvdPackets has been separated into two stats, to
specify at which layer the unknown protocol was found (L3 or L4)
* MalformedRcvdPacket is not aggregated across every endpoint anymore.
Doing it this way did not add useful information, and it was also error-prone
(example: ipv6 forgot to increment this aggregated stat, it only
incremented its own ipv6.MalformedPacketsReceived). It is now only incremented
 the NIC.
* Removed TestStatsString test which was outdated and had no real
utility.

PiperOrigin-RevId: 375057472
2021-05-21 04:27:41 -07:00
Ghanan GowripalanandgVisor bot a1d4a6a23d Control forwarding per NetworkEndpoint
...instead of per NetworkProtocol to better conform with linux
(https://www.kernel.org/doc/Documentation/networking/ip-sysctl.txt):

```
conf/interface/*

forwarding - BOOLEAN
	Enable IP forwarding on this interface.  This controls whether packets
	received _on_ this interface can be forwarded.
```

Fixes #5932.

PiperOrigin-RevId: 373888000
2021-05-14 16:32:16 -07:00
Ghanan GowripalanandgVisor bot 8403501143 Rename SetForwarding to SetForwardingDefaultAndAllNICs
...to make it clear to callers that all interfaces are updated with the
forwarding flag and that future NICs will be created with the new
forwarding state.

PiperOrigin-RevId: 373618435
2021-05-13 11:24:20 -07:00
Ghanan GowripalanandgVisor bot d18b0a9d7a Allow handling RAs when forwarding is enabled
...to conform with Linux's `accept_ra` sysctl option.

```
  accept_ra - INTEGER
    Accept Router Advertisements; autoconfigure using them.

    It also determines whether or not to transmit Router
    Solicitations. If and only if the functional setting is to
    accept Router Advertisements, Router Solicitations will be
    transmitted.

    Possible values are:
      0 Do not accept Router Advertisements.
      1 Accept Router Advertisements if forwarding is disabled.
      2 Overrule forwarding behaviour. Accept Router Advertisements
        even if forwarding is enabled.

    Functional default: enabled if local forwarding is disabled.
                        disabled if local forwarding is enabled.
```

PiperOrigin-RevId: 372214640
2021-05-05 15:04:13 -07:00
Ting-Yu WangandgVisor bot c1b08c7c6f netstack: Rename pkt.Data().TrimFront() to DeleteFront(), and ...
... it may now invalidate backing slice references

This is currently safe because TrimFront() in VectorisedView only shrinks the
view. This may not hold under the a different buffer implementation.
Reordering method calls order to allow this.

PiperOrigin-RevId: 371167610
2021-04-29 11:43:26 -07:00
Ghanan GowripalanandgVisor bot 3860526af3 Only carry GSO options in the packet buffer
With this change, GSO options no longer needs to be passed around as
a function argument in the write path.

This change is done in preparation for a later change that defers
segmentation, and may change GSO options for a packet as it flows
down the stack.

Updates #170.

PiperOrigin-RevId: 369774872
2021-04-21 18:09:27 -07:00
Nayana BidariandgVisor bot f1de34234a Move SO_RCVBUF to socketops.
Fixes #2926, #674

PiperOrigin-RevId: 369457123
2021-04-20 09:32:54 -07:00
Kevin KrakauerandgVisor bot 89cfab11eb Use nicer formatting for IP addresses in tests
This was semi-automated -- there are many addresses that were not replaced.
Future commits should clean those up.

Parse4 and Parse6 were given their own package because //pkg/test can introduce
dependency cycles, as it depends transitively on //pkg/tcpip and some other
netstack packages.

PiperOrigin-RevId: 368726528
2021-04-15 15:11:04 -07:00
Nick BrownandgVisor bot 3c492ff8b0 Unexpose immutable fields in stack.Route
This change sets the inner `routeInfo` struct to be a named private member
and replaces direct access with access through getters. Note that direct
access to the fields of `routeInfo` is still possible through the `RouteInfo`
struct.

Fixes #4902

PiperOrigin-RevId: 364822872
2021-03-24 09:38:27 -07:00
Ghanan GowripalanandgVisor bot 363816e491 Return tcpip.Error from (*Stack).GetMainNICAddress
PiperOrigin-RevId: 364381970
2021-03-22 12:31:46 -07:00
Ghanan GowripalanandgVisor bot f9ad8a2510 Do not call into Stack from LinkAddressRequest
Calling into the stack from LinkAddressRequest is not needed as we
already have a reference to the network endpoint (IPv6) or network
interface (IPv4/ARP).

PiperOrigin-RevId: 363213973
2021-03-16 10:29:49 -07:00
Ghanan GowripalanandgVisor bot 7e3e96351d Make stack.DADResult an interface
While I'm here, update NDPDispatcher.OnDuplicateAddressDetectionStatus to
take a DADResult and rename it to OnDuplicateAddressDetectionResult.

Fixes #5606.

PiperOrigin-RevId: 360965416
2021-03-05 11:54:58 -08:00
Ting-Yu WangandgVisor bot 86b1006dcb Make dedicated methods for data operations in PacketBuffer
One of the preparation to decouple underlying buffer implementation.
There are still some methods that tie to VectorisedView, and they will be
changed gradually in later CLs.

This CL also introduce a new ICMPv6ChecksumParams to replace long list of
parameters when calling ICMPv6Checksum, aiming to be more descriptive.

PiperOrigin-RevId: 360778149
2021-03-03 16:05:16 -08:00
Tamir DubersteinandgVisor bot ad9b2b7950 Plumb link address request errors up to requester
Prevent the situation where callers to (*stack).GetLinkAddress provide
incorrect arguments and are unable to observe this condition.

Updates #5583.

PiperOrigin-RevId: 360481557
2021-03-02 11:58:12 -08:00
Ghanan GowripalanandgVisor bot 4c58b2f5ad Support performing DAD for any address
...as long as the network protocol supports duplicate address detection.

This CL provides the facilities for a netstack integrator to perform
DAD.

DHCP recommends that clients effectively perform DAD before accepting an
offer. As per RFC 2131 section 4.4.1 pg 38,

  The client SHOULD perform a check on the suggested address to ensure
  that the address is not already in use.  For example, if the client
  is on a network that supports ARP, the client may issue an ARP request
  for the suggested request.

The implementation of ARP-based IPv4 DAD effectively operates the same
as IPv6's NDP DAD - using ARP requests and responses in place of
NDP neighbour solicitations and advertisements, respectively.

DAD performed by calls to (*Stack).CheckDuplicateAddress don't interfere
with DAD performed when a new IPv6 address is added. This is so that
integrator requests to check for duplicate addresses aren't unexpectedly
aborted when addresses are removed.

A network package internal package provides protocol agnostic DAD state
management that specific protocols that provide DAD can use.

Fixes #4550.

Tests:
  - internal/ip_test.*
  - integration_test.TestDAD
  - arp_test.TestDADARPRequestPacket
  - ipv6.TestCheckDuplicateAddress
PiperOrigin-RevId: 356405593
2021-02-08 19:05:45 -08:00
Ghanan GowripalanandgVisor bot 4669f686ad Remove linkAddrCache
It was replaced by NUD/neighborCache.

Fixes #4658.

PiperOrigin-RevId: 356085221
2021-02-06 21:37:15 -08:00
Ghanan GowripalanandgVisor bot 34ef9a2edc Refactor locally delivered packets
Make it clear that failing to parse a looped back is not a packet
sending error but a malformed received packet error.

FindNetworkEndpoint returns nil when no network endpoint is found
instead of an error.

PiperOrigin-RevId: 355954946
2021-02-05 16:47:11 -08:00
Ghanan GowripalanandgVisor bot fe295b5972 Refactor HandleControlPacket/SockError
...to remove the need for the transport layer to deduce the type of
error it received.

Rename HandleControlPacket to HandleError as HandleControlPacket only
handles errors.

tcpip.SockError now holds a tcpip.SockErrorCause interface that
different errors can implement.

PiperOrigin-RevId: 354994306
2021-02-01 12:04:03 -08:00