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) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 962CCC1A2D for ; Wed, 17 Jan 2024 10:50:29 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 7D0083FE25 for ; Wed, 17 Jan 2024 10:50:29 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (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 for ; Wed, 17 Jan 2024 10:50:28 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id ACDCF49194 for ; Wed, 17 Jan 2024 10:50:28 +0100 (CET) Message-ID: <0e8e713e-35c5-47d4-912a-c6d4ba8c5ed2@proxmox.com> Date: Wed, 17 Jan 2024 10:50:27 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Lukas Wagner To: Proxmox Backup Server development discussion , Stefan Lendl References: <20240111155303.1072675-1-s.lendl@proxmox.com> <20240111155303.1072675-7-s.lendl@proxmox.com> Content-Language: de-AT, en-US In-Reply-To: <20240111155303.1072675-7-s.lendl@proxmox.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.004 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [network.rs, mod.rs] Subject: Re: [pbs-devel] [PATCH proxmox-backup 03/10] config: write vlan network interface 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, 17 Jan 2024 09:50:29 -0000 On 1/11/24 16:52, Stefan Lendl wrote: > add vlan_id and vlan_raw_device to Interface struct > write them out if the interface type is Vlan > add several tests > > Signed-off-by: Stefan Lendl > --- > pbs-api-types/src/network.rs | 17 ++++++++ > pbs-config/src/network/mod.rs | 73 ++++++++++++++++++++++++++++++++++- > 2 files changed, 89 insertions(+), 1 deletion(-) > > diff --git a/pbs-api-types/src/network.rs b/pbs-api-types/src/network.rs > index e3a5e481..fe083dc6 100644 > --- a/pbs-api-types/src/network.rs > +++ b/pbs-api-types/src/network.rs > @@ -224,6 +224,15 @@ pub const NETWORK_INTERFACE_LIST_SCHEMA: Schema = > schema: NETWORK_INTERFACE_ARRAY_SCHEMA, > optional: true, > }, > + "vlan-id": { > + description: "VLAN ID.", > + type: u16, > + optional: true, > + }, > + "vlan-raw-device": { > + schema: NETWORK_INTERFACE_NAME_SCHEMA, > + optional: true, > + }, > bond_mode: { > type: LinuxBondMode, > optional: true, > @@ -287,6 +296,12 @@ pub struct Interface { > /// Enable bridge vlan support. > #[serde(skip_serializing_if = "Option::is_none")] > pub bridge_vlan_aware: Option, > + #[serde(skip_serializing_if = "Option::is_none")] > + #[serde(rename = "vlan-id")] > + pub vlan_id: Option, > + #[serde(skip_serializing_if = "Option::is_none")] > + #[serde(rename = "vlan-raw-device")] > + pub vlan_raw_device: Option, > > #[serde(skip_serializing_if = "Option::is_none")] > pub slaves: Option>, > @@ -319,6 +334,8 @@ impl Interface { > mtu: None, > bridge_ports: None, > bridge_vlan_aware: None, > + vlan_id: None, > + vlan_raw_device: None, > slaves: None, > bond_mode: None, > bond_primary: None, > diff --git a/pbs-config/src/network/mod.rs b/pbs-config/src/network/mod.rs > index 7fec7e29..971c1ebe 100644 > --- a/pbs-config/src/network/mod.rs > +++ b/pbs-config/src/network/mod.rs > @@ -79,6 +79,14 @@ fn write_iface_attributes(iface: &Interface, w: &mut dyn Write) -> Result<(), Er > writeln!(w, "\tbond-slaves {}", slaves.join(" "))?; > } > } > + NetworkInterfaceType::Vlan => { > + if let Some(vlan_id) = iface.vlan_id { > + writeln!(w, "\tvlan-id {}", vlan_id)?; > + } > + if let Some(vlan_raw_device) = &iface.vlan_raw_device { > + writeln!(w, "\tvlan-raw-device {}", vlan_raw_device)?; Mini-nit: You can inline the string formatting: {vlan_raw_device} > + } > + } > _ => {} > } > > @@ -580,5 +588,68 @@ iface enp3s0 inet static > .trim() > ); > } > -} > > + #[test] > + fn test_write_network_config_vlan_id_in_name() { > + let iface_name = String::from("vmbr0.100"); > + let mut iface = Interface::new(iface_name.clone()); > + iface.interface_type = Vlan; > + iface.method = Some(Manual); > + iface.active = true; > + > + let nw_config = NetworkConfig { > + interfaces: BTreeMap::from([(iface_name.clone(), iface)]), > + order: vec![Iface(iface_name.clone())], > + }; > + assert_eq!( > + String::try_from(nw_config).unwrap().trim(), > + "iface vmbr0.100 inet manual" > + ); > + } > + > + #[test] > + fn test_write_network_config_vlan_with_raw_device() { > + let iface_name = String::from("vlan100"); > + let mut iface = Interface::new(iface_name.clone()); > + iface.interface_type = Vlan; > + iface.vlan_raw_device = Some(String::from("vmbr0")); > + iface.method = Some(Manual); > + iface.active = true; > + > + let nw_config = NetworkConfig { > + interfaces: BTreeMap::from([(iface_name.clone(), iface)]), > + order: vec![Iface(iface_name.clone())], > + }; > + assert_eq!( > + String::try_from(nw_config).unwrap().trim(), > + r#" > +iface vlan100 inet manual > + vlan-raw-device vmbr0"# > + .trim() > + ); > + } > + > + #[test] > + fn test_write_network_config_vlan_with_individual_name() { > + let iface_name = String::from("individual_name"); > + let mut iface = Interface::new(iface_name.clone()); > + iface.interface_type = Vlan; > + iface.vlan_raw_device = Some(String::from("vmbr0")); > + iface.vlan_id = Some(100); > + iface.method = Some(Manual); > + iface.active = true; > + > + let nw_config = NetworkConfig { > + interfaces: BTreeMap::from([(iface_name.clone(), iface)]), > + order: vec![Iface(iface_name.clone())], > + }; > + assert_eq!( > + String::try_from(nw_config).unwrap().trim(), > + r#" > +iface individual_name inet manual > + vlan-id 100 > + vlan-raw-device vmbr0"# > + .trim() > + ); > + } > +} -- - Lukas