net_backend_resources/
lib.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Resource definitions for network backends (endpoints).
5//!
6//! TODO: move the resource definitions to separate crates for each endpoint.
7
8#![forbid(unsafe_code)]
9
10pub mod mac_address;
11
12/// Null backend.
13pub mod null {
14    use mesh::MeshPayload;
15    use vm_resource::ResourceId;
16    use vm_resource::kind::NetEndpointHandleKind;
17
18    /// Handle to a null network endpoint, which drops sent packets and never
19    /// receives packets.
20    #[derive(MeshPayload)]
21    pub struct NullHandle;
22
23    impl ResourceId<NetEndpointHandleKind> for NullHandle {
24        const ID: &'static str = "null";
25    }
26}
27
28/// Consomme backend.
29pub mod consomme {
30    use mesh::MeshPayload;
31    use vm_resource::ResourceId;
32    use vm_resource::kind::NetEndpointHandleKind;
33
34    /// Handle to a Consomme network endpoint.
35    #[derive(MeshPayload)]
36    pub struct ConsommeHandle {
37        /// The CIDR of the network to use.
38        pub cidr: Option<String>,
39    }
40
41    impl ResourceId<NetEndpointHandleKind> for ConsommeHandle {
42        const ID: &'static str = "consomme";
43    }
44}
45
46/// Windows vmswitch DirectIO backend.
47pub mod dio {
48    use guid::Guid;
49    use mesh::MeshPayload;
50    use vm_resource::ResourceId;
51    use vm_resource::kind::NetEndpointHandleKind;
52
53    /// A Hyper-V networking switch port ID.
54    #[derive(Copy, Clone, MeshPayload)]
55    pub struct SwitchPortId {
56        /// The switch ID.
57        pub switch: Guid,
58        /// The allocated port ID.
59        pub port: Guid,
60    }
61
62    /// Handle to a DirectIO network endpoint.
63    #[derive(MeshPayload)]
64    pub struct WindowsDirectIoHandle {
65        /// The allocated switch port ID.
66        pub switch_port_id: SwitchPortId,
67    }
68
69    impl ResourceId<NetEndpointHandleKind> for WindowsDirectIoHandle {
70        const ID: &'static str = "dio";
71    }
72}
73
74/// Linux TAP backend.
75pub mod tap {
76    use mesh::MeshPayload;
77    use vm_resource::ResourceId;
78    use vm_resource::kind::NetEndpointHandleKind;
79
80    /// A handle to a TAP device.
81    #[derive(MeshPayload)]
82    pub struct TapHandle {
83        /// The name of the TAP device.
84        ///
85        /// FUTURE: change this to a pre-opened `File`.
86        pub name: String,
87    }
88
89    impl ResourceId<NetEndpointHandleKind> for TapHandle {
90        const ID: &'static str = "tap";
91    }
92}