fix #2942: implement lacp bond mode and bond_xmit_hash_policy
this was not yet implemented, should be compatible with pve and the gui Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
committed by
Dietmar Maurer
parent
85959a99ea
commit
8f2f3dd710
@ -17,7 +17,7 @@ pub use lexer::*;
|
||||
mod parser;
|
||||
pub use parser::*;
|
||||
|
||||
use crate::api2::types::{Interface, NetworkConfigMethod, NetworkInterfaceType, LinuxBondMode};
|
||||
use crate::api2::types::{Interface, NetworkConfigMethod, NetworkInterfaceType, LinuxBondMode, BondXmitHashPolicy};
|
||||
|
||||
lazy_static!{
|
||||
static ref PHYSICAL_NIC_REGEX: Regex = Regex::new(r"^(?:eth\d+|en[^:.]+|ib\d+)$").unwrap();
|
||||
@ -44,6 +44,19 @@ pub fn bond_mode_to_str(mode: LinuxBondMode) -> &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bond_xmit_hash_policy_from_str(s: &str) -> Result<BondXmitHashPolicy, Error> {
|
||||
BondXmitHashPolicy::deserialize(s.into_deserializer())
|
||||
.map_err(|_: value::Error| format_err!("invalid bond_xmit_hash_policy '{}'", s))
|
||||
}
|
||||
|
||||
pub fn bond_xmit_hash_policy_to_str(policy: &BondXmitHashPolicy) -> &'static str {
|
||||
match policy {
|
||||
BondXmitHashPolicy::layer2 => "layer2",
|
||||
BondXmitHashPolicy::layer2_3 => "layer2+3",
|
||||
BondXmitHashPolicy::layer3_4 => "layer3+4",
|
||||
}
|
||||
}
|
||||
|
||||
impl Interface {
|
||||
|
||||
pub fn new(name: String) -> Self {
|
||||
@ -68,6 +81,7 @@ impl Interface {
|
||||
slaves: None,
|
||||
bond_mode: None,
|
||||
bond_primary: None,
|
||||
bond_xmit_hash_policy: None,
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,6 +190,14 @@ impl Interface {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(xmit_policy) = &self.bond_xmit_hash_policy {
|
||||
if mode == LinuxBondMode::ieee802_3ad ||
|
||||
mode == LinuxBondMode::balance_xor
|
||||
{
|
||||
writeln!(w, "\tbond_xmit_hash_policy {}", bond_xmit_hash_policy_to_str(xmit_policy))?;
|
||||
}
|
||||
}
|
||||
|
||||
let slaves = self.slaves.as_ref().unwrap_or(&EMPTY_LIST);
|
||||
if slaves.is_empty() {
|
||||
writeln!(w, "\tbond-slaves none")?;
|
||||
|
@ -27,6 +27,7 @@ pub enum Token {
|
||||
BondSlaves,
|
||||
BondMode,
|
||||
BondPrimary,
|
||||
BondXmitHashPolicy,
|
||||
EOF,
|
||||
}
|
||||
|
||||
@ -54,6 +55,8 @@ lazy_static! {
|
||||
map.insert("bond-mode", Token::BondMode);
|
||||
map.insert("bond-primary", Token::BondPrimary);
|
||||
map.insert("bond_primary", Token::BondPrimary);
|
||||
map.insert("bond_xmit_hash_policy", Token::BondXmitHashPolicy);
|
||||
map.insert("bond-xmit-hash-policy", Token::BondXmitHashPolicy);
|
||||
map
|
||||
};
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ use regex::Regex;
|
||||
use super::helper::*;
|
||||
use super::lexer::*;
|
||||
|
||||
use super::{NetworkConfig, NetworkOrderEntry, Interface, NetworkConfigMethod, NetworkInterfaceType, bond_mode_from_str};
|
||||
use super::{NetworkConfig, NetworkOrderEntry, Interface, NetworkConfigMethod, NetworkInterfaceType, bond_mode_from_str, bond_xmit_hash_policy_from_str};
|
||||
|
||||
pub struct NetworkParser<R: BufRead> {
|
||||
input: Peekable<Lexer<R>>,
|
||||
@ -249,6 +249,12 @@ impl <R: BufRead> NetworkParser<R> {
|
||||
interface.bond_primary = Some(primary);
|
||||
self.eat(Token::Newline)?;
|
||||
}
|
||||
Token::BondXmitHashPolicy => {
|
||||
self.eat(Token::BondXmitHashPolicy)?;
|
||||
let policy = bond_xmit_hash_policy_from_str(&self.next_text()?)?;
|
||||
interface.bond_xmit_hash_policy = Some(policy);
|
||||
self.eat(Token::Newline)?;
|
||||
}
|
||||
Token::Netmask => bail!("netmask is deprecated and no longer supported"),
|
||||
|
||||
_ => { // parse addon attributes
|
||||
|
Reference in New Issue
Block a user