mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-03 21:21:32 +00:00
krata: event-based network backend startup and api enhancements
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
use std::net::IpAddr;
|
||||
use std::net::{IpAddr, Ipv6Addr};
|
||||
use std::{fs, net::Ipv4Addr, str::FromStr};
|
||||
|
||||
use advmac::MacAddr6;
|
||||
@ -113,7 +113,7 @@ impl GuestLauncher {
|
||||
];
|
||||
let cmdline = cmdline_options.join(" ");
|
||||
|
||||
let container_mac_string = container_mac.to_string().replace('-', ":");
|
||||
let guest_mac_string = container_mac.to_string().replace('-', ":");
|
||||
let gateway_mac_string = gateway_mac.to_string().replace('-', ":");
|
||||
|
||||
let mut extra_keys = vec![
|
||||
@ -140,7 +140,7 @@ impl GuestLauncher {
|
||||
),
|
||||
(
|
||||
"krata/network/guest/mac".to_string(),
|
||||
container_mac_string.clone(),
|
||||
guest_mac_string.clone(),
|
||||
),
|
||||
(
|
||||
"krata/network/gateway/ipv4".to_string(),
|
||||
@ -182,7 +182,7 @@ impl GuestLauncher {
|
||||
],
|
||||
consoles: vec![],
|
||||
vifs: vec![DomainNetworkInterface {
|
||||
mac: &container_mac_string,
|
||||
mac: &guest_mac_string,
|
||||
mtu: 1500,
|
||||
bridge: None,
|
||||
script: None,
|
||||
@ -199,14 +199,24 @@ impl GuestLauncher {
|
||||
domid,
|
||||
image: request.image.to_string(),
|
||||
loops: vec![],
|
||||
ipv4: Some(IpNetwork::new(
|
||||
guest_ipv4: Some(IpNetwork::new(
|
||||
IpAddr::V4(guest_ipv4),
|
||||
ipv4_network_mask as u8,
|
||||
)?),
|
||||
ipv6: Some(IpNetwork::new(
|
||||
guest_ipv6: Some(IpNetwork::new(
|
||||
IpAddr::V6(guest_ipv6),
|
||||
ipv6_network_mask as u8,
|
||||
)?),
|
||||
guest_mac: Some(guest_mac_string.clone()),
|
||||
gateway_ipv4: Some(IpNetwork::new(
|
||||
IpAddr::V4(Ipv4Addr::from_str(gateway_ipv4)?),
|
||||
ipv4_network_mask as u8,
|
||||
)?),
|
||||
gateway_ipv6: Some(IpNetwork::new(
|
||||
IpAddr::V6(Ipv6Addr::from_str(gateway_ipv6)?),
|
||||
ipv4_network_mask as u8,
|
||||
)?),
|
||||
gateway_mac: Some(gateway_mac_string.clone()),
|
||||
state: GuestState { exit_code: None },
|
||||
}),
|
||||
Err(error) => {
|
||||
|
@ -45,8 +45,12 @@ pub struct GuestInfo {
|
||||
pub domid: u32,
|
||||
pub image: String,
|
||||
pub loops: Vec<ContainerLoopInfo>,
|
||||
pub ipv4: Option<IpNetwork>,
|
||||
pub ipv6: Option<IpNetwork>,
|
||||
pub guest_ipv4: Option<IpNetwork>,
|
||||
pub guest_ipv6: Option<IpNetwork>,
|
||||
pub guest_mac: Option<String>,
|
||||
pub gateway_ipv4: Option<IpNetwork>,
|
||||
pub gateway_ipv6: Option<IpNetwork>,
|
||||
pub gateway_mac: Option<String>,
|
||||
pub state: GuestState,
|
||||
}
|
||||
|
||||
@ -130,25 +134,57 @@ impl RuntimeContext {
|
||||
.store
|
||||
.read_string(&format!("{}/krata/loops", &dom_path))
|
||||
.await?;
|
||||
let ipv4 = self
|
||||
let guest_ipv4 = self
|
||||
.xen
|
||||
.store
|
||||
.read_string(&format!("{}/krata/network/guest/ipv4", &dom_path))
|
||||
.await?;
|
||||
let ipv6 = self
|
||||
let guest_ipv6 = self
|
||||
.xen
|
||||
.store
|
||||
.read_string(&format!("{}/krata/network/guest/ipv6", &dom_path))
|
||||
.await?;
|
||||
let guest_mac = self
|
||||
.xen
|
||||
.store
|
||||
.read_string(&format!("{}/krata/network/guest/mac", &dom_path))
|
||||
.await?;
|
||||
let gateway_ipv4 = self
|
||||
.xen
|
||||
.store
|
||||
.read_string(&format!("{}/krata/network/gateway/ipv4", &dom_path))
|
||||
.await?;
|
||||
let gateway_ipv6 = self
|
||||
.xen
|
||||
.store
|
||||
.read_string(&format!("{}/krata/network/gateway/ipv6", &dom_path))
|
||||
.await?;
|
||||
let gateway_mac = self
|
||||
.xen
|
||||
.store
|
||||
.read_string(&format!("{}/krata/network/gateway/mac", &dom_path))
|
||||
.await?;
|
||||
|
||||
let ipv4 = if let Some(ipv4) = ipv4 {
|
||||
IpNetwork::from_str(&ipv4).ok()
|
||||
let guest_ipv4 = if let Some(guest_ipv4) = guest_ipv4 {
|
||||
IpNetwork::from_str(&guest_ipv4).ok()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let ipv6 = if let Some(ipv6) = ipv6 {
|
||||
IpNetwork::from_str(&ipv6).ok()
|
||||
let guest_ipv6 = if let Some(guest_ipv6) = guest_ipv6 {
|
||||
IpNetwork::from_str(&guest_ipv6).ok()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let gateway_ipv4 = if let Some(gateway_ipv4) = gateway_ipv4 {
|
||||
IpNetwork::from_str(&gateway_ipv4).ok()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let gateway_ipv6 = if let Some(gateway_ipv6) = gateway_ipv6 {
|
||||
IpNetwork::from_str(&gateway_ipv6).ok()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
@ -173,8 +209,12 @@ impl RuntimeContext {
|
||||
domid,
|
||||
image,
|
||||
loops,
|
||||
ipv4,
|
||||
ipv6,
|
||||
guest_ipv4,
|
||||
guest_ipv6,
|
||||
guest_mac,
|
||||
gateway_ipv4,
|
||||
gateway_ipv6,
|
||||
gateway_mac,
|
||||
state,
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user