src/config/network.rs: do not allow to change interface type
This commit is contained in:
parent
42fbe91a34
commit
c38b4bb8b2
|
@ -92,6 +92,15 @@ impl Interface {
|
|||
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) {
|
||||
if self.method_v4.is_none() && self.method_v6.is_some() {
|
||||
self.options_v6.push(text);
|
||||
|
|
|
@ -174,6 +174,7 @@ impl <R: BufRead> NetworkParser<R> {
|
|||
|
||||
Ok(list)
|
||||
}
|
||||
|
||||
fn parse_iface_attributes(&mut self, interface: &mut Interface) -> Result<(), Error> {
|
||||
|
||||
loop {
|
||||
|
@ -194,13 +195,13 @@ impl <R: BufRead> NetworkParser<R> {
|
|||
self.eat(Token::BridgePorts)?;
|
||||
let ports = self.parse_iface_list()?;
|
||||
interface.bridge_ports = Some(ports);
|
||||
interface.interface_type = NetworkInterfaceType::Bridge;
|
||||
interface.set_interface_type(NetworkInterfaceType::Bridge)?;
|
||||
}
|
||||
Token::BondSlaves => {
|
||||
self.eat(Token::BondSlaves)?;
|
||||
let slaves = self.parse_iface_list()?;
|
||||
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"),
|
||||
_ => {
|
||||
|
|
Loading…
Reference in New Issue