src/config/network.rs: make it compatible with pve
and depend on proxmox 0.1.26
This commit is contained in:
@ -23,6 +23,7 @@ pub enum Token {
|
||||
Attribute,
|
||||
MTU,
|
||||
BridgePorts,
|
||||
BridgeVlanAware,
|
||||
BondSlaves,
|
||||
EOF,
|
||||
}
|
||||
@ -44,6 +45,8 @@ lazy_static! {
|
||||
map.insert("mtu", Token::MTU);
|
||||
map.insert("bridge-ports", Token::BridgePorts);
|
||||
map.insert("bridge_ports", Token::BridgePorts);
|
||||
map.insert("bridge-vlan-aware", Token::BridgeVlanAware);
|
||||
map.insert("bridge_vlan_aware", Token::BridgeVlanAware);
|
||||
map.insert("bond-slaves", Token::BondSlaves);
|
||||
map.insert("bond_slaves", Token::BondSlaves);
|
||||
map
|
||||
|
@ -137,6 +137,21 @@ impl <R: BufRead> NetworkParser<R> {
|
||||
Ok(mtu)
|
||||
}
|
||||
|
||||
fn parse_yes_no(&mut self) -> Result<bool, Error> {
|
||||
let text = self.next_text()?;
|
||||
let value = match text.to_lowercase().as_str() {
|
||||
"yes" => true,
|
||||
"no" => false,
|
||||
_ => {
|
||||
bail!("unable to bool value '{}' - (expected yes/no)", text);
|
||||
}
|
||||
};
|
||||
|
||||
self.eat(Token::Newline)?;
|
||||
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
fn parse_to_eol(&mut self) -> Result<String, Error> {
|
||||
let mut line = String::new();
|
||||
loop {
|
||||
@ -182,15 +197,15 @@ impl <R: BufRead> NetworkParser<R> {
|
||||
Token::Comment => {
|
||||
let comment = self.eat(Token::Comment)?;
|
||||
if !address_family_v4 && address_family_v6 {
|
||||
let mut comments = interface.comments_v6.take().unwrap_or(String::new());
|
||||
let mut comments = interface.comments6.take().unwrap_or(String::new());
|
||||
if !comments.is_empty() { comments.push('\n'); }
|
||||
comments.push_str(&comment);
|
||||
interface.comments_v6 = Some(comments);
|
||||
interface.comments6 = Some(comments);
|
||||
} else {
|
||||
let mut comments = interface.comments_v4.take().unwrap_or(String::new());
|
||||
let mut comments = interface.comments.take().unwrap_or(String::new());
|
||||
if !comments.is_empty() { comments.push('\n'); }
|
||||
comments.push_str(&comment);
|
||||
interface.comments_v4 = Some(comments);
|
||||
interface.comments = Some(comments);
|
||||
}
|
||||
self.eat(Token::Newline)?;
|
||||
continue;
|
||||
@ -207,6 +222,11 @@ impl <R: BufRead> NetworkParser<R> {
|
||||
let mtu = self.parse_iface_mtu()?;
|
||||
interface.mtu = Some(mtu);
|
||||
}
|
||||
Token::BridgeVlanAware => {
|
||||
self.eat(Token::BridgeVlanAware)?;
|
||||
let bridge_vlan_aware = self.parse_yes_no()?;
|
||||
interface.bridge_vlan_aware = Some(bridge_vlan_aware);
|
||||
}
|
||||
Token::BridgePorts => {
|
||||
self.eat(Token::BridgePorts)?;
|
||||
let ports = self.parse_iface_list()?;
|
||||
@ -225,9 +245,9 @@ impl <R: BufRead> NetworkParser<R> {
|
||||
let option = self.parse_to_eol()?;
|
||||
if !option.is_empty() {
|
||||
if !address_family_v4 && address_family_v6 {
|
||||
interface.options_v6.push(option);
|
||||
interface.options6.push(option);
|
||||
} else {
|
||||
interface.options_v4.push(option);
|
||||
interface.options.push(option);
|
||||
}
|
||||
};
|
||||
},
|
||||
@ -335,7 +355,7 @@ impl <R: BufRead> NetworkParser<R> {
|
||||
|
||||
for iface in auto_flag.iter() {
|
||||
if let Some(interface) = config.interfaces.get_mut(iface) {
|
||||
interface.auto = true;
|
||||
interface.autostart = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -349,13 +369,13 @@ impl <R: BufRead> NetworkParser<R> {
|
||||
for (iface, active) in existing_interfaces.iter() {
|
||||
if let Some(interface) = config.interfaces.get_mut(iface) {
|
||||
interface.active = *active;
|
||||
if interface.interface_type == NetworkInterfaceType::Unknown {
|
||||
interface.interface_type = NetworkInterfaceType::Ethernet;
|
||||
if interface.interface_type == NetworkInterfaceType::Unknown && PHYSICAL_NIC_REGEX.is_match(iface) {
|
||||
interface.interface_type = NetworkInterfaceType::Eth;
|
||||
}
|
||||
} else if PHYSICAL_NIC_REGEX.is_match(iface) { // also add all physical NICs
|
||||
let mut interface = Interface::new(iface.clone());
|
||||
interface.set_method_v4(NetworkConfigMethod::Manual)?;
|
||||
interface.interface_type = NetworkInterfaceType::Ethernet;
|
||||
interface.interface_type = NetworkInterfaceType::Eth;
|
||||
interface.active = *active;
|
||||
config.interfaces.insert(interface.name.clone(), interface);
|
||||
config.order.push(NetworkOrderEntry::Iface(iface.to_string()));
|
||||
@ -378,7 +398,7 @@ impl <R: BufRead> NetworkParser<R> {
|
||||
continue;
|
||||
}
|
||||
if PHYSICAL_NIC_REGEX.is_match(name) {
|
||||
interface.interface_type = NetworkInterfaceType::Vanished;
|
||||
interface.interface_type = NetworkInterfaceType::Eth;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -387,7 +407,7 @@ impl <R: BufRead> NetworkParser<R> {
|
||||
let mut interface = Interface::new(String::from("lo"));
|
||||
interface.set_method_v4(NetworkConfigMethod::Loopback)?;
|
||||
interface.interface_type = NetworkInterfaceType::Loopback;
|
||||
interface.auto = true;
|
||||
interface.autostart = true;
|
||||
config.interfaces.insert(interface.name.clone(), interface);
|
||||
|
||||
// Note: insert 'lo' as first interface after initial comments
|
||||
|
Reference in New Issue
Block a user