src/config/network.rs: do not allow to change interface type

This commit is contained in:
Dietmar Maurer 2020-04-23 09:43:38 +02:00
parent 42fbe91a34
commit c38b4bb8b2
2 changed files with 12 additions and 2 deletions

View File

@ -92,6 +92,15 @@ impl Interface {
Ok(()) Ok(())
} }
fn set_interface_type(&mut self, interface_type: NetworkInterfaceType) -> Result<(), Error> {
if self.interface_type == NetworkInterfaceType::Unknown {
self.interface_type = interface_type;
} else if self.interface_type != interface_type {
bail!("interface type already defined - cannot change from {:?} to {:?}", self.interface_type, interface_type);
}
Ok(())
}
fn push_addon_option(&mut self, text: String) { fn push_addon_option(&mut self, text: String) {
if self.method_v4.is_none() && self.method_v6.is_some() { if self.method_v4.is_none() && self.method_v6.is_some() {
self.options_v6.push(text); self.options_v6.push(text);

View File

@ -174,6 +174,7 @@ impl <R: BufRead> NetworkParser<R> {
Ok(list) Ok(list)
} }
fn parse_iface_attributes(&mut self, interface: &mut Interface) -> Result<(), Error> { fn parse_iface_attributes(&mut self, interface: &mut Interface) -> Result<(), Error> {
loop { loop {
@ -194,13 +195,13 @@ impl <R: BufRead> NetworkParser<R> {
self.eat(Token::BridgePorts)?; self.eat(Token::BridgePorts)?;
let ports = self.parse_iface_list()?; let ports = self.parse_iface_list()?;
interface.bridge_ports = Some(ports); interface.bridge_ports = Some(ports);
interface.interface_type = NetworkInterfaceType::Bridge; interface.set_interface_type(NetworkInterfaceType::Bridge)?;
} }
Token::BondSlaves => { Token::BondSlaves => {
self.eat(Token::BondSlaves)?; self.eat(Token::BondSlaves)?;
let slaves = self.parse_iface_list()?; let slaves = self.parse_iface_list()?;
interface.bond_slaves = Some(slaves); interface.bond_slaves = Some(slaves);
interface.interface_type = NetworkInterfaceType::Bond; interface.set_interface_type(NetworkInterfaceType::Bond)?;
} }
Token::Netmask => bail!("netmask is deprecated and no longer supported"), Token::Netmask => bail!("netmask is deprecated and no longer supported"),
_ => { _ => {