hypha: begin working on network support

This commit is contained in:
Alex Zenla 2024-02-01 13:56:03 +00:00
parent dc5adcb413
commit e73cfa92c8
No known key found for this signature in database
GPG Key ID: 067B238899B51269
3 changed files with 72 additions and 1 deletions

View File

@ -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()),

View File

@ -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![],
};

View File

@ -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<DomainDisk<'a>>,
pub vifs: Vec<DomainNetworkInterface<'a>>,
pub filesystems: Vec<DomainFilesystem<'a>>,
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,