Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
patches/ | 25-Apr-2025 | - | 239 | 238 | ||
src/ | 25-Apr-2025 | - | 1,419 | 942 | ||
.cargo-checksum.json | D | 25-Apr-2025 | 492 | 1 | 1 | |
Android.bp | D | 25-Apr-2025 | 764 | 29 | 25 | |
CHANGELOG.md | D | 25-Apr-2025 | 1.1 KiB | 63 | 35 | |
Cargo.toml | D | 25-Apr-2025 | 1.2 KiB | 49 | 42 | |
LICENSE | D | 25-Apr-2025 | 12.6 KiB | 233 | 197 | |
METADATA | D | 25-Apr-2025 | 389 | 18 | 17 | |
MODULE_LICENSE_APACHE2 | D | 25-Apr-2025 | 0 | |||
MODULE_LICENSE_BSD | D | 25-Apr-2025 | 0 | |||
README.md | D | 25-Apr-2025 | 2.9 KiB | 64 | 49 | |
cargo_embargo.json | D | 25-Apr-2025 | 182 | 12 | 11 |
README.md
1# virtio-vsock 2 3The `virtio-vsock` crate provides abstractions for the components of the 4[vsock device](https://docs.oasis-open.org/virtio/virtio/v1.1/csprd01/virtio-v1.1-csprd01.html#x1-39000010). 5For now, it offers only an implementation for the vsock packet. 6The support is provided only for stream sockets. 7 8The vsock device is a socket device that can be used as a communication 9mechanism between the host and the guest. It is implemented using the virtio 10standard. The vsock device has three queues: an RX one, a TX one and an event 11one. In a simplified manner, the communication between the host and the guest 12is realized with the buffers that are exchanged using the device’s queues. 13These buffers are called packets in the vsock device context. 14 15## Vsock Packet 16 17### Design 18 19The virtio vsock packet is defined in the standard as having a header of type 20`virtio_vsock_hdr` and an optional `data` array of bytes. There are multiple 21operations that can be requested within a packet, e.g. `VIRTIO_VSOCK_OP_RST` 22for resetting the connection, `VIRTIO_VSOCK_OP_RW` for sending payload. Most 23operations are of the `VIRTIO_VSOCK_OP_RW` type, which means for data transfer, 24and the other ones are used for connection and buffer space management. 25`data` is non-empty only for the `VIRTIO_VSOCK_OP_RW` operations. 26 27The abstraction used for the packet implementation is the `VsockPacket`. 28It is using 29[`VolatileSlice`](https://github.com/rust-vmm/vm-memory/blob/fc7153a4f63c352d1fa9419c4654a6c9aec408cb/src/volatile_memory.rs#L266)s 30for representing the header and the data. We chose to use the `VolatileSlice` 31because it's a safe wrapper over the unsafe Rust's raw pointers, and it is also 32generic enough to allow creating packets from pointers to slices. Going with a 33`GuestMemory` based approach would not make such configuration possible. 34More details (including design 35limitations) in [the `packet`'s module-level documentation](src/packet.rs). 36 37A `VsockPacket` instance is created by parsing a descriptor chain from either 38the TX or the RX virtqueue. The `VsockPacket` API is also providing methods for 39creating/setting up packets directly from pointers to slices. 40It also offers setters and getters for each `virtio_vsock_hdr` field (e.g. 41*src_cid*, *dst_port*, *op*). 42 43### Usage 44 45The driver queues receive buffers on the RX virtqueue, and outgoing packets on 46the TX virtqueue. The device processes the RX virtqueue using 47`VsockPacket::from_rx_virtq_chain` and fills the buffers with data from the 48vsock backend. 49On the TX side, the device processes the TX queue using 50`VsockPacket::from_tx_virtq_chain`, packages the read buffers as vsock packets, 51and then sends them to the backend. 52 53### Examples 54 55Examples of usage can be found as documentation tests in 56[the packet module](src/packet.rs). 57 58## License 59 60This project is licensed under either of 61 62- [Apache License](http://www.apache.org/licenses/LICENSE-2.0), Version 2.0 63- [BSD-3-Clause License](https://opensource.org/licenses/BSD-3-Clause) 64