48 Commits
Author SHA1 Message Date
Kevin KrakauerandgVisor bot 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
Peter JohnstonandgVisor bot 21edc122da NAT source ports for locally generated traffic when necessary
Currently, when a packet hits the NAT table and does not hit any NAT targets,
its connection is assigned "no-op NAT", which basically means that the
connection will not be NATed. However, this causes a problem when, for example,
locally-generated traffic chooses a local port that has already been used by
forwarded traffic that the stack is NATing. In this case, the locally-generated
traffic will simply be dropped when the connection is finalized due to a tuple
conflict.

Instead of doing nothing, the netstack must implicitly perform SNAT for the
locally-generated traffic to remap its source port to prevent that traffic from
being dropped.

Also, when setting up NAT for a connection, the netstack checks if the
connections' reply tuple is unique to see whether it needs to rewrite the
transport-layer port/ID. This logic currently doesn't account for self-connected
sockets, where the original and reply tuples are identical and point to the same
connection; add logic handling that scenario, such that the reply tuple can be
non-unique if it refers to the same connection as the original tuple.

PiperOrigin-RevId: 612969884
2024-03-05 14:30:24 -08:00
Kevin KrakauerandgVisor bot 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 KrakauerandgVisor bot 1ac6325b3b iptables: support address-only and port-only nat
Also fix the way we return target revision numbers.

Also also change some incorrect receiver names.

PiperOrigin-RevId: 582789755
2023-11-15 13:38:48 -08:00
Kevin KrakauerandgVisor bot 03d35d400f Automated rollback of changelist 580649803
PiperOrigin-RevId: 582102498
2023-11-13 15:30:48 -08:00
Kevin KrakauerandgVisor bot 40ee36ac4c Automated rollback of changelist 580051079
PiperOrigin-RevId: 580649803
2023-11-08 14:04:04 -08:00
Kevin KrakauerandgVisor bot b988b57921 runsc: reproduce NAT table inside gVisor only when non-default
... instead of depending on a flag.

In most cases the NAT table is in an all-ACCEPT default state:

```
root@5a7ce3a6c623:/# iptables -t nat -S
-P PREROUTING ACCEPT
-P INPUT ACCEPT
-P OUTPUT ACCEPT
-P POSTROUTING ACCEPT
```

In such cases we leave iptables off in the sandbox as a performance
optimization.

But when the table contains anything else, we now install those rules inside
the sandbox.

Turns out packetdrill installes a rule, so support for that rules is also added
in this CL.

PiperOrigin-RevId: 580051079
2023-11-06 22:05:48 -08:00
Kevin KrakauerandgVisor bot 89d6bf18c8 have gVisor use renamed buffer package
PiperOrigin-RevId: 537209194
2023-06-01 21:27:49 -07:00
Kevin KrakauerandgVisor bot c3da0e4f0d Automated rollback of changelist 531020857
PiperOrigin-RevId: 532863869
2023-05-17 12:09:12 -07:00
Kevin KrakauerandgVisor bot 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
Kevin KrakauerandgVisor bot d207727b3a 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
Andrei VaginandgVisor bot 1338761211 Fix reference leaks
PiperOrigin-RevId: 494027351
2022-12-08 16:38:26 -08:00
Kevin KrakauerandgVisor bot 4eca206fa4 netstack: introduce PacketBufferPtr
PiperOrigin-RevId: 479437464
2022-10-06 16:16:54 -07:00
Lucas ManningandgVisor bot 22ca20c0f1 Move checksum to its own package and optimize bufferv2 checksumming.
Checksum capabilities are logically separate from tcpip header definitions
and operations. It makes sense to extract this logic into its own package.
This is also necessary to avoid circular dependencies with bufferv2.

PiperOrigin-RevId: 473096480
2022-09-08 15:17:00 -07:00
Lucas ManningandgVisor bot 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
Lucas ManningandgVisor bot e64458ff08 Remove VectorisedView everywhere.
PiperOrigin-RevId: 453471156
2022-06-07 10:36:23 -07:00
Kevin KrakauerandgVisor bot a09c49b908 netstack: conntrack skips bad packets
Conntrack, like Linux, now skips bad packets entirely and lets the appropriate
layer deal with them. See net/netfilter/nf_conntrack_core.c:nf_conntrack_in.

This change shares the bad packet detection code between conntrack and TCP/UDP
so that they see the same packets as bad.

PiperOrigin-RevId: 452374626
2022-06-01 13:44:49 -07:00
Lucas ManningandgVisor bot f175fb526f Move prependable to its own package.
#CodeHealth

PiperOrigin-RevId: 452099435
2022-05-31 11:39:06 -07:00
Kevin KrakauerandgVisor bot 657b52920d netstack: replace PacketBufferList with slices
This has no impact on performance. It is in preparation for ticket references
(see final CL in the diffbase chain).

PiperOrigin-RevId: 450976957
2022-05-25 11:45:42 -07:00
Ayush RanjanandgVisor bot f6ed4523dc Reformat codebase.
PiperOrigin-RevId: 449358041
2022-05-17 17:48:35 -07:00
bemascandgVisor bot f375784d83 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 c6de0ac802 Drop return from IPTables.ReplaceTable
We always return the same thing.

PiperOrigin-RevId: 421893067
2022-01-14 12:58:24 -08:00
Ghanan GowripalanandgVisor bot 381a17d923 Support REJECT hook
PiperOrigin-RevId: 420174647
2022-01-06 17:11:19 -08:00
Ghanan GowripalanandgVisor bot 76776aad8b Perform Output hook for ICMPv4 Reply
Before this change, locally generated ICMPv4 replies would not
perform the Output hook so NAT will not be performed for locally
generated ICMPv4 replies. This change fixes that bug.

PiperOrigin-RevId: 418513563
2021-12-27 11:20:10 -08:00
Ghanan GowripalanandgVisor bot e49295ddeb Consider tid == tid.reply() when finalizing
https://github.com/google/gvisor/commit/4ab52f3cfdbe2c75c6525aa6732210a6d5d64b11
introduced a change to drop packets if we fail to insert the reply
tuple. This change did not take into consideration the case where the
original tuple ID is the same as the reply tuple ID. In this case, we
will have a "reply tuple conflict". However, since the reply tuple is
the same as the original tuple, we should not consider the conflict
as a real conflict since reply packets will map to the original tuple.

Updates #6850.

The change referenced above is cl/410368440.

PiperOrigin-RevId: 417634147
2021-12-21 09:24:58 -08:00