From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id C9AF61FF16B for ; Tue, 29 Jul 2025 18:56:05 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 133B218C94; Tue, 29 Jul 2025 18:57:31 +0200 (CEST) From: Stefan Hanreich To: pbs-devel@lists.proxmox.com Date: Tue, 29 Jul 2025 18:56:47 +0200 Message-ID: <20250729165655.681368-3-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250729165655.681368-1-s.hanreich@proxmox.com> References: <20250729165655.681368-1-s.hanreich@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.195 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 KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS 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. [network.rs] Subject: [pbs-devel] [PATCH proxmox 1/3] pbs-api-types: use proxmox-network-api types 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: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" proxmox-network-api contains the api types for the network API as well. Since it has been migrated to use the types from proxmox-network-api, we can delete them from the pbs specific crate. Signed-off-by: Stefan Hanreich --- pbs-api-types/src/network.rs | 345 --------------------------- proxmox-network-api/src/api_types.rs | 8 +- 2 files changed, 4 insertions(+), 349 deletions(-) delete mode 100644 pbs-api-types/src/network.rs diff --git a/pbs-api-types/src/network.rs b/pbs-api-types/src/network.rs deleted file mode 100644 index fe083dc6..00000000 --- a/pbs-api-types/src/network.rs +++ /dev/null @@ -1,345 +0,0 @@ -use std::fmt; - -use serde::{Deserialize, Serialize}; - -use proxmox_schema::*; - -use crate::{ - CIDR_FORMAT, CIDR_V4_FORMAT, CIDR_V6_FORMAT, IP_FORMAT, IP_V4_FORMAT, IP_V6_FORMAT, - PROXMOX_SAFE_ID_REGEX, -}; - -pub const NETWORK_INTERFACE_FORMAT: ApiStringFormat = - ApiStringFormat::Pattern(&PROXMOX_SAFE_ID_REGEX); - -pub const IP_V4_SCHEMA: Schema = StringSchema::new("IPv4 address.") - .format(&IP_V4_FORMAT) - .max_length(15) - .schema(); - -pub const IP_V6_SCHEMA: Schema = StringSchema::new("IPv6 address.") - .format(&IP_V6_FORMAT) - .max_length(39) - .schema(); - -pub const IP_SCHEMA: Schema = StringSchema::new("IP (IPv4 or IPv6) address.") - .format(&IP_FORMAT) - .max_length(39) - .schema(); - -pub const CIDR_V4_SCHEMA: Schema = StringSchema::new("IPv4 address with netmask (CIDR notation).") - .format(&CIDR_V4_FORMAT) - .max_length(18) - .schema(); - -pub const CIDR_V6_SCHEMA: Schema = StringSchema::new("IPv6 address with netmask (CIDR notation).") - .format(&CIDR_V6_FORMAT) - .max_length(43) - .schema(); - -pub const CIDR_SCHEMA: Schema = - StringSchema::new("IP address (IPv4 or IPv6) with netmask (CIDR notation).") - .format(&CIDR_FORMAT) - .max_length(43) - .schema(); - -#[api()] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] -#[serde(rename_all = "lowercase")] -/// Interface configuration method -pub enum NetworkConfigMethod { - /// Configuration is done manually using other tools - Manual, - /// Define interfaces with statically allocated addresses. - Static, - /// Obtain an address via DHCP - DHCP, - /// Define the loopback interface. - Loopback, -} - -#[api()] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] -#[serde(rename_all = "kebab-case")] -#[repr(u8)] -/// Linux Bond Mode -pub enum LinuxBondMode { - /// Round-robin policy - BalanceRr = 0, - /// Active-backup policy - ActiveBackup = 1, - /// XOR policy - BalanceXor = 2, - /// Broadcast policy - Broadcast = 3, - /// IEEE 802.3ad Dynamic link aggregation - #[serde(rename = "802.3ad")] - Ieee802_3ad = 4, - /// Adaptive transmit load balancing - BalanceTlb = 5, - /// Adaptive load balancing - BalanceAlb = 6, -} - -impl fmt::Display for LinuxBondMode { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str(match self { - LinuxBondMode::BalanceRr => "balance-rr", - LinuxBondMode::ActiveBackup => "active-backup", - LinuxBondMode::BalanceXor => "balance-xor", - LinuxBondMode::Broadcast => "broadcast", - LinuxBondMode::Ieee802_3ad => "802.3ad", - LinuxBondMode::BalanceTlb => "balance-tlb", - LinuxBondMode::BalanceAlb => "balance-alb", - }) - } -} - -#[api()] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] -#[serde(rename_all = "kebab-case")] -#[repr(u8)] -/// Bond Transmit Hash Policy for LACP (802.3ad) -pub enum BondXmitHashPolicy { - /// Layer 2 - Layer2 = 0, - /// Layer 2+3 - #[serde(rename = "layer2+3")] - Layer2_3 = 1, - /// Layer 3+4 - #[serde(rename = "layer3+4")] - Layer3_4 = 2, -} - -impl fmt::Display for BondXmitHashPolicy { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str(match self { - BondXmitHashPolicy::Layer2 => "layer2", - BondXmitHashPolicy::Layer2_3 => "layer2+3", - BondXmitHashPolicy::Layer3_4 => "layer3+4", - }) - } -} - -#[api()] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] -#[serde(rename_all = "lowercase")] -/// Network interface type -pub enum NetworkInterfaceType { - /// Loopback - Loopback, - /// Physical Ethernet device - Eth, - /// Linux Bridge - Bridge, - /// Linux Bond - Bond, - /// Linux VLAN (eth.10) - Vlan, - /// Interface Alias (eth:1) - Alias, - /// Unknown interface type - Unknown, -} - -pub const NETWORK_INTERFACE_NAME_SCHEMA: Schema = StringSchema::new("Network interface name.") - .format(&NETWORK_INTERFACE_FORMAT) - .min_length(1) - .max_length(15) // libc::IFNAMSIZ-1 - .schema(); - -pub const NETWORK_INTERFACE_ARRAY_SCHEMA: Schema = - ArraySchema::new("Network interface list.", &NETWORK_INTERFACE_NAME_SCHEMA).schema(); - -pub const NETWORK_INTERFACE_LIST_SCHEMA: Schema = - StringSchema::new("A list of network devices, comma separated.") - .format(&ApiStringFormat::PropertyString( - &NETWORK_INTERFACE_ARRAY_SCHEMA, - )) - .schema(); - -#[api( - properties: { - name: { - schema: NETWORK_INTERFACE_NAME_SCHEMA, - }, - "type": { - type: NetworkInterfaceType, - }, - method: { - type: NetworkConfigMethod, - optional: true, - }, - method6: { - type: NetworkConfigMethod, - optional: true, - }, - cidr: { - schema: CIDR_V4_SCHEMA, - optional: true, - }, - cidr6: { - schema: CIDR_V6_SCHEMA, - optional: true, - }, - gateway: { - schema: IP_V4_SCHEMA, - optional: true, - }, - gateway6: { - schema: IP_V6_SCHEMA, - optional: true, - }, - options: { - description: "Option list (inet)", - type: Array, - items: { - description: "Optional attribute line.", - type: String, - }, - }, - options6: { - description: "Option list (inet6)", - type: Array, - items: { - description: "Optional attribute line.", - type: String, - }, - }, - comments: { - description: "Comments (inet, may span multiple lines)", - type: String, - optional: true, - }, - comments6: { - description: "Comments (inet6, may span multiple lines)", - type: String, - optional: true, - }, - bridge_ports: { - schema: NETWORK_INTERFACE_ARRAY_SCHEMA, - optional: true, - }, - slaves: { - 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, - }, - "bond-primary": { - schema: NETWORK_INTERFACE_NAME_SCHEMA, - optional: true, - }, - bond_xmit_hash_policy: { - type: BondXmitHashPolicy, - optional: true, - }, - } -)] -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -/// Network Interface configuration -pub struct Interface { - /// Autostart interface - #[serde(rename = "autostart")] - pub autostart: bool, - /// Interface is active (UP) - pub active: bool, - /// Interface name - pub name: String, - /// Interface type - #[serde(rename = "type")] - pub interface_type: NetworkInterfaceType, - #[serde(skip_serializing_if = "Option::is_none")] - pub method: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub method6: Option, - #[serde(skip_serializing_if = "Option::is_none")] - /// IPv4 address with netmask - pub cidr: Option, - #[serde(skip_serializing_if = "Option::is_none")] - /// IPv4 gateway - pub gateway: Option, - #[serde(skip_serializing_if = "Option::is_none")] - /// IPv6 address with netmask - pub cidr6: Option, - #[serde(skip_serializing_if = "Option::is_none")] - /// IPv6 gateway - pub gateway6: Option, - - #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub options: Vec, - #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub options6: Vec, - - #[serde(skip_serializing_if = "Option::is_none")] - pub comments: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub comments6: Option, - - #[serde(skip_serializing_if = "Option::is_none")] - /// Maximum Transmission Unit - pub mtu: Option, - - #[serde(skip_serializing_if = "Option::is_none")] - pub bridge_ports: Option>, - /// 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>, - #[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, - #[serde(skip_serializing_if = "Option::is_none")] - pub bond_xmit_hash_policy: Option, -} - -impl Interface { - pub fn new(name: String) -> Self { - Self { - name, - interface_type: NetworkInterfaceType::Unknown, - autostart: false, - active: false, - method: None, - method6: None, - cidr: None, - gateway: None, - cidr6: None, - gateway6: None, - options: Vec::new(), - options6: Vec::new(), - comments: None, - comments6: None, - mtu: None, - bridge_ports: None, - bridge_vlan_aware: None, - vlan_id: None, - vlan_raw_device: None, - slaves: None, - bond_mode: None, - bond_primary: None, - bond_xmit_hash_policy: None, - } - } -} diff --git a/proxmox-network-api/src/api_types.rs b/proxmox-network-api/src/api_types.rs index 9f12b029..00c941e5 100644 --- a/proxmox-network-api/src/api_types.rs +++ b/proxmox-network-api/src/api_types.rs @@ -6,10 +6,10 @@ use serde::{Deserialize, Serialize}; use regex::Regex; -use proxmox_schema::api; -use proxmox_schema::api_types::SAFE_ID_REGEX; -use proxmox_schema::api_types::{CIDR_V4_SCHEMA, CIDR_V6_SCHEMA}; -use proxmox_schema::api_types::{IP_V4_SCHEMA, IP_V6_SCHEMA}; +pub use proxmox_schema::api; +pub use proxmox_schema::api_types::SAFE_ID_REGEX; +pub use proxmox_schema::api_types::{CIDR_V4_SCHEMA, CIDR_V6_SCHEMA}; +pub use proxmox_schema::api_types::{IP_V4_SCHEMA, IP_V6_SCHEMA}; use proxmox_schema::ApiStringFormat; use proxmox_schema::ArraySchema; use proxmox_schema::Schema; -- 2.47.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel