From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pve-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id C46CE1FF164 for <inbox@lore.proxmox.com>; Fri, 28 Mar 2025 18:15:25 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 7FF5287F2; Fri, 28 Mar 2025 18:14:04 +0100 (CET) From: Gabriel Goller <g.goller@proxmox.com> To: pve-devel@lists.proxmox.com Date: Fri, 28 Mar 2025 18:12:53 +0100 Message-Id: <20250328171340.885413-6-g.goller@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250328171340.885413-1-g.goller@proxmox.com> References: <20250328171340.885413-1-g.goller@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.025 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 Subject: [pve-devel] [PATCH proxmox-ve-rs 04/17] network-types: move Ipv4Cidr and Ipv6Cidr types X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/> List-Post: <mailto:pve-devel@lists.proxmox.com> List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com> Move the Ipv4Cidr and Ipv6Cidr types (and co.) from proxmox-ve-config firewall module to the proxmox-network-types crate. They are also used in the fabrics module, so to avoid importing from the firewall module, move them here. We also have to update the proxmox-firewall crate, which is done in a following patch. Signed-off-by: Gabriel Goller <g.goller@proxmox.com> --- .../src}/address.rs | 14 +++++----- proxmox-network-types/src/lib.rs | 1 + proxmox-ve-config/Cargo.toml | 1 + proxmox-ve-config/src/firewall/cluster.rs | 3 +-- proxmox-ve-config/src/firewall/ct_helper.rs | 8 +++--- proxmox-ve-config/src/firewall/host.rs | 3 ++- proxmox-ve-config/src/firewall/types/alias.rs | 3 ++- proxmox-ve-config/src/firewall/types/ipset.rs | 26 ++++++++++++++++--- proxmox-ve-config/src/firewall/types/mod.rs | 2 -- proxmox-ve-config/src/firewall/types/rule.rs | 3 +-- .../src/firewall/types/rule_match.rs | 5 ++-- proxmox-ve-config/src/guest/vm.rs | 4 ++- proxmox-ve-config/src/host/utils.rs | 2 +- proxmox-ve-config/src/sdn/config.rs | 8 +++--- proxmox-ve-config/src/sdn/ipam.rs | 4 ++- proxmox-ve-config/src/sdn/mod.rs | 2 +- proxmox-ve-config/tests/sdn/main.rs | 3 ++- 17 files changed, 61 insertions(+), 31 deletions(-) rename {proxmox-ve-config/src/firewall/types => proxmox-network-types/src}/address.rs (99%) diff --git a/proxmox-ve-config/src/firewall/types/address.rs b/proxmox-network-types/src/address.rs similarity index 99% rename from proxmox-ve-config/src/firewall/types/address.rs rename to proxmox-network-types/src/address.rs index 9b73d3d79d4e..218e2e21105e 100644 --- a/proxmox-ve-config/src/firewall/types/address.rs +++ b/proxmox-network-types/src/address.rs @@ -119,7 +119,9 @@ impl From<IpAddr> for Cidr { const IPV4_LENGTH: u8 = 32; -#[derive(Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq, Hash)] +#[derive( + SerializeDisplay, DeserializeFromStr, Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq, Hash, +)] pub struct Ipv4Cidr { addr: Ipv4Addr, mask: u8, @@ -193,7 +195,9 @@ impl fmt::Display for Ipv4Cidr { const IPV6_LENGTH: u8 = 128; -#[derive(Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq, Hash)] +#[derive( + SerializeDisplay, DeserializeFromStr, Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq, Hash, +)] pub struct Ipv6Cidr { addr: Ipv6Addr, mask: u8, @@ -596,8 +600,7 @@ impl<T: fmt::Display> fmt::Display for AddressRange<T> { } } -#[derive(Clone, Debug)] -#[cfg_attr(test, derive(Eq, PartialEq))] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum IpEntry { Cidr(Cidr), Range(IpRange), @@ -649,8 +652,7 @@ impl From<IpRange> for IpEntry { } } -#[derive(Clone, Debug, DeserializeFromStr)] -#[cfg_attr(test, derive(Eq, PartialEq))] +#[derive(Clone, Debug, DeserializeFromStr, PartialEq, Eq)] pub struct IpList { // guaranteed to have the same family entries: Vec<IpEntry>, diff --git a/proxmox-network-types/src/lib.rs b/proxmox-network-types/src/lib.rs index 797084fec423..53079b2712a7 100644 --- a/proxmox-network-types/src/lib.rs +++ b/proxmox-network-types/src/lib.rs @@ -1,3 +1,4 @@ +pub mod address; pub mod hostname; pub mod net; pub mod openfabric; diff --git a/proxmox-ve-config/Cargo.toml b/proxmox-ve-config/Cargo.toml index b20ced177265..4906d77550f3 100644 --- a/proxmox-ve-config/Cargo.toml +++ b/proxmox-ve-config/Cargo.toml @@ -20,3 +20,4 @@ serde_with = "3" proxmox-schema = "4" proxmox-sys = "0.6.4" proxmox-sortable-macro = "0.1.3" +proxmox-network-types = { version = "0.1", path = "../proxmox-network-types/" } diff --git a/proxmox-ve-config/src/firewall/cluster.rs b/proxmox-ve-config/src/firewall/cluster.rs index ce3dd53446f8..b4e5271c4497 100644 --- a/proxmox-ve-config/src/firewall/cluster.rs +++ b/proxmox-ve-config/src/firewall/cluster.rs @@ -135,7 +135,6 @@ pub struct Options { #[cfg(test)] mod tests { use crate::firewall::types::{ - address::IpList, alias::{AliasName, AliasScope}, ipset::{IpsetAddress, IpsetEntry}, log::{LogLevel, LogRateLimitTimescale}, @@ -143,8 +142,8 @@ mod tests { rule_match::{ Icmpv6, Icmpv6Code, IpAddrMatch, IpMatch, Ports, Protocol, RuleMatch, Tcp, Udp, }, - Cidr, }; + use proxmox_network_types::address::{Cidr, IpList}; use super::*; diff --git a/proxmox-ve-config/src/firewall/ct_helper.rs b/proxmox-ve-config/src/firewall/ct_helper.rs index 40e4feef5b12..f4c5ba8cef3b 100644 --- a/proxmox-ve-config/src/firewall/ct_helper.rs +++ b/proxmox-ve-config/src/firewall/ct_helper.rs @@ -1,9 +1,11 @@ -use anyhow::{bail, Error}; -use serde::Deserialize; use std::collections::HashMap; use std::sync::OnceLock; -use crate::firewall::types::address::Family; +use anyhow::{bail, Error}; +use serde::Deserialize; + +use proxmox_network_types::address::Family; + use crate::firewall::types::rule_match::{Ports, Protocol, Tcp, Udp}; #[derive(Clone, Debug, Deserialize)] diff --git a/proxmox-ve-config/src/firewall/host.rs b/proxmox-ve-config/src/firewall/host.rs index 394896c48221..31ced4c3edbe 100644 --- a/proxmox-ve-config/src/firewall/host.rs +++ b/proxmox-ve-config/src/firewall/host.rs @@ -5,12 +5,13 @@ use anyhow::{bail, Error}; use serde::Deserialize; use crate::host::utils::{host_ips, network_interface_cidrs}; +use proxmox_network_types::address::Cidr; use proxmox_sys::nodename; use crate::firewall::parse; use crate::firewall::types::log::LogLevel; use crate::firewall::types::rule::Direction; -use crate::firewall::types::{Alias, Cidr, Rule}; +use crate::firewall::types::{Alias, Rule}; /// default setting for the enabled key pub const HOST_ENABLED_DEFAULT: bool = true; diff --git a/proxmox-ve-config/src/firewall/types/alias.rs b/proxmox-ve-config/src/firewall/types/alias.rs index 7bc2fb8395db..2fa2658e413a 100644 --- a/proxmox-ve-config/src/firewall/types/alias.rs +++ b/proxmox-ve-config/src/firewall/types/alias.rs @@ -4,8 +4,9 @@ use std::str::FromStr; use anyhow::{bail, format_err, Error}; use serde_with::{DeserializeFromStr, SerializeDisplay}; +use proxmox_network_types::address::Cidr; + use crate::firewall::parse::{match_name, match_non_whitespace}; -use crate::firewall::types::address::Cidr; #[derive(Debug, Clone)] #[cfg_attr(test, derive(Eq, PartialEq))] diff --git a/proxmox-ve-config/src/firewall/types/ipset.rs b/proxmox-ve-config/src/firewall/types/ipset.rs index fe5a930f2352..c048e3f82c32 100644 --- a/proxmox-ve-config/src/firewall/types/ipset.rs +++ b/proxmox-ve-config/src/firewall/types/ipset.rs @@ -1,12 +1,14 @@ use core::fmt::Display; +use std::net::IpAddr; use std::ops::{Deref, DerefMut}; use std::str::FromStr; use anyhow::{bail, format_err, Error}; use serde_with::DeserializeFromStr; +use proxmox_network_types::address::{Cidr, IpRange, Ipv4Cidr, Ipv6Cidr}; + use crate::firewall::parse::match_non_whitespace; -use crate::firewall::types::address::{Cidr, IpRange}; use crate::firewall::types::alias::AliasName; use crate::guest::vm::NetworkConfig; @@ -112,8 +114,26 @@ impl FromStr for IpsetAddress { } } -impl<T: Into<Cidr>> From<T> for IpsetAddress { - fn from(cidr: T) -> Self { +impl From<Ipv4Cidr> for IpsetAddress { + fn from(cidr: Ipv4Cidr) -> Self { + IpsetAddress::Cidr(cidr.into()) + } +} + +impl From<Ipv6Cidr> for IpsetAddress { + fn from(cidr: Ipv6Cidr) -> Self { + IpsetAddress::Cidr(cidr.into()) + } +} + +impl From<Cidr> for IpsetAddress { + fn from(cidr: Cidr) -> Self { + IpsetAddress::Cidr(cidr) + } +} + +impl From<IpAddr> for IpsetAddress { + fn from(cidr: IpAddr) -> Self { IpsetAddress::Cidr(cidr.into()) } } diff --git a/proxmox-ve-config/src/firewall/types/mod.rs b/proxmox-ve-config/src/firewall/types/mod.rs index 8fd551e4d226..9633e0b4fc3c 100644 --- a/proxmox-ve-config/src/firewall/types/mod.rs +++ b/proxmox-ve-config/src/firewall/types/mod.rs @@ -1,4 +1,3 @@ -pub mod address; pub mod alias; pub mod group; pub mod ipset; @@ -7,7 +6,6 @@ pub mod port; pub mod rule; pub mod rule_match; -pub use address::Cidr; pub use alias::Alias; pub use group::Group; pub use ipset::Ipset; diff --git a/proxmox-ve-config/src/firewall/types/rule.rs b/proxmox-ve-config/src/firewall/types/rule.rs index 2c8f49c27507..192d4ddfa66a 100644 --- a/proxmox-ve-config/src/firewall/types/rule.rs +++ b/proxmox-ve-config/src/firewall/types/rule.rs @@ -248,13 +248,12 @@ impl FromStr for RuleGroup { #[cfg(test)] mod tests { use crate::firewall::types::{ - address::{IpEntry, IpList, IpRange}, alias::{AliasName, AliasScope}, ipset::{IpsetName, IpsetScope}, log::LogLevel, rule_match::{Icmp, IcmpCode, IpAddrMatch, IpMatch, Ports, Protocol, Udp}, - Cidr, }; + use proxmox_network_types::address::{Cidr, IpEntry, IpList, IpRange}; use super::*; diff --git a/proxmox-ve-config/src/firewall/types/rule_match.rs b/proxmox-ve-config/src/firewall/types/rule_match.rs index 94d862439e18..05a34a7bcd46 100644 --- a/proxmox-ve-config/src/firewall/types/rule_match.rs +++ b/proxmox-ve-config/src/firewall/types/rule_match.rs @@ -7,10 +7,10 @@ use serde::Deserialize; use anyhow::{bail, format_err, Error}; use serde::de::IntoDeserializer; +use proxmox_network_types::address::{Family, IpList}; use proxmox_sortable_macro::sortable; use crate::firewall::parse::{match_name, match_non_whitespace, SomeStr}; -use crate::firewall::types::address::{Family, IpList}; use crate::firewall::types::alias::AliasName; use crate::firewall::types::ipset::IpsetName; use crate::firewall::types::log::LogLevel; @@ -770,7 +770,8 @@ impl fmt::Display for Icmpv6Code { #[cfg(test)] mod tests { - use crate::firewall::types::{alias::AliasScope::Guest, Cidr}; + use crate::firewall::types::alias::AliasScope::Guest; + use proxmox_network_types::address::Cidr; use super::*; diff --git a/proxmox-ve-config/src/guest/vm.rs b/proxmox-ve-config/src/guest/vm.rs index 3476b93cabd1..fcb653f51967 100644 --- a/proxmox-ve-config/src/guest/vm.rs +++ b/proxmox-ve-config/src/guest/vm.rs @@ -9,7 +9,7 @@ use anyhow::{bail, Error}; use serde_with::DeserializeFromStr; use crate::firewall::parse::{match_digits, parse_bool}; -use crate::firewall::types::address::{Ipv4Cidr, Ipv6Cidr}; +use proxmox_network_types::address::{Ipv4Cidr, Ipv6Cidr}; #[derive(Clone, Debug, DeserializeFromStr, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct MacAddress([u8; 6]); @@ -266,6 +266,8 @@ impl NetworkConfig { #[cfg(test)] mod tests { + use proxmox_network_types::address::Ipv4Cidr; + use super::*; #[test] diff --git a/proxmox-ve-config/src/host/utils.rs b/proxmox-ve-config/src/host/utils.rs index b1dc8e988b32..270b1af4b5d8 100644 --- a/proxmox-ve-config/src/host/utils.rs +++ b/proxmox-ve-config/src/host/utils.rs @@ -1,6 +1,6 @@ use std::net::{IpAddr, ToSocketAddrs}; -use crate::firewall::types::Cidr; +use proxmox_network_types::address::Cidr; use nix::sys::socket::{AddressFamily, SockaddrLike}; use proxmox_sys::nodename; diff --git a/proxmox-ve-config/src/sdn/config.rs b/proxmox-ve-config/src/sdn/config.rs index 7ee1101e5bb6..a25bb35ae060 100644 --- a/proxmox-ve-config/src/sdn/config.rs +++ b/proxmox-ve-config/src/sdn/config.rs @@ -6,17 +6,17 @@ use std::{ str::FromStr, }; -use proxmox_schema::{property_string::PropertyString, ApiType, ObjectSchema, StringSchema}; - use serde::Deserialize; use serde_with::{DeserializeFromStr, SerializeDisplay}; +use proxmox_network_types::address::{Cidr, IpRange, IpRangeError}; +use proxmox_schema::{property_string::PropertyString, ApiType, ObjectSchema, StringSchema}; + use crate::{ common::Allowlist, firewall::types::{ - address::{IpRange, IpRangeError}, ipset::{IpsetEntry, IpsetName, IpsetScope}, - Cidr, Ipset, + Ipset, }, sdn::{SdnNameError, SubnetName, VnetName, ZoneName}, }; diff --git a/proxmox-ve-config/src/sdn/ipam.rs b/proxmox-ve-config/src/sdn/ipam.rs index 598b835c1f72..a73e8abbdcd2 100644 --- a/proxmox-ve-config/src/sdn/ipam.rs +++ b/proxmox-ve-config/src/sdn/ipam.rs @@ -7,11 +7,13 @@ use std::{ use serde::Deserialize; +use proxmox_network_types::address::Cidr; + use crate::{ common::Allowlist, firewall::types::{ ipset::{IpsetEntry, IpsetScope}, - Cidr, Ipset, + Ipset, }, guest::{types::Vmid, vm::MacAddress}, sdn::{SdnNameError, SubnetName, ZoneName}, diff --git a/proxmox-ve-config/src/sdn/mod.rs b/proxmox-ve-config/src/sdn/mod.rs index c8dc72471693..25ed7e476b9f 100644 --- a/proxmox-ve-config/src/sdn/mod.rs +++ b/proxmox-ve-config/src/sdn/mod.rs @@ -5,7 +5,7 @@ use std::{error::Error, fmt::Display, str::FromStr}; use serde_with::DeserializeFromStr; -use crate::firewall::types::Cidr; +use proxmox_network_types::address::Cidr; #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub enum SdnNameError { diff --git a/proxmox-ve-config/tests/sdn/main.rs b/proxmox-ve-config/tests/sdn/main.rs index 1815bec5ff1a..bc71cd536ae0 100644 --- a/proxmox-ve-config/tests/sdn/main.rs +++ b/proxmox-ve-config/tests/sdn/main.rs @@ -3,8 +3,9 @@ use std::{ str::FromStr, }; +use proxmox_network_types::address::{Cidr, IpRange}; + use proxmox_ve_config::{ - firewall::types::{address::IpRange, Cidr}, guest::vm::MacAddress, sdn::{ config::{ -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel