and rename bond_slaves to slaves to make it compatible with pve.
type: bool,
optional: true,
},
- bond_slaves: {
+ bond_mode: {
+ type: LinuxBondMode,
+ optional: true,
+ },
+ slaves: {
schema: NETWORK_INTERFACE_LIST_SCHEMA,
optional: true,
},
mtu: Option<u64>,
bridge_ports: Option<Vec<String>>,
bridge_vlan_aware: Option<bool>,
- bond_slaves: Option<Vec<String>>,
+ bond_mode: Option<LinuxBondMode>,
+ slaves: Option<Vec<String>>,
param: Value,
) -> Result<(), Error> {
if bridge_vlan_aware.is_some() { interface.bridge_vlan_aware = bridge_vlan_aware; }
}
NetworkInterfaceType::Bond => {
- if let Some(slaves) = bond_slaves { interface.set_bond_slaves(slaves)?; }
+ if bond_mode.is_some() { interface.bond_mode = bond_mode; }
+ if let Some(slaves) = slaves { interface.set_bond_slaves(slaves)?; }
}
_ => bail!("creating network interface type '{:?}' is not supported", interface_type),
}
/// Delet bridge-vlan-aware flag
bridge_vlan_aware,
/// Delete bond-slaves (set to 'none')
- bond_slaves,
+ slaves,
}
type: bool,
optional: true,
},
- bond_slaves: {
+ bond_mode: {
+ type: LinuxBondMode,
+ optional: true,
+ },
+ slaves: {
schema: NETWORK_INTERFACE_LIST_SCHEMA,
optional: true,
},
mtu: Option<u64>,
bridge_ports: Option<Vec<String>>,
bridge_vlan_aware: Option<bool>,
- bond_slaves: Option<Vec<String>>,
+ bond_mode: Option<LinuxBondMode>,
+ slaves: Option<Vec<String>>,
delete: Option<Vec<DeletableProperty>>,
digest: Option<String>,
param: Value,
DeletableProperty::autostart => { interface.autostart = false; },
DeletableProperty::bridge_ports => { interface.set_bridge_ports(Vec::new())?; }
DeletableProperty::bridge_vlan_aware => { interface.bridge_vlan_aware = None; }
- DeletableProperty::bond_slaves => { interface.set_bond_slaves(Vec::new())?; }
+ DeletableProperty::slaves => { interface.set_bond_slaves(Vec::new())?; }
}
}
}
if mtu.is_some() { interface.mtu = mtu; }
if let Some(ports) = bridge_ports { interface.set_bridge_ports(ports)?; }
if bridge_vlan_aware.is_some() { interface.bridge_vlan_aware = bridge_vlan_aware; }
- if let Some(slaves) = bond_slaves { interface.set_bond_slaves(slaves)?; }
+ if let Some(slaves) = slaves { interface.set_bond_slaves(slaves)?; }
+ if bond_mode.is_some() { interface.bond_mode = bond_mode; }
if let Some(cidr) = cidr {
let (_, _, is_v6) = network::parse_cidr(&cidr)?;
Loopback,
}
+#[api()]
+#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
+#[serde(rename_all = "kebab-case")]
+#[allow(non_camel_case_types)]
+#[repr(u8)]
+/// Linux Bond Mode
+pub enum LinuxBondMode {
+ /// Round-robin policy
+ balance_rr = 0,
+ /// Active-backup policy
+ active_backup = 1,
+ /// XOR policy
+ balance_xor = 2,
+ /// Broadcast policy
+ broadcast = 3,
+ /// IEEE 802.3ad Dynamic link aggregation
+ //#[serde(rename = "802.3ad")]
+ ieee802_3ad = 4,
+ /// Adaptive transmit load balancing
+ balance_tlb = 5,
+ /// Adaptive load balancing
+ balance_alb = 6,
+}
+
#[api()]
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
schema: NETWORK_INTERFACE_LIST_SCHEMA,
optional: true,
},
- bond_slaves: {
+ slaves: {
schema: NETWORK_INTERFACE_LIST_SCHEMA,
optional: true,
},
+ bond_mode: {
+ type: LinuxBondMode,
+ optional: true,
+ }
}
)]
#[derive(Debug, Serialize, Deserialize)]
pub bridge_vlan_aware: Option<bool>,
#[serde(skip_serializing_if="Option::is_none")]
- pub bond_slaves: Option<Vec<String>>,
+ pub slaves: Option<Vec<String>>,
+ #[serde(skip_serializing_if="Option::is_none")]
+ pub bond_mode: Option<LinuxBondMode>,
}
// Regression tests
use std::collections::{HashSet, HashMap};
use anyhow::{Error, format_err, bail};
+use serde::de::{value, IntoDeserializer, Deserialize};
use proxmox::tools::{fs::replace_file, fs::CreateOptions};
mod parser;
pub use parser::*;
-use crate::api2::types::{Interface, NetworkConfigMethod, NetworkInterfaceType};
+use crate::api2::types::{Interface, NetworkConfigMethod, NetworkInterfaceType, LinuxBondMode};
+
+pub fn bond_mode_from_str(s: &str) -> Result<LinuxBondMode, Error> {
+ LinuxBondMode::deserialize(s.into_deserializer())
+ .map_err(|_: value::Error| format_err!("invalid bond_mode '{}'", s))
+}
+
+pub fn bond_mode_to_str(mode: LinuxBondMode) -> &'static str {
+ match mode {
+ LinuxBondMode::balance_rr => "balance-rr",
+ LinuxBondMode::active_backup => "active-backup",
+ LinuxBondMode::balance_xor => "balance-xor",
+ LinuxBondMode::broadcast => "broadcast",
+ LinuxBondMode::ieee802_3ad => "802.3ad",
+ LinuxBondMode::balance_tlb => "balance-tlb",
+ LinuxBondMode::balance_alb => "balance-alb",
+ }
+}
impl Interface {
mtu: None,
bridge_ports: None,
bridge_vlan_aware: None,
- bond_slaves: None,
+ slaves: None,
+ bond_mode: None,
}
}
if self.interface_type != NetworkInterfaceType::Bond {
bail!("interface '{}' is no bond (type is {:?})", self.name, self.interface_type);
}
- self.bond_slaves = Some(slaves);
+ self.slaves = Some(slaves);
Ok(())
}
}
}
NetworkInterfaceType::Bond => {
- if let Some(ref slaves) = self.bond_slaves {
+ let mode = self.bond_mode.unwrap_or(LinuxBondMode::balance_rr);
+ writeln!(w, "\tbond-mode {}", bond_mode_to_str(mode))?;
+
+ if let Some(ref slaves) = self.slaves {
if slaves.is_empty() {
writeln!(w, "\tbond-slaves none")?;
} else {
mtu: _mtu,
bridge_ports: _bridge_ports,
bridge_vlan_aware: _bridge_vlan_aware,
- bond_slaves: _bond_slaves,
+ slaves: _slaves,
+ bond_mode: _bond_mode,
} => {
method == method6
&& comments.is_none()
}
return Ok(());
}
-
+
if let Some(method) = self.method {
writeln!(w, "iface {} inet {}", self.name, method_to_str(method))?;
self.write_iface_attributes_v4(w, method)?;
self.write_iface_attributes(w)?;
writeln!(w)?;
}
-
+
if let Some(method6) = self.method6 {
let mut skip_v6 = false; // avoid empty inet6 manual entry
if self.method.is_some() && method6 == NetworkConfigMethod::Manual {
if self.comments6.is_none() && self.options6.is_empty() { skip_v6 = true; }
}
-
+
if !skip_v6 {
writeln!(w, "iface {} inet6 {}", self.name, method_to_str(method6))?;
self.write_iface_attributes_v6(w, method6)?;
BridgePorts,
BridgeVlanAware,
BondSlaves,
+ BondMode,
EOF,
}
map.insert("bridge_vlan_aware", Token::BridgeVlanAware);
map.insert("bond-slaves", Token::BondSlaves);
map.insert("bond_slaves", Token::BondSlaves);
+ map.insert("bond-mode", Token::BondMode);
+ map.insert("bond_mode", Token::BondMode);
map
};
}
use super::helper::*;
use super::lexer::*;
-use super::{NetworkConfig, NetworkOrderEntry, Interface, NetworkConfigMethod, NetworkInterfaceType};
+use super::{NetworkConfig, NetworkOrderEntry, Interface, NetworkConfigMethod, NetworkInterfaceType, bond_mode_from_str};
pub struct NetworkParser<R: BufRead> {
input: Peekable<Lexer<R>>,
Token::BondSlaves => {
self.eat(Token::BondSlaves)?;
let slaves = self.parse_iface_list()?;
- interface.bond_slaves = Some(slaves);
+ interface.slaves = Some(slaves);
interface.set_interface_type(NetworkInterfaceType::Bond)?;
}
+ Token::BondMode => {
+ self.eat(Token::BondMode)?;
+ let mode = self.next_text()?;
+ interface.bond_mode = Some(bond_mode_from_str(&mode)?);
+ self.eat(Token::Newline)?;
+ }
Token::Netmask => bail!("netmask is deprecated and no longer supported"),
_ => { // parse addon attributes