824 Commits

Author SHA1 Message Date
Lucas Manning faac8f36cd Add support for PACKET_STATISTICS.
PiperOrigin-RevId: 725271073
2025-02-10 10:46:54 -08:00
Lucas Manning 9c490f813d Implement GetSockOpt PACKET_HDRLEN and add a test for tcpdump.
PiperOrigin-RevId: 724445536
2025-02-07 13:06:14 -08:00
Lucas Manning 6194338723 Add support for setting PACKET_VERSION for PACKET_MMAP.
tcpdump requires TPACKET_V2 to work properly.

PiperOrigin-RevId: 723670574
2025-02-05 15:19:34 -08:00
Lucas Manning 198ac833f1 Create the interfaces for PACKET_MMAP endpoints to implement.
PiperOrigin-RevId: 721823737
2025-01-31 10:43:05 -08:00
Jing Chen a500a2c751 Defalke test target pkg/tcpip/stack:bridge_test.
There is a race in the test between WritePacketToRemote and FindFDBEntry, even
though it rarely happens, we just enforce FindFDBEntry to wait for
WritePacketToRemote's completion here.

PiperOrigin-RevId: 721747159
2025-01-31 06:10:20 -08:00
Andrei Vagin f010ae01ac Fix a few typos 2025-01-29 21:16:51 -08:00
Kevin Krakauer 1375c611d8 cleanup GRO TODOs
GRO is implemented. We don't need to leave TODOs for every possible
optimization.

PiperOrigin-RevId: 720613096
2025-01-28 10:02:54 -08:00
Nayana Bidari cd31d0522a Enable netstack save/restore in cloud/gvisor by default.
PiperOrigin-RevId: 712978128
2025-01-07 11:19:26 -08:00
Nayana Bidari a3e5887415 Changes to support netstack save restore.
- Added a new Stats() method in inet.Stack to get the saved stats
during restore.
- Mark stack.nic, tcpip.Route and stack.addressState structs as "nosave".
These fields should not be saved because the IP addresses and routes can
change during restore and new configuration of routes and IP addresses will be
extracted from the restore spec and initialized in the saved stack.
- Changes in Restore() method in icmp, udp, tcp, packet and raw endpoint files
to support save restore of these endpoints. These changes are flag guarded by
the TESTONLY-save-restore-netstack flag.

PiperOrigin-RevId: 707639274
2024-12-18 12:52:22 -08:00
Lucas Manning afa323bd30 Replace most instances of IncRef with Clone.
Incrementing the reference count of a packet as a means of granting ownership
is unsafe when the packet is shared across gorountines. The underlying buffer's
reference count is unchanged since it "technically" has the same owning
PacketBuffer, which means different goroutines operating on the underlying
buffer (and packet itself) race.

Clones are roughly as fast as IncRefs because the PacketBuffers allocate from
a pool and the underlying buffers are cloned with copy-on-write
semantics.

I've left IncRef in places where the original packet in obviously going out of
scope at the end of the function or in some tests.

Reported-by: syzbot+e026046f4bf8ad09ae1f@syzkaller.appspotmail.com
Reported-by: syzbot+559365d6050db4b30e0f@syzkaller.appspotmail.com
Reported-by: syzbot+63c78a2c88a5744c636b@syzkaller.appspotmail.com
PiperOrigin-RevId: 705676806
2024-12-12 17:09:40 -08:00
Jing Chen c88ffa321e Returns ENOBUFS when writing to a veth device whose buffer is full.
A task is stuck when it keeps sendMsg w/o any recvMsg  until  the number of
message exceeds the buffer limit. The change also significantly bumps the
limit from 64 to 1000 for a larger buffer.

Reported-by: syzbot+8788f5c1ba95e12ab07d@syzkaller.appspotmail.com
Reported-by: syzbot+67759fceac0c30ece991@syzkaller.appspotmail.com
PiperOrigin-RevId: 704904404
2024-12-10 17:35:54 -08:00
Nayana Bidari 0335cf778d Remove TODOs for fields which are restored in netstack.
insecureRNG and secureRNG stack fields are restored in stack.afterLoad()
tcp processor fields are restored in tcp endpoint.Restore()

PiperOrigin-RevId: 704477536
2024-12-09 17:37:04 -08:00
Jing Chen 54eb79b6e8 Acquire rlock when reading link address from the bridge.
It happens along with the other issue when the veth device buffer is full,
then the task is stuck and still have the bridge's lock (RLock) via
DeliverNetworkPacket. When the second task reads the bridge's MAC address,
it waits forever for the first task to release the rlock. Using RLock can
allow the concurrent access to the MAC address, it dones't have to be
blocked until the messages are sent.

Reported-by: syzbot+1d6d1d8f47eae4e308dc@syzkaller.appspotmail.com
PiperOrigin-RevId: 704163976
2024-12-08 23:47:51 -08:00
Lucas Manning d16d0c71e1 Add method to forwarder to handle experiment option values.
PiperOrigin-RevId: 703625219
2024-12-06 14:59:02 -08:00
Kevin Krakauer 70dc6ea4ce netstack: re-enable checkescape
This was enabled in cl/452137751 and accidentally turned back off in
cl/479437464 (probably me messing up a rebase).

PiperOrigin-RevId: 703146788
2024-12-05 09:46:14 -08:00
Lucas Manning cd70b0a4c0 Add support for the experiment option header in IPv6.
PiperOrigin-RevId: 702771719
2024-12-04 10:25:30 -08:00
Lucas Manning 9eb188d881 Require special NIC settings for enabling experiment IP option passing.
PiperOrigin-RevId: 702465832
2024-12-03 14:18:05 -08:00
Lucas Manning 2267c24a41 Add support for custom socket options and setting the experiment IP option.
PiperOrigin-RevId: 700011458
2024-11-25 09:43:21 -08:00
Kevin Krakauer 113b24b432 netstack: move TCP state to tcp package and cleanup probe
TCP probe support is implemented, unnecessarily, across the stack and and tcp
packages. It can live entirely in tcp. Additionally, it is only ever set at
initialization time, so support for dynamically adding/removing the probe isn't
necesary.

The probe is getting in the way of adding debugging for b/339664055.

PiperOrigin-RevId: 699330364
2024-11-22 17:11:04 -08:00
Nayana Bidari df9ba5fb67 Restore listening connections when netstack s/r is enabled.
This CL restores the listening connections when netstack s/r is enabled.
The changes include:
- New method as a workaround to replace the new routes and nics to the loaded
stack after restore.
- New Restore() for transport layer protocols to restore the protocol level
background workers.
- Adds afterLoad() method for fdbased processors.
- Adds a test to verify listening connection is restored after checkpointing
with netstack s/r enabled.
- Few other changes to save restore fields to enable netstack s/r.

PiperOrigin-RevId: 698453124
2024-11-20 11:13:57 -08:00
Jing Chen 94db2b2de7 Implement a basic bridge FDB by leanrning.
Bridge uses bridge FDB to decide which port(s) it forwards the
received packets to.

The bridge FDB, when the bridge receives a packet, records the packet's source
MAC address and the bridge port where the packet is received. The received
packet's source MAC address will be the lookup key to the bridge FDB.

When deciding a forward port, the bridge looks for a FDB key which matches
the packet's destination MAC address, the associated port from the FDB will
forward the packet. Otherwise, the packet will flood to all available bridge
ports.

The FDB will never be garbage collected until the nic device is removed
from the bridge.

PiperOrigin-RevId: 693143851
2024-11-04 17:25:34 -08:00
Koichi Shiraishi 0cf77c02f8 all: remove use io/ioutil deprecated package & fix some deprecated thing
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
2024-10-10 20:36:24 +09:00
Jing Chen 5e8dd6482c Disallow setting a coordinator for a coordinator device.
The error code is based on the runc's behavior:

```shell
# ip link set dev br0 master br0
Error: Can not enslave a bridge to a bridge.
# echo $?
2
```

Reported-by: syzbot+9dcefbdcc9ecdeb4df96@syzkaller.appspotmail.com
PiperOrigin-RevId: 679761515
2024-09-27 16:13:45 -07:00
Jing Chen f681bcc095 Implement RTM_DELROUTE in netstack.
PiperOrigin-RevId: 675711612
2024-09-17 14:33:41 -07:00
Nayana Bidari 50d46c627c Initiliaze rand variables after netstack is restored.
Add a afterLoad method on netstack.Stack to initialize rand variables after
netstack is restored.

PiperOrigin-RevId: 675278982
2024-09-16 13:59:04 -07:00