src/config/network.rs: add Interface flags 'exists' and 'active'
This commit is contained in:
		@ -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<ConfigMethod>,
 | 
			
		||||
    pub method_v6: Option<ConfigMethod>,
 | 
			
		||||
@ -42,6 +44,8 @@ impl Interface {
 | 
			
		||||
        Self {
 | 
			
		||||
            name,
 | 
			
		||||
            autostart: false,
 | 
			
		||||
            exists: false,
 | 
			
		||||
            active: false,
 | 
			
		||||
            method_v4: None,
 | 
			
		||||
            method_v6: None,
 | 
			
		||||
            address_v4: None,
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user