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 33ddc62 commit 8f1a555
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 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

0 comments on commit 8f1a555

Please sign in to comment.