hyperv_ic_resources/
kvp.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Resources for the KVP IC.
5
6use mesh::MeshPayload;
7use mesh::rpc::FailableRpc;
8use vm_resource::ResourceId;
9use vm_resource::kind::VmbusDeviceHandleKind;
10
11/// A handle to the KVP IC.
12#[derive(MeshPayload)]
13pub struct KvpIcHandle {
14    /// The receiver for KVP connect requests.
15    pub recv: mesh::Receiver<KvpConnectRpc>,
16}
17
18impl ResourceId<VmbusDeviceHandleKind> for KvpIcHandle {
19    const ID: &'static str = "kvp_ic";
20}
21
22/// A connect request.
23#[derive(MeshPayload)]
24pub enum KvpConnectRpc {
25    /// Waits for the guest to connect, returning a sender for issuing KVP
26    /// requests and a receiver for determining when the KVP channel is no
27    /// longer available.
28    WaitForGuest(FailableRpc<(), (mesh::Sender<KvpRpc>, mesh::OneshotReceiver<()>)>),
29}
30
31/// A KVP request.
32#[derive(MeshPayload)]
33pub enum KvpRpc {
34    /// Sets a key/value pair in the KVP store.
35    Set(FailableRpc<SetParams, ()>),
36    /// Deletes a key/value pair from the KVP store.
37    Delete(FailableRpc<DeleteParams, ()>),
38    /// Enumerates the key/value pairs in the KVP store.
39    Enumerate(FailableRpc<EnumerateParams, Option<KeyValue>>),
40    /// Gets IP address information for a given adapter.
41    GetIpInfo(FailableRpc<GetIpInfoParams, IpInfo>),
42    /// Sets IP address information for a given adapter.
43    SetIpInfo(FailableRpc<SetIpInfoParams, ()>),
44}
45
46/// Parameters for setting a key/value pair in the KVP store.
47#[derive(MeshPayload, Clone, Debug)]
48pub struct SetParams {
49    /// The pool to use.
50    pub pool: KvpPool,
51    /// The key to set.
52    pub key: String,
53    /// The value.
54    pub value: Value,
55}
56
57/// Parameters for deleting a key/value pair in the KVP store.
58#[derive(MeshPayload, Clone, Debug)]
59pub struct DeleteParams {
60    /// The pool to use.
61    pub pool: KvpPool,
62    /// The key to delete.
63    pub key: String,
64}
65
66/// Parameters for enumerating key/value pairs in the KVP store.
67#[derive(MeshPayload, Clone, Debug)]
68pub struct EnumerateParams {
69    /// The pool to use.
70    pub pool: KvpPool,
71    /// The key to start enumerating from.
72    pub index: u32,
73}
74
75/// Parameters for getting IP address information for a given adapter.
76#[derive(MeshPayload, Clone, Debug)]
77pub struct GetIpInfoParams {
78    /// The MAC address to get the IP info for.
79    pub adapter_id: String,
80}
81
82/// The result of getting IP address information for a given adapter.
83#[derive(MeshPayload, Clone, Debug)]
84pub struct IpInfo {
85    /// Whether ipv4 is enabled.
86    pub ipv4: bool,
87    /// Whether ipv6 is enabled.
88    pub ipv6: bool,
89    /// Whether DHCP is enabled.
90    pub dhcp_enabled: bool,
91    /// The set of bound IPv4 addresses.
92    pub ipv4_addresses: Vec<Ipv4AddressInfo>,
93    /// The set of bound IPv6 addresses.
94    pub ipv6_addresses: Vec<Ipv6AddressInfo>,
95    /// The set of IPv4 gateways.
96    pub ipv4_gateways: Vec<std::net::Ipv4Addr>,
97    /// The set of IPv6 gateways.
98    pub ipv6_gateways: Vec<std::net::Ipv6Addr>,
99    /// The set of IPv4 DNS servers.
100    pub ipv4_dns_servers: Vec<std::net::Ipv4Addr>,
101    /// The set of IPv6 DNS servers.
102    pub ipv6_dns_servers: Vec<std::net::Ipv6Addr>,
103}
104
105/// Parameters for setting IP address information for a given adapter.
106#[derive(MeshPayload, Clone, Debug)]
107pub struct SetIpInfoParams {
108    /// The vmbus device ID of the adapter.
109    pub adapter_id: String,
110    /// The IP information to set.
111    ///
112    /// The IP origin information is ignored.
113    pub info: IpInfo,
114}
115
116/// Information about an IPv4 address.
117#[derive(MeshPayload, Clone, Debug)]
118pub struct Ipv4AddressInfo {
119    /// The IPv4 address.
120    pub address: std::net::Ipv4Addr,
121    /// The subnet mask.
122    pub subnet: std::net::Ipv4Addr,
123    /// The origin of the address.
124    pub origin: AddressOrigin,
125}
126
127/// Information about an IPv6 address.
128#[derive(MeshPayload, Clone, Debug)]
129pub struct Ipv6AddressInfo {
130    /// The IPv6 address.
131    pub address: std::net::Ipv6Addr,
132    /// The subnet prefix length.
133    pub subnet: u32,
134    /// The origin of the address.
135    pub origin: AddressOrigin,
136}
137
138/// The origin of an address.
139#[derive(MeshPayload, Clone, Debug)]
140pub enum AddressOrigin {
141    /// The origin is unknown.
142    Unknown,
143    /// The address was assigned statically.
144    Static,
145    /// The address was not assigned statically.
146    Other,
147}
148
149/// A key/value pair.
150#[derive(MeshPayload, Clone, Debug)]
151pub struct KeyValue {
152    /// The key.
153    pub key: String,
154    /// The value.
155    pub value: Value,
156}
157
158/// A value.
159#[derive(MeshPayload, Clone, Debug, PartialEq, Eq)]
160pub enum Value {
161    /// A string value.
162    String(String),
163    /// A 32-bit integer value.
164    U32(u32),
165    /// A 64-bit integer value.
166    U64(u64),
167}
168
169/// The pool to use for KVP operations.
170#[derive(Copy, Clone, Debug, MeshPayload)]
171pub enum KvpPool {
172    /// The guest pool.
173    Guest,
174    /// The external pool.
175    External,
176    /// The automatic pool.
177    Auto,
178    /// The automatic external pool.
179    AutoExternal,
180}