Commit Graph
734 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
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
Lucas ManningandgVisor bot 31c7a6281e Automated rollback of changelist 538230394
PiperOrigin-RevId: 540671483
2023-06-15 13:21:26 -07:00
Kevin KrakauerandgVisor bot 5c5e85baea netstack: clear buckets upon close
It was possible for `close` and `dispatch` to race, each trying to `DecRef` the
same packet. We now clear the bucket of packets upon `close` so that `DecRef`
occurs only once.

PiperOrigin-RevId: 540663408
2023-06-15 12:51:59 -07:00
Lucas ManningandgVisor bot 4f0dc3b1a3 Change Buffer.PullUp so that it returns views that are not shared.
The underlying chunks returned from PullUp should not be shared,
since the underlying slice can sometimes be directly modified. This change
also reworks some of the network parsing code so that ownership of
views is more explicit to the reader.

PiperOrigin-RevId: 538230394
2023-06-06 10:51:15 -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 00d2a5f557 netstack: avoid buffer cloning when merging in GRO
This pattern can be seen in tcp.segment.merge.

PiperOrigin-RevId: 537155366
2023-06-01 16:13:07 -07:00
Kevin KrakauerandgVisor bot 4d013c2a59 netstack: speed up merge
Merge clears the other buffer, so rather than cloning and dealing with
refcounts, we can just steal other's view list and adjust sizes.

This increases the speed of Merge 10x, and this was with a benchmark that
didn't do any TrimFront/Truncate (which will induce copying in the old
implementation).

BenchmarkMerge
BenchmarkMerge-33               99412884                12.74 ns/op            0 B/op          0 allocs/op
BenchmarkOldMerge
BenchmarkOldMerge-33             6075222               217.4 ns/op             0 B/op          0 allocs/op

This change uncovered that PacketBuffer.DeepCopyForForwarding wasn't doing a
true deep copy. It seems that, in the ICMP error path, a call to Merge was
forcing a deep copy (maybe because Append was copying bytes), obfuscating the
issue. This change also addresses that issue by having DeepCopyForForwarding
produce a copy that shares no data with other packets.

PiperOrigin-RevId: 537143838
2023-06-01 15:25:28 -07:00
Kevin KrakauerandgVisor bot 95bede57e7 netstack: use bytes.Equal in GRO
bytes.Equal produces faster compiled code.

PiperOrigin-RevId: 536778125
2023-05-31 11:47:58 -07:00
Ghanan GowripalanandgVisor bot 4b8f7d281b Don't hold link address in tcpip.Address
All tcpip.Endpoints use a tcpip.FullAddress to hold addresses associated
with an outgoing or incoming packet, but the struct only had a field for
a tcpip.Address. This field was overloaded to also hold a link address
(which is normally held in a tcpip.LinkAddress). This worked relatively
fine until the change to make addresses opaque types.

commit ef88b30bff required the use of a
workaround to continue passing around link addresses through the
tcpip.Address field. This workaround requires assumptions about the
size of the hardware address and unncessary jumping-through-hoops.

This change just introduces a new field to tcpip.FullAddress with type
tcpip.LinkAddress that can hold link addresses and this new field will
be used by packet endpoints.

The change referenced above is cl/532284732.

PiperOrigin-RevId: 536561363
2023-05-30 18:14:32 -07:00
Kevin KrakauerandgVisor bot 888468293c Automated rollback of changelist 531020857
PiperOrigin-RevId: 532863869
2023-05-17 12:09:12 -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
Kevin KrakauerandgVisor bot 47db5b5c8f netstack: replace slice-based PacketBufferList with linked list
This is effectively a rollback of cl/450976957. The original motivation never
panned out, and it's easier to work with the lists. They also are easier to
avoid allocations with.

PiperOrigin-RevId: 531020857
2023-05-10 15:43:59 -07:00
Kevin KrakauerandgVisor bot f970f1df1f netstack: change PacketBufferPtr back to *PacketBuffer
The benefits of PacketBufferPtr never materialized and it makes the type
difficult to work with, e.g. it can't be used with go_generics to make a
(performant) list.

This is effectively a rollback of cl/480518221.

PiperOrigin-RevId: 530954630
2023-05-10 11:16:28 -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
Jeff MartinandgVisor bot 8d99c4fa85 tcpip/stack: Export the NeighborCacheSize constant
Fuchsia's Netstack component would like to depend on this constant when
setting the buffer size for neighbor events. See https://fxrev.dev/824598.

Fixes #8766

PiperOrigin-RevId: 522337436
2023-04-06 08:07:09 -07:00
Kevin KrakauerandgVisor bot 03081d61a4 gro: remove unnecessary restriction on GRO-able packets
DF doesn't need to be set. Linux also allows GRO on packets without DF set.

This fixes an issue where loopback traffic couldn't be GRO'd because gVisor
never sets the DF bit (we don't implement PMTUD yet).

PiperOrigin-RevId: 518684608
2023-03-22 15:12:12 -07:00
Kevin KrakauerandgVisor bot 1792d99fda gro: fix bug where handshake packets would be stuck waiting in GRO
GRO would not immediately flush the final ACK in the SYN-SYN/ACK-ACK handshake.
This could lead to a situation where

- Client A calls connect(), which returns once the final ACK of the handshake
  is sent and A reaches state ESTABLISHED
- The ACK gets GRO'd, delaying it from reaching the server
- Client B calls non-blocking connect()
- Client B's ACK gets GRO'd as well
- Client B is marked as ESTABLISHED
- The server, with accept queue size 1, is only going to accept one connection,
  but two clients are ESTABLISHED.

It now immediately flushes packets with no payload, as they are important to
TCP connection state and management.

PiperOrigin-RevId: 517474519
2023-03-17 12:13:27 -07:00
Kevin KrakauerandgVisor bot 575847947b Automated rollback of changelist 516870932
PiperOrigin-RevId: 516937389
2023-03-15 14:56:55 -07:00
Kevin KrakauerandgVisor bot cc4b14b884 gro: fix bug where handshake packets would be stuck waiting in GRO
Also enables GRO in syscall tests. GRO should be totally transparent and should
not affect behavior. This ensures it's tested and fixes the bug it uncovered.

GRO would not immediately flush the final ACK in the SYN-SYN/ACK-ACK handshake.
This could lead to a situation where

- Client A calls connect(), which returns once the final ACK of the handshake
  is sent and A reaches state ESTABLISHED
- The ACK gets GRO'd, delaying it from reaching the server
- Client B calls non-blocking connect()
- Client B's ACK gets GRO'd as well
- Client B is marked as ESTABLISHED
- The server, with accept queue size 1, is only going to accept one connection,
  but two clients are ESTABLISHED.

It now immediately flushes packets with no payload, as they are important to
TCP connection state and management.

PiperOrigin-RevId: 516870932
2023-03-15 10:54:43 -07:00
Kevin KrakauerandgVisor bot 0e5c57e3a7 Schedule GRO flush iff packets are queued
Originally Ghanan's cl/494241863.

This prevents goroutines from being unnecessarily scheduled when there
are no packets in the GRO dispatcher, reducing wasted CPU cycles.

With this change, a timer to flush GRO packets is scheduled when a
packet is enqueued and no previous timer exists. The timer is
rescheduled to be fired again if after flushing packets, packets remain
in the GRO dispatcher. If GRO is disabled, and a timer was previously
set, the timer is reset to fire immediately and flush all packets.

Performance:

The big win here is for non-network-heavy workloads. The GRO flush thread no
longer fires when unnecessary. GRO used to add absurd overhead for such
workloads. Now it adds none: e.g. `sleep 10` used <= 10ms without GRO, 7.79s
with it (!!!), and now uses <= 10ms with this change.

This lowers throughput and CPU usage roughly proportionally in networking-heavy
benchmarking. CPU usage seems to decrease slightly more than throughput (which
is good!).

PiperOrigin-RevId: 516720406
2023-03-14 21:51:54 -07:00
Kevin KrakauerandgVisor bot feade6e66c gro: IPv6
Opted for separate code paths rather than over-fitting to interfaces when
there're only 2 supported network protocols and 1 transport protocol.

The performance improvement is more modest than IPv4, I'm guessing due to the
process of parsing extension headers. As with IPv4, we'd benefit from parsing
only once and saving header state.

PiperOrigin-RevId: 513928270
2023-03-04 00:44:34 -08:00
Kevin KrakauerandgVisor bot 5b31197c09 gro: factor out TCP checks
PiperOrigin-RevId: 513599763
2023-03-02 11:57:10 -08:00
Kevin KrakauerandgVisor bot 4c97946539 gro: move groBucket functions together
Just makes reviewing easier than changing and moving in one CL.

PiperOrigin-RevId: 513589363
2023-03-02 11:17:15 -08:00
Adin ScannellandgVisor bot 2911d8c3b8 Add default_applicable_licenses rules to packages.
PiperOrigin-RevId: 513581243
2023-03-02 10:50:04 -08:00
Kevin KrakauerandgVisor bot 027e688b86 gro: small refactor to prepare for IPv6 support
PiperOrigin-RevId: 512713323
2023-02-27 13:23:30 -08:00
Kevin KrakauerandgVisor bot cb585ba8ab gro: use packet data size instead of IPv4 total length
In preparation for IPv6 support. IPv6 doesn't have a total length field.
pkt.Data().Size() is equivalent and also works with IPv6.

PiperOrigin-RevId: 512677616
2023-02-27 11:11:08 -08:00
gVisor bot 98e97f8ef6 Merge pull request #8312 from jtolio:patch-1
PiperOrigin-RevId: 503573267
2023-01-20 19:50:22 -08:00
Bruno Dal BoandgVisor bot ecc112a3eb Set PktType for all Ethernet Packets
In preparation for improving ARP handling of gratuitous ARPs, set PktType in
regular inbound flow instead of only when handling packet sockets.

PiperOrigin-RevId: 501562322
2023-01-12 07:43:18 -08:00
Zeling FengandgVisor bot 6d2dbc4c2e Handle all codes for ICMPv4 destination unreachable message for TCP
Some hosts use iptables and are configured to respond an ICMP destination
unreachable message with a {host/net/admin}prohibited code instead of a RST.
Linux handles these codes correctly by aborting the handshake. This commit
adds handling of all possible codes of an ICMPv4 destination unreachable message
to bring gVisor to parity.

PiperOrigin-RevId: 496703813
2022-12-20 11:07:27 -08:00
Andrei VaginandgVisor bot 94f2216c55 stack/conntrack: suppress the nested locking warning
reapEverything intentionally takes the second bucket lock.

PiperOrigin-RevId: 495967790
2022-12-16 14:59:49 -08:00
Nicolas LacasseandgVisor bot b8685d3d2d Don't hold nic.mu when calling n.linkResQueue.cancel.
Reported-by: [email protected]
PiperOrigin-RevId: 495756802
2022-12-15 19:30:00 -08:00
JT Olio 1e7debfe90 pkg/tcpip/stack: HasDisconncetOkCapability -> HasDisconnectOkCapability
oof, no idea if you can even accept this change. feel free to close or whatever.
2022-12-15 09:45:20 -05:00
Nicolas LacasseandgVisor bot cfb0f3e522 Lock nic.networkEndpoints with nic.mu.
PiperOrigin-RevId: 495141130
2022-12-13 15:28:12 -08:00
Lucas ManningandgVisor bot 2a64b16f35 Remove unsetting route's cached neighbor entry in link res callback.
This does not change behavior, since expired or invalid entries
are ignored anyways.

PiperOrigin-RevId: 495130325
2022-12-13 14:42:04 -08:00
Nicolas LacasseandgVisor bot c6df9c8269 Make nic.spoofing and nic.promiscuous atomic Bools to avoid lock contention.
Also add atomicbitops.Bool which is just a Uint32, but behaves as a boolean.

PiperOrigin-RevId: 495103870
2022-12-13 13:08:11 -08:00
Tony GongandgVisor bot 194a1cd865 Fix not setting AddressDispatcher on promotion
AddressDispatcher was being set when adding an address only for new
addresses, resulting in cases such as when an expired addresses is
re-added to lose the AddressDispatcher that is passed.

Added a regression test.

PiperOrigin-RevId: 494220872
2022-12-09 11:25:53 -08:00
Andrei VaginandgVisor bot 7d66029df0 Fix reference leaks
PiperOrigin-RevId: 494027351
2022-12-08 16:38:26 -08:00
gVisor bot 9c50d380d2 Merge pull request #8212 from avagin:addressStateRefs
PiperOrigin-RevId: 494016953
2022-12-08 15:55:10 -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
Ghanan GowripalanandgVisor bot ca720ab9d9 Wait for GRO loop to stop
...before returning from groDispatcher.close.

This is to make sure that when we return from cleanup functions, the
caller can safely assume that resources have been released.

PiperOrigin-RevId: 493714729
2022-12-07 14:58:45 -08:00
Andrei Vagin 5318c9ebfc tcpip/stack: use atomic refs for addressState
In this case, we don't need to take a read-write lock in IncRef and DecRef.
2022-12-01 15:15:09 -08:00
Ayush RanjanandgVisor bot d937df6218 Replace pkg/refs with pkg/refsvfs2.
All VFS1 only bits have been deleted.

Updates #1624

PiperOrigin-RevId: 492273183
2022-12-01 12:46:11 -08:00
Kevin KrakauerandgVisor bot 27d63adf22 conntrack: don't nest conntrack locks
PiperOrigin-RevId: 491713226
2022-11-29 12:53:54 -08:00
Kevin KrakauerandgVisor bot 0d6c4e6a9a gro: use packet size to infer MSS
Linux GRO simply uses the size of the first packet in a flow as the MSS. So
identically sized packets are coalesced until an oddly-sized one comes along.

See net/core/gro.c:dev_gro_receive and net/ipv4/tcp_offload.c:tcp_gro_receive.

Also fixed clobbering of the groPacket.idx field, which caused memory
corruption.

PiperOrigin-RevId: 490361840
2022-11-22 16:20:51 -08:00