Skip to content

Commit

Permalink
Properly configure default gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenSoeters committed Mar 12, 2023
1 parent 71ca556 commit df5270d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
8 changes: 8 additions & 0 deletions auraed/src/hypervisor/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// #[async_trait]
// pub trait Hypervisor: Send + Sync {
// async fn create_vm(&self, id: &str, netns: Option<String>) -> Result<()>;
// async fn start_vm(&self, timeout: i32) -> Result<()>;
// async fn stop_vm(&self) -> Result<()>;
// async fn add_device(&self, device: device::Device) -> Result<()>;
// async fn remove_device(&self, device: device::Device) -> Result<()>;
// }
19 changes: 13 additions & 6 deletions auraed/src/init/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,23 +144,30 @@ async fn configure_loopback(handle: &Handle) -> Result<(), NetworkError> {
async fn configure_nic(handle: &Handle) -> Result<(), NetworkError> {
const DEFAULT_NET_DEV: &str = "eth0";
const DEFAULT_NET_DEV_IPV6: &str = "fe80::2";
const DEFAULT_NET_DEV_IPV6_GATEWAY: &str = "fe80::1";
const DEFAULT_NET_DEV_IPV6_SUBNET: &str = "/64";

trace!("configure {DEFAULT_NET_DEV}");

let ipv6 = format!("{DEFAULT_NET_DEV_IPV6}{DEFAULT_NET_DEV_IPV6_SUBNET}")
let ipv6_addr =
format!("{DEFAULT_NET_DEV_IPV6}{DEFAULT_NET_DEV_IPV6_SUBNET}")
.parse::<Ipv6Network>()
.expect("valid ipv6 address");

let gateway = DEFAULT_NET_DEV_IPV6_GATEWAY
.to_string()
.parse::<Ipv6Network>()
.expect("valid ipv6 address");
.expect("gateway");

add_address(handle, DEFAULT_NET_DEV.to_owned(), ipv6).await?;
add_address(handle, DEFAULT_NET_DEV.to_owned(), ipv6_addr).await?;

set_link_up(handle, DEFAULT_NET_DEV.to_owned()).await?;

add_route_v6(
handle,
DEFAULT_NET_DEV.to_owned(),
ipv6,
"::/0".parse::<Ipv6Network>().expect("valid ipv6 address"),
gateway,
)
.await?;

Expand Down Expand Up @@ -293,9 +300,9 @@ async fn add_route_v6(
.route()
.add()
.v6()
.destination_prefix(dest.ip(), dest.prefix())
.source_prefix(source.ip(), source.prefix())
.gateway(dest.ip())
.output_interface(link_index)
.pref_source(source.ip())
.execute()
.await
.map_err(|e| NetworkError::ErrorAddingRoute {
Expand Down
20 changes: 0 additions & 20 deletions auraed/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,26 +145,6 @@ impl AuraedRuntime {

impl Default for AuraedRuntime {
fn default() -> Self {
let auraed = {
#[cfg(not(test))]
let auraed = if std::process::id() == 1 {
// If auraed is running as true PID 1 /proc wouldn't be mounted
// at this point. For VMs, as long as we control the disk image
// this shouldn't be a problem.
"/lib/auraed/auraed".into()
} else {
std::fs::read_link(PROC_SELF_EXE).expect(
"failed read auraed symbolic link from /proc/self/exe",
)
};

// In unit tests, we cannot use /proc/self/exe since main.rs is not part of the test binary.
#[cfg(test)]
let auraed = "auraed".into();

auraed
};

// In order to prevent their use from other areas, do not make these values into constants.
AuraedRuntime {
auraed: AuraedPath::default(),
Expand Down

0 comments on commit df5270d

Please sign in to comment.