diff --git a/hypha/src/ctl/mod.rs b/hypha/src/ctl/mod.rs index 04c4ab4..2eb2662 100644 --- a/hypha/src/ctl/mod.rs +++ b/hypha/src/ctl/mod.rs @@ -15,7 +15,7 @@ use std::str::FromStr; use std::{fs, io, thread}; use termion::raw::IntoRawMode; use uuid::Uuid; -use xenclient::{DomainConfig, DomainDisk, XenClient}; +use xenclient::{DomainConfig, DomainDisk, DomainNetworkInterface, XenClient}; use xenstore::client::{XsdClient, XsdInterface}; pub struct Controller { @@ -121,6 +121,12 @@ impl Controller { writable: false, }, ], + vifs: vec![DomainNetworkInterface { + mac: "00:16:3E:46:0C:1B", + mtu: 1500, + bridge: "xenbr0", + script: "/etc/xen/scripts/vif-bridge", + }], filesystems: vec![], extra_keys: vec![ ("hypha/uuid".to_string(), uuid.to_string()), diff --git a/libs/xen/xenclient/examples/boot.rs b/libs/xen/xenclient/examples/boot.rs index 9edffe8..299a4ce 100644 --- a/libs/xen/xenclient/examples/boot.rs +++ b/libs/xen/xenclient/examples/boot.rs @@ -22,6 +22,7 @@ fn main() -> Result<()> { initrd_path: initrd_path.as_str(), cmdline: "debug elevator=noop", disks: vec![], + vifs: vec![], filesystems: vec![], extra_keys: vec![], }; diff --git a/libs/xen/xenclient/src/lib.rs b/libs/xen/xenclient/src/lib.rs index 7b1f752..d15483a 100644 --- a/libs/xen/xenclient/src/lib.rs +++ b/libs/xen/xenclient/src/lib.rs @@ -48,6 +48,14 @@ pub struct DomainFilesystem<'a> { pub tag: &'a str, } +#[derive(Debug)] +pub struct DomainNetworkInterface<'a> { + pub mac: &'a str, + pub mtu: u32, + pub bridge: &'a str, + pub script: &'a str, +} + #[derive(Debug)] pub struct DomainConfig<'a> { pub backend_domid: u32, @@ -58,6 +66,7 @@ pub struct DomainConfig<'a> { pub initrd_path: &'a str, pub cmdline: &'a str, pub disks: Vec>, + pub vifs: Vec>, pub filesystems: Vec>, pub extra_keys: Vec<(String, String)>, } @@ -352,6 +361,7 @@ impl XenClient { disk, )?; } + for (index, filesystem) in config.filesystems.iter().enumerate() { self.fs_9p_device_add( &dom_path, @@ -362,6 +372,17 @@ impl XenClient { filesystem, )?; } + + for (index, vif) in config.vifs.iter().enumerate() { + self.vif_device_add( + &dom_path, + &backend_dom_path, + config.backend_domid, + domid, + index, + vif, + )?; + } self.call.unpause_domain(domid)?; Ok(()) } @@ -493,6 +514,49 @@ impl XenClient { Ok(()) } + fn vif_device_add( + &mut self, + dom_path: &str, + backend_dom_path: &str, + backend_domid: u32, + domid: u32, + index: usize, + vif: &DomainNetworkInterface, + ) -> Result<()> { + let id = 20 + index as u64; + let backend_items: Vec<(&str, String)> = vec![ + ("frontend-id", domid.to_string()), + ("online", "1".to_string()), + ("state", "1".to_string()), + ("mac", vif.mac.to_string()), + ("mtu", vif.mtu.to_string()), + ("type", "vif".to_string()), + ("bridge", vif.bridge.to_string()), + ("handle", id.to_string()), + ("script", vif.script.to_string()), + ("hotplug-status", "".to_string()), + ]; + + let frontend_items: Vec<(&str, String)> = vec![ + ("backend-id", backend_domid.to_string()), + ("state", "1".to_string()), + ("mac", vif.mac.to_string()), + ("trusted", "1".to_string()), + ]; + + self.device_add( + "vif", + id, + dom_path, + backend_dom_path, + backend_domid, + domid, + frontend_items, + backend_items, + )?; + Ok(()) + } + #[allow(clippy::too_many_arguments)] fn device_add( &mut self,