containers / gvisor-tap-vsock

A new network stack based on gVisor
Apache License 2.0
269 stars 50 forks source link

[spike] Rework rx/tx loop in pkg/tap/switch.go? #390

Open cfergeau opened 2 months ago

cfergeau commented 2 months ago

The rx/tx code in pkg/tap/switch.go is a bit hard to follow, with the protocol.Stream() tests, and the Buf()/Read()/Write() code in the stream case. What the code is doing is to send data to/from the hypervisor. For some hypervisors (qemu, hyperkit, stdio), the size must be sent before the data, either as a 16 bit little-endian, or as a 32 bit little-endian data. This is what the code calls 'stream', and the Buf()/Read()/Write() methods from the streamProtocol interface are only used to write this 2 or 4 bytes for the size.

I've tried to rework this code in https://github.com/cfergeau/gvisor-tap-vsock/tree/rxtx:

This seems to simplify the code, but is untested, and I don't want to spend more time on this right away. What needs to be done to complete this:

One potential further improvement is to see if we can remove this allocation from rxStream using https://pkg.go.dev/bytes#Buffer