xref: /cloud-hypervisor/virtio-devices/src/vsock/unix/mod.rs (revision 3ce0fef7fd546467398c914dbc74d8542e45cf6f)
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 //!
10 //! Check out `muxer.rs` for a more detailed explanation of the inner workings of this backend.
11 
12 mod muxer;
13 mod muxer_killq;
14 mod muxer_rxq;
15 
16 pub use muxer::VsockMuxer as VsockUnixBackend;
17 pub use Error as VsockUnixError;
18 
19 mod defs {
20     /// Maximum number of established connections that we can handle.
21     pub const MAX_CONNECTIONS: usize = 1023;
22 
23     /// Size of the muxer RX packet queue.
24     pub const MUXER_RXQ_SIZE: usize = 256;
25 
26     /// Size of the muxer connection kill queue.
27     pub const MUXER_KILLQ_SIZE: usize = 128;
28 }
29 
30 #[derive(Debug)]
31 pub enum Error {
32     /// Error converting from UTF-8
33     ConvertFromUtf8(std::str::Utf8Error),
34     /// Error registering a new epoll-listening FD.
35     EpollAdd(std::io::Error),
36     /// Error creating an epoll FD.
37     EpollFdCreate(std::io::Error),
38     /// The host made an invalid vsock port connection request.
39     InvalidPortRequest,
40     /// Error parsing integer.
41     ParseInteger(std::num::ParseIntError),
42     /// Error reading stream port.
43     ReadStreamPort(Box<Error>),
44     /// Error accepting a new connection from the host-side Unix socket.
45     UnixAccept(std::io::Error),
46     /// Error binding to the host-side Unix socket.
47     UnixBind(std::io::Error),
48     /// Error connecting to a host-side Unix socket.
49     UnixConnect(std::io::Error),
50     /// Error reading from host-side Unix socket.
51     UnixRead(std::io::Error),
52     /// Muxer connection limit reached.
53     TooManyConnections,
54 }
55 
56 type Result<T> = std::result::Result<T, Error>;
57 type MuxerConnection = super::csm::VsockConnection<std::os::unix::net::UnixStream>;
58