1434a5d0eSSebastien Boeuf // Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2434a5d0eSSebastien Boeuf // SPDX-License-Identifier: Apache-2.0 3434a5d0eSSebastien Boeuf // 4434a5d0eSSebastien Boeuf 5f6236087SAlyssa Ross //! This module implements the Unix Domain Sockets backend for vsock - a mediator between 6f6236087SAlyssa Ross //! guest-side AF_VSOCK sockets and host-side AF_UNIX sockets. The heavy lifting is performed by 7f6236087SAlyssa Ross //! `muxer::VsockMuxer`, a connection multiplexer that uses `super::csm::VsockConnection` for 8f6236087SAlyssa Ross //! handling vsock connection states. 9f6236087SAlyssa Ross //! 10f6236087SAlyssa Ross //! Check out `muxer.rs` for a more detailed explanation of the inner workings of this backend. 11f6236087SAlyssa Ross 12434a5d0eSSebastien Boeuf mod muxer; 13434a5d0eSSebastien Boeuf mod muxer_killq; 14434a5d0eSSebastien Boeuf mod muxer_rxq; 15434a5d0eSSebastien Boeuf 16434a5d0eSSebastien Boeuf pub use muxer::VsockMuxer as VsockUnixBackend; 1778b0f68bSPhilipp Schuster use thiserror::Error; 18475e487aSSebastien Boeuf pub use Error as VsockUnixError; 19434a5d0eSSebastien Boeuf 20434a5d0eSSebastien Boeuf mod defs { 21434a5d0eSSebastien Boeuf /// Maximum number of established connections that we can handle. 22434a5d0eSSebastien Boeuf pub const MAX_CONNECTIONS: usize = 1023; 23434a5d0eSSebastien Boeuf 24434a5d0eSSebastien Boeuf /// Size of the muxer RX packet queue. 25434a5d0eSSebastien Boeuf pub const MUXER_RXQ_SIZE: usize = 256; 26434a5d0eSSebastien Boeuf 27434a5d0eSSebastien Boeuf /// Size of the muxer connection kill queue. 28434a5d0eSSebastien Boeuf pub const MUXER_KILLQ_SIZE: usize = 128; 29434a5d0eSSebastien Boeuf } 30434a5d0eSSebastien Boeuf 31b2993fb2SPhilipp Schuster #[derive(Error, Debug)] 32434a5d0eSSebastien Boeuf pub enum Error { 330a7bcc9aSSebastien Boeuf /// Error converting from UTF-8 34*8e2973feSPhilipp Schuster #[error("Error converting from UTF-8")] 35b2993fb2SPhilipp Schuster ConvertFromUtf8(#[source] std::str::Utf8Error), 36434a5d0eSSebastien Boeuf /// Error registering a new epoll-listening FD. 37*8e2973feSPhilipp Schuster #[error("Error registering a new epoll-listening FD")] 38b2993fb2SPhilipp Schuster EpollAdd(#[source] std::io::Error), 39434a5d0eSSebastien Boeuf /// Error creating an epoll FD. 40*8e2973feSPhilipp Schuster #[error("Error creating an epoll FD")] 41b2993fb2SPhilipp Schuster EpollFdCreate(#[source] std::io::Error), 42434a5d0eSSebastien Boeuf /// The host made an invalid vsock port connection request. 43b2993fb2SPhilipp Schuster #[error("The host made an invalid vsock port connection request")] 44434a5d0eSSebastien Boeuf InvalidPortRequest, 450a7bcc9aSSebastien Boeuf /// Error parsing integer. 46*8e2973feSPhilipp Schuster #[error("Error parsing integer")] 47b2993fb2SPhilipp Schuster ParseInteger(#[source] std::num::ParseIntError), 480a7bcc9aSSebastien Boeuf /// Error reading stream port. 49*8e2973feSPhilipp Schuster #[error("Error reading stream port")] 50b2993fb2SPhilipp Schuster ReadStreamPort(#[source] Box<Error>), 51434a5d0eSSebastien Boeuf /// Error accepting a new connection from the host-side Unix socket. 52*8e2973feSPhilipp Schuster #[error("Error accepting a new connection from the host-side Unix socket")] 53b2993fb2SPhilipp Schuster UnixAccept(#[source] std::io::Error), 54434a5d0eSSebastien Boeuf /// Error binding to the host-side Unix socket. 55*8e2973feSPhilipp Schuster #[error("Error binding to the host-side Unix socket")] 56b2993fb2SPhilipp Schuster UnixBind(#[source] std::io::Error), 57434a5d0eSSebastien Boeuf /// Error connecting to a host-side Unix socket. 58*8e2973feSPhilipp Schuster #[error("Error connecting to a host-side Unix socket")] 59b2993fb2SPhilipp Schuster UnixConnect(#[source] std::io::Error), 60434a5d0eSSebastien Boeuf /// Error reading from host-side Unix socket. 61*8e2973feSPhilipp Schuster #[error("Error reading from host-side Unix socket")] 62b2993fb2SPhilipp Schuster UnixRead(#[source] std::io::Error), 63434a5d0eSSebastien Boeuf /// Muxer connection limit reached. 64b2993fb2SPhilipp Schuster #[error("Muxer connection limit reached")] 65434a5d0eSSebastien Boeuf TooManyConnections, 66434a5d0eSSebastien Boeuf } 67434a5d0eSSebastien Boeuf 68434a5d0eSSebastien Boeuf type Result<T> = std::result::Result<T, Error>; 69434a5d0eSSebastien Boeuf type MuxerConnection = super::csm::VsockConnection<std::os::unix::net::UnixStream>; 70