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 use thiserror::Error; 18 pub use Error as VsockUnixError; 19 20 mod defs { 21 /// Maximum number of established connections that we can handle. 22 pub const MAX_CONNECTIONS: usize = 1023; 23 24 /// Size of the muxer RX packet queue. 25 pub const MUXER_RXQ_SIZE: usize = 256; 26 27 /// Size of the muxer connection kill queue. 28 pub const MUXER_KILLQ_SIZE: usize = 128; 29 } 30 31 #[derive(Error, Debug)] 32 pub enum Error { 33 /// Error converting from UTF-8 34 #[error("Error converting from UTF-8: {0}")] 35 ConvertFromUtf8(#[source] std::str::Utf8Error), 36 /// Error registering a new epoll-listening FD. 37 #[error("Error registering a new epoll-listening FD: {0}")] 38 EpollAdd(#[source] std::io::Error), 39 /// Error creating an epoll FD. 40 #[error("Error creating an epoll FD: {0}")] 41 EpollFdCreate(#[source] std::io::Error), 42 /// The host made an invalid vsock port connection request. 43 #[error("The host made an invalid vsock port connection request")] 44 InvalidPortRequest, 45 /// Error parsing integer. 46 #[error("Error parsing integer: {0}")] 47 ParseInteger(#[source] std::num::ParseIntError), 48 /// Error reading stream port. 49 #[error("Error reading stream port: {0}")] 50 ReadStreamPort(#[source] Box<Error>), 51 /// Error accepting a new connection from the host-side Unix socket. 52 #[error("Error accepting a new connection from the host-side Unix socket: {0}")] 53 UnixAccept(#[source] std::io::Error), 54 /// Error binding to the host-side Unix socket. 55 #[error("Error binding to the host-side Unix socket: {0}")] 56 UnixBind(#[source] std::io::Error), 57 /// Error connecting to a host-side Unix socket. 58 #[error("Error connecting to a host-side Unix socket: {0}")] 59 UnixConnect(#[source] std::io::Error), 60 /// Error reading from host-side Unix socket. 61 #[error("Error reading from host-side Unix socket: {0}")] 62 UnixRead(#[source] std::io::Error), 63 /// Muxer connection limit reached. 64 #[error("Muxer connection limit reached")] 65 TooManyConnections, 66 } 67 68 type Result<T> = std::result::Result<T, Error>; 69 type MuxerConnection = super::csm::VsockConnection<std::os::unix::net::UnixStream>; 70