Skip to content

Commit 61baffe

Browse files
committed
Autoconfigure network without DHCP
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]>
1 parent c11ac74 commit 61baffe

7 files changed

Lines changed: 383 additions & 89 deletions

File tree

Cargo.lock

Lines changed: 232 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/muvm/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ anyhow = { version = "1.0.82", default-features = false, features = ["std"] }
1313
bpaf = { version = "0.9.11", default-features = false, features = [] }
1414
byteorder = { version = "1.5.0", default-features = false, features = ["std"] }
1515
env_logger = { version = "0.11.3", default-features = false, features = ["auto-color", "humantime", "unstable-kv"] }
16+
futures-util = { version = "0.3.30", default-features = false, features = [] }
1617
krun-sys = { path = "../krun-sys", version = "1.9.1", default-features = false, features = [] }
1718
log = { version = "0.4.21", default-features = false, features = ["kv"] }
1819
nix = { version = "0.28.0", default-features = false, features = ["user"] }
20+
regex = { version = "1.10.6" }
1921
rustix = { version = "0.38.34", default-features = false, features = ["fs", "mount", "process", "std", "system", "use-libc-auxv"] }
22+
rtnetlink = { version = "0.14.1" }
2023
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
2124
serde_json = { version = "1.0.117", default-features = false, features = ["std"] }
2225
tempfile = { version = "3.10.1", default-features = false, features = [] }

crates/muvm/src/bin/muvm.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,19 @@ fn main() -> Result<()> {
233233
}
234234
}
235235

236+
let mut env = prepare_env_vars(env).context("Failed to prepare environment variables")?;
237+
env.insert(
238+
"MUVM_SERVER_PORT".to_owned(),
239+
options.server_port.to_string(),
240+
);
241+
236242
{
237243
let passt_fd: OwnedFd = if let Some(passt_socket) = options.passt_socket {
238244
connect_to_passt(passt_socket)
239245
.context("Failed to connect to `passt`")?
240246
.into()
241247
} else {
242-
start_passt(options.server_port)
248+
start_passt(options.server_port, &mut env)
243249
.context("Failed to start `passt`")?
244250
.into()
245251
};
@@ -355,12 +361,6 @@ fn main() -> Result<()> {
355361
muvm_guest_args.push(arg);
356362
}
357363

358-
let mut env = prepare_env_vars(env).context("Failed to prepare environment variables")?;
359-
env.insert(
360-
"MUVM_SERVER_PORT".to_owned(),
361-
options.server_port.to_string(),
362-
);
363-
364364
let mut krun_config = KrunConfig {
365365
args: Vec::new(),
366366
envs: Vec::new(),

0 commit comments

Comments
 (0)