microvmi/api/
params.rs

1//! This module describes initialization parameters for all libmicrovmi drivers
2//!
3//! The [`DriverInitParams`](struct.DriverInitParams.html) is used to pass additional driver initialization parameters.
4//! You might want to check it's documentation for examples on how to initialize your driver.
5
6/// Xen initialization parameters
7#[derive(Debug, Clone, PartialEq)]
8pub enum XenInitParams {}
9
10/// KVM initialization parameters
11#[derive(Debug, Clone, PartialEq)]
12pub enum KVMInitParams {
13    UnixSocket { path: String },
14}
15
16/// Memflow connector parameters
17///
18/// This enumeration reflects the possibilities to initialize Memflow
19/// - default: will simply forward the string arguments to the connector
20// TODO
21// - [`qemu`](https://github.com/memflow/memflow-qemu)
22// - [`kvm`](https://github.com/memflow/memflow-kvm)
23// - [`pcileech`](https://github.com/memflow/memflow-pcileech)
24// - [`coredump`](https://github.com/memflow/memflow-coredump)
25#[derive(Debug, Clone, PartialEq)]
26pub enum MemflowConnectorParams {
27    // allow to pass an abritrary list of Strings as parameters
28    Default { args: Vec<String> },
29    // TODO
30    // // optional vm_name, otherwise will search for the first QEMU process
31    // QEMUProcFs {
32    //     vm_name: Option<String>,
33    // },
34    // KVM {
35    //     pid: u32,
36    // },
37    // // default value for device: "FPGA"
38    // PCILeech {
39    //     device: Option<String>,
40    //     memmap: Option<String>,
41    // },
42    // Coredump {
43    //     filepath: String,
44    // },
45}
46
47/// Memflow initialization parameters
48#[derive(Debug, Default, Clone, PartialEq)]
49pub struct MemflowInitParams {
50    /// connector name
51    pub connector_name: String,
52    /// optional connector initialization parameters
53    pub connector_args: Option<MemflowConnectorParams>,
54}
55
56/// VirtualBox initialization parameters
57#[derive(Debug, Clone, PartialEq)]
58pub enum VBoxInitParams {}
59
60/// Common initialization parameters
61///
62/// These parameters are shared by two or more drivers, and are stored in this struct
63/// to avoid duplication and simplify the API
64#[repr(C)]
65#[derive(Default, Debug, Clone, PartialEq)]
66pub struct CommonInitParams {
67    pub vm_name: String,
68}
69
70/// This struct is used to specify the initialization parameters for all drivers
71///
72/// # Examples
73///
74/// ```no_run
75/// // Xen
76/// // common.vm_name: mandatory
77/// use microvmi::api::params::{DriverInitParams, CommonInitParams, KVMInitParams, MemflowInitParams};
78/// let init_params = DriverInitParams {
79///     common: Some(CommonInitParams { vm_name: String::from("windows10")}),
80///     ..Default::default()
81/// };
82/// // KVM
83/// // common.vm_name: mandatory
84/// // kvm.unix_socket: mandatory
85/// let init_params = DriverInitParams {
86///     common: Some(CommonInitParams { vm_name: String::from("windows10")}),
87///     kvm: Some(KVMInitParams::UnixSocket { path: String::from("/tmp/introspector")}),
88///     ..Default::default()
89/// };
90/// // VirtualBox
91/// // common.vm_name: mandatory
92/// let init_params = DriverInitParams {
93///     common: Some(CommonInitParams { vm_name: String::from("windows10")}),
94///     ..Default::default()
95/// };
96/// // Memflow
97/// // memflow.connector_name: mandatory
98/// // memflow.connector_args: optional
99/// let init_params = DriverInitParams {
100///     memflow: Some(MemflowInitParams { connector_name: String::from("qemu"), ///
101///         ..Default::default()}),
102///     ..Default::default()
103/// };
104/// ```
105#[derive(Default, Debug, Clone, PartialEq)]
106pub struct DriverInitParams {
107    pub common: Option<CommonInitParams>,
108    pub xen: Option<XenInitParams>,
109    pub kvm: Option<KVMInitParams>,
110    pub memflow: Option<MemflowInitParams>,
111    pub virtualbox: Option<VBoxInitParams>,
112}