From 3f129233be91eb644af9967af48d08dbf167771a Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 21 Apr 2020 11:46:56 +0200 Subject: [PATCH] src/config/network.rs: add Interface flags 'exists' and 'active' --- src/config/network.rs | 4 ++++ src/config/network/parser.rs | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/config/network.rs b/src/config/network.rs index f64ce1a4..8d9be908 100644 --- a/src/config/network.rs +++ b/src/config/network.rs @@ -23,6 +23,8 @@ pub enum ConfigMethod { #[derive(Debug)] pub struct Interface { pub autostart: bool, + pub exists: bool, + pub active: bool, pub name: String, pub method_v4: Option, pub method_v6: Option, @@ -42,6 +44,8 @@ impl Interface { Self { name, autostart: false, + exists: false, + active: false, method_v4: None, method_v6: None, address_v4: None, diff --git a/src/config/network/parser.rs b/src/config/network/parser.rs index b1ae9f98..7b5957e9 100644 --- a/src/config/network/parser.rs +++ b/src/config/network/parser.rs @@ -317,6 +317,27 @@ impl NetworkParser { } } + let existing_interfaces = get_network_interfaces()?; + + lazy_static!{ + static ref PHYSICAL_NIC_REGEX: Regex = Regex::new(r"(?:eth\d+|en[^:.]+|ib\d+)").unwrap(); + } + + for (iface, active) in existing_interfaces.iter() { + let exists = PHYSICAL_NIC_REGEX.is_match(iface); + if let Some(interface) = config.interfaces.get_mut(iface) { + interface.exists = exists; + interface.active = *active; + } else if exists { // also add physical NICs + let mut interface = Interface::new(iface.clone()); + interface.set_method_v4(ConfigMethod::Manual)?; + interface.exists = true; + interface.active = *active; + config.interfaces.insert(interface.name.clone(), interface); + config.order.push(NetworkOrderEntry::Iface(iface.to_string())); + } + } + Ok(config) } }