From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 80B7C6239B for ; Wed, 16 Sep 2020 14:12:33 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 78F5E23A01 for ; Wed, 16 Sep 2020 14:12:33 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id DEEFF239F9 for ; Wed, 16 Sep 2020 14:12:31 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 9FC49453D5 for ; Wed, 16 Sep 2020 14:12:31 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Wed, 16 Sep 2020 14:12:29 +0200 Message-Id: <20200916121230.12906-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.175 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods NO_DNS_FOR_FROM 0.379 Envelope sender has no MX or A DNS records RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [parser.rs, network.rs, lexer.rs, mod.rs] Subject: [pbs-devel] [PATCH proxmox-backup 1/2] api2/network: add bond-primary parameter X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Sep 2020 12:12:33 -0000 needed for 'active-backup' bond mode Signed-off-by: Dominik Csapak --- this needs my previous patches for the api-macro (and a bump) src/api2/node/network.rs | 34 ++++++++++++++++++++++++++++++++-- src/api2/types/mod.rs | 9 ++++++++- src/config/network.rs | 6 ++++++ src/config/network/lexer.rs | 4 +++- src/config/network/parser.rs | 6 ++++++ 5 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/api2/node/network.rs b/src/api2/node/network.rs index 7266da05..4de12ef2 100644 --- a/src/api2/node/network.rs +++ b/src/api2/node/network.rs @@ -198,6 +198,10 @@ pub fn read_interface(iface: String) -> Result { type: LinuxBondMode, optional: true, }, + "bond-primary": { + schema: NETWORK_INTERFACE_NAME_SCHEMA, + optional: true, + }, slaves: { schema: NETWORK_INTERFACE_LIST_SCHEMA, optional: true, @@ -224,6 +228,7 @@ pub fn create_interface( bridge_ports: Option, bridge_vlan_aware: Option, bond_mode: Option, + bond_primary: Option, slaves: Option, param: Value, ) -> Result<(), Error> { @@ -284,7 +289,15 @@ pub fn create_interface( if bridge_vlan_aware.is_some() { interface.bridge_vlan_aware = bridge_vlan_aware; } } NetworkInterfaceType::Bond => { - if bond_mode.is_some() { interface.bond_mode = bond_mode; } + if let Some(mode) = bond_mode { + interface.bond_mode = bond_mode; + if bond_primary.is_some() { + if mode != LinuxBondMode::active_backup { + bail!("bond-primary is only valid with Active/Backup mode"); + } + interface.bond_primary = bond_primary; + } + } if let Some(slaves) = slaves { let slaves = split_interface_list(&slaves)?; interface.set_bond_slaves(slaves)?; @@ -343,6 +356,9 @@ pub enum DeletableProperty { bridge_vlan_aware, /// Delete bond-slaves (set to 'none') slaves, + /// Delete bond-primary + #[serde(rename = "bond-primary")] + bond_primary, } @@ -420,6 +436,10 @@ pub enum DeletableProperty { type: LinuxBondMode, optional: true, }, + "bond-primary": { + schema: NETWORK_INTERFACE_NAME_SCHEMA, + optional: true, + }, slaves: { schema: NETWORK_INTERFACE_LIST_SCHEMA, optional: true, @@ -458,6 +478,7 @@ pub fn update_interface( bridge_ports: Option, bridge_vlan_aware: Option, bond_mode: Option, + bond_primary: Option, slaves: Option, delete: Option>, digest: Option, @@ -501,6 +522,7 @@ pub fn update_interface( DeletableProperty::bridge_ports => { interface.set_bridge_ports(Vec::new())?; } DeletableProperty::bridge_vlan_aware => { interface.bridge_vlan_aware = None; } DeletableProperty::slaves => { interface.set_bond_slaves(Vec::new())?; } + DeletableProperty::bond_primary => { interface.bond_primary = None; } } } } @@ -518,7 +540,15 @@ pub fn update_interface( let slaves = split_interface_list(&slaves)?; interface.set_bond_slaves(slaves)?; } - if bond_mode.is_some() { interface.bond_mode = bond_mode; } + if let Some(mode) = bond_mode { + interface.bond_mode = bond_mode; + if bond_primary.is_some() { + if mode != LinuxBondMode::active_backup { + bail!("bond-primary is only valid with Active/Backup mode"); + } + interface.bond_primary = bond_primary; + } + } if let Some(cidr) = cidr { let (_, _, is_v6) = network::parse_cidr(&cidr)?; diff --git a/src/api2/types/mod.rs b/src/api2/types/mod.rs index 5495d693..e2eb08aa 100644 --- a/src/api2/types/mod.rs +++ b/src/api2/types/mod.rs @@ -812,7 +812,11 @@ pub const NETWORK_INTERFACE_LIST_SCHEMA: Schema = StringSchema::new( bond_mode: { type: LinuxBondMode, optional: true, - } + }, + "bond-primary": { + schema: NETWORK_INTERFACE_NAME_SCHEMA, + optional: true, + }, } )] #[derive(Debug, Serialize, Deserialize)] @@ -869,6 +873,9 @@ pub struct Interface { pub slaves: Option>, #[serde(skip_serializing_if="Option::is_none")] pub bond_mode: Option, + #[serde(skip_serializing_if="Option::is_none")] + #[serde(rename = "bond-primary")] + pub bond_primary: Option, } // Regression tests diff --git a/src/config/network.rs b/src/config/network.rs index 53693283..6e3b9ea1 100644 --- a/src/config/network.rs +++ b/src/config/network.rs @@ -67,6 +67,7 @@ impl Interface { bridge_vlan_aware: None, slaves: None, bond_mode: None, + bond_primary: None, } } @@ -169,6 +170,11 @@ impl Interface { NetworkInterfaceType::Bond => { let mode = self.bond_mode.unwrap_or(LinuxBondMode::balance_rr); writeln!(w, "\tbond-mode {}", bond_mode_to_str(mode))?; + if let Some(primary) = &self.bond_primary { + if mode == LinuxBondMode::active_backup { + writeln!(w, "\tbond-primary {}", primary)?; + } + } let slaves = self.slaves.as_ref().unwrap_or(&EMPTY_LIST); if slaves.is_empty() { diff --git a/src/config/network/lexer.rs b/src/config/network/lexer.rs index c050745f..c29d4f37 100644 --- a/src/config/network/lexer.rs +++ b/src/config/network/lexer.rs @@ -26,6 +26,7 @@ pub enum Token { BridgeVlanAware, BondSlaves, BondMode, + BondPrimary, EOF, } @@ -51,7 +52,8 @@ lazy_static! { 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.insert("bond-primary", Token::BondPrimary); + map.insert("bond_primary", Token::BondPrimary); map }; } diff --git a/src/config/network/parser.rs b/src/config/network/parser.rs index a97d0f79..b9b7ddc3 100644 --- a/src/config/network/parser.rs +++ b/src/config/network/parser.rs @@ -243,6 +243,12 @@ impl NetworkParser { interface.bond_mode = Some(bond_mode_from_str(&mode)?); self.eat(Token::Newline)?; } + Token::BondPrimary => { + self.eat(Token::BondPrimary)?; + let primary = self.next_text()?; + interface.bond_primary = Some(primary); + self.eat(Token::Newline)?; + } Token::Netmask => bail!("netmask is deprecated and no longer supported"), _ => { // parse addon attributes -- 2.20.1