From b9241b987ad7a6a7553451dbeffdffd51a9b8176 Mon Sep 17 00:00:00 2001 From: Himbeer Date: Sun, 6 Apr 2025 13:02:31 +0200 Subject: Wait for link to be created before adding routes over it This fixes an issue where routes fail to be added if the interface is created by a service, such as WireGuard links. --- Cargo.toml | 2 +- src/main.rs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2e436f3..0275656 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -rsdsl_netlinklib = { git = "https://github.com/rsdsl/netlinklib.git", version = "0.6.0", features = ["blocking", "rule"] } +rsdsl_netlinklib = { git = "https://github.com/rsdsl/netlinklib.git", version = "0.6.0", features = ["blocking", "link", "rule"] } diff --git a/src/main.rs b/src/main.rs index 0754003..a6901c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -251,6 +251,13 @@ impl RouteDef { Ok(()) } + + fn link(&self) -> &str { + match self { + Self::V4(r) => &r.link, + Self::V6(r) => &r.link, + } + } } impl fmt::Display for RouteDef { @@ -842,6 +849,10 @@ fn run() -> Result<(), Error> { Err(e) => println!("[warn] del {}: {}", route, e), } + println!("[info] wait for link {}", route.def.link()); + conn.link_wait_exists(route.def.link().to_string()) + .map_err(SetupError::from)?; + if !route.delete { match route.def.clone().add(&conn) { Ok(_) => println!("[info] add {}", route), -- cgit v1.2.3