Skip to content

Commit

Permalink
Autoconfigure network without DHCP
Browse files Browse the repository at this point in the history
Passt includes a DHCP server to allow guests to easily configure the
network without being aware passt is on the other side. But we _are_
aware of that, so we can take advantage of it.

Instead of using DHCP, read the configuration output from passt,
marshall it into some environment variables, pass it to the guest, and
have krun-guest read it and apply it using rtnetlink.

By doing that, we reduce the startup time in half, from...

$ time krun /bin/false
(...)
real    0m4,301s

... to ...

$ time krun /bin/false
(...)
real    0m1,966s

In addition of reducing the boot time, this potentially will prevent
some of the dhcp issues we've seen in the past.

Signed-off-by: Sergio Lopez <[email protected]>
  • Loading branch information
slp committed Oct 18, 2024
1 parent c11ac74 commit 61baffe
Show file tree
Hide file tree
Showing 7 changed files with 383 additions and 89 deletions.
243 changes: 232 additions & 11 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions crates/muvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ anyhow = { version = "1.0.82", default-features = false, features = ["std"] }
bpaf = { version = "0.9.11", default-features = false, features = [] }
byteorder = { version = "1.5.0", default-features = false, features = ["std"] }
env_logger = { version = "0.11.3", default-features = false, features = ["auto-color", "humantime", "unstable-kv"] }
futures-util = { version = "0.3.30", default-features = false, features = [] }
krun-sys = { path = "../krun-sys", version = "1.9.1", default-features = false, features = [] }
log = { version = "0.4.21", default-features = false, features = ["kv"] }
nix = { version = "0.28.0", default-features = false, features = ["user"] }
regex = { version = "1.10.6" }
rustix = { version = "0.38.34", default-features = false, features = ["fs", "mount", "process", "std", "system", "use-libc-auxv"] }
rtnetlink = { version = "0.14.1" }
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.117", default-features = false, features = ["std"] }
tempfile = { version = "3.10.1", default-features = false, features = [] }
Expand Down
14 changes: 7 additions & 7 deletions crates/muvm/src/bin/muvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,19 @@ fn main() -> Result<()> {
}
}

let mut env = prepare_env_vars(env).context("Failed to prepare environment variables")?;
env.insert(
"MUVM_SERVER_PORT".to_owned(),
options.server_port.to_string(),
);

{
let passt_fd: OwnedFd = if let Some(passt_socket) = options.passt_socket {
connect_to_passt(passt_socket)
.context("Failed to connect to `passt`")?
.into()
} else {
start_passt(options.server_port)
start_passt(options.server_port, &mut env)
.context("Failed to start `passt`")?
.into()
};
Expand Down Expand Up @@ -355,12 +361,6 @@ fn main() -> Result<()> {
muvm_guest_args.push(arg);
}

let mut env = prepare_env_vars(env).context("Failed to prepare environment variables")?;
env.insert(
"MUVM_SERVER_PORT".to_owned(),
options.server_port.to_string(),
);

let mut krun_config = KrunConfig {
args: Vec::new(),
envs: Vec::new(),
Expand Down
Loading

0 comments on commit 61baffe

Please sign in to comment.