vmm/devices/virtio/vsock/unix/
mod.rs

1// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3//
4
5/// This module implements the Unix Domain Sockets backend for vsock - a mediator between
6/// guest-side AF_VSOCK sockets and host-side AF_UNIX sockets. The heavy lifting is performed by
7/// `muxer::VsockMuxer`, a connection multiplexer that uses `super::csm::VsockConnection` for
8/// handling vsock connection states.
9/// Check out `muxer.rs` for a more detailed explanation of the inner workings of this backend.
10mod muxer;
11mod muxer_killq;
12mod muxer_rxq;
13
14pub use muxer::VsockMuxer as VsockUnixBackend;
15
16use crate::devices::virtio::vsock::csm::VsockConnectionBackend;
17
18mod defs {
19    /// Maximum number of established connections that we can handle.
20    pub const MAX_CONNECTIONS: usize = 1023;
21
22    /// Size of the muxer RX packet queue.
23    pub const MUXER_RXQ_SIZE: u32 = 256;
24
25    /// Size of the muxer connection kill queue.
26    pub const MUXER_KILLQ_SIZE: u32 = 128;
27}
28
29/// Vsock backend related errors.
30#[derive(Debug, thiserror::Error, displaydoc::Display)]
31pub enum VsockUnixBackendError {
32    /// Error registering a new epoll-listening FD: {0}
33    EpollAdd(std::io::Error),
34    /// Error creating an epoll FD: {0}
35    EpollFdCreate(std::io::Error),
36    /// The host made an invalid vsock port connection request.
37    InvalidPortRequest,
38    /// Error accepting a new connection from the host-side Unix socket: {0}
39    UnixAccept(std::io::Error),
40    /// Error binding to the host-side Unix socket: {0}
41    UnixBind(std::io::Error),
42    /// Error connecting to a host-side Unix socket: {0}
43    UnixConnect(std::io::Error),
44    /// Error reading from host-side Unix socket: {0}
45    UnixRead(std::io::Error),
46    /// Muxer connection limit reached.
47    TooManyConnections,
48}
49
50type MuxerConnection = super::csm::VsockConnection<std::os::unix::net::UnixStream>;
51
52impl VsockConnectionBackend for std::os::unix::net::UnixStream {}