Skip to content

Commit

Permalink
Configure eth0 down before running systemd from the system image
Browse files Browse the repository at this point in the history
  • Loading branch information
andrisaar committed Jul 10, 2023
1 parent ab8a959 commit ee755ac
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
84 changes: 84 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions oak_containers_stage1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ clap = { version = "*", features = ["derive"] }
futures-util = "*"
nix = "*"
prost = { workspace = true }
rtnetlink = "*"
tar = "*"
tokio = { version = "*", features = [
"rt-multi-thread",
Expand Down
25 changes: 25 additions & 0 deletions oak_containers_stage1/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mod image;
use anyhow::Context;
use clap::Parser;
use client::LauncherClient;
use futures_util::TryStreamExt;
use nix::{
mount::{mount, umount2, MntFlags, MsFlags},
unistd::chroot,
Expand Down Expand Up @@ -101,5 +102,29 @@ async fn main() -> Result<(), Box<dyn Error>> {
if !Path::new("/etc/machine-id").exists() {
fs::write("/etc/machine-id", []).context("error writing placeholder /etc/machine-id")?;
}

// Configure eth0 down, as systemd will want to manage it itself and gets confused if it already
// has an IP address.
{
let (connection, handle, _) =
rtnetlink::new_connection().context("error opening netlink connection")?;
tokio::spawn(connection);

// `ip link show eth0`
let mut links = handle.link().get().match_name("eth0".to_string()).execute();

if let Some(link) = links.try_next().await? {
// `ip link set dev $INDEX down`
handle
.link()
.set(link.header.index)
.down()
.execute()
.await?;
} else {
println!("warning: eth0 not found");
}
}

image::switch(&args.init).context("error switching to the system image")?
}

0 comments on commit ee755ac

Please sign in to comment.