To avoid artificially limiting what users can do, remove the checks that ascertain if a supplied address is a network or broadcast address. RFC1812 [0] does not explicitly forbid this, nor does RFC3021.
[0] https://www.rfc-editor.org/rfc/rfc1812 [1] https://www.rfc-editor.org/rfc/rfc3021 Signed-off-by: Michael Köppl <m.koe...@proxmox.com> --- proxmox-auto-installer/tests/parse-answer.rs | 2 -- .../parse_answer/ipv4_and_subnet_31.json | 19 ---------- .../parse_answer/ipv4_and_subnet_31.toml | 18 ---------- .../ipv4_and_subnet_addr_is_network.json | 3 -- .../ipv4_and_subnet_addr_is_network.toml | 18 ---------- proxmox-installer-common/src/utils.rs | 35 ------------------- 6 files changed, 95 deletions(-) delete mode 100644 proxmox-auto-installer/tests/resources/parse_answer/ipv4_and_subnet_31.json delete mode 100644 proxmox-auto-installer/tests/resources/parse_answer/ipv4_and_subnet_31.toml delete mode 100644 proxmox-auto-installer/tests/resources/parse_answer_fail/ipv4_and_subnet_addr_is_network.json delete mode 100644 proxmox-auto-installer/tests/resources/parse_answer_fail/ipv4_and_subnet_addr_is_network.toml diff --git a/proxmox-auto-installer/tests/parse-answer.rs b/proxmox-auto-installer/tests/parse-answer.rs index a354f21..6754374 100644 --- a/proxmox-auto-installer/tests/parse-answer.rs +++ b/proxmox-auto-installer/tests/parse-answer.rs @@ -128,7 +128,6 @@ mod tests { fqdn_from_dhcp_no_dhcp_domain_with_default_domain, full_fqdn_from_dhcp_with_default_domain, hashed_root_password, - ipv4_and_subnet_31, minimal, nic_matching, specific_nic, @@ -148,7 +147,6 @@ mod tests { duplicate_disk, fqdn_from_dhcp_no_default_domain, fqdn_hostname_only, - ipv4_and_subnet_addr_is_network, ipv4_and_subnet_mask_33, lvm_swapsize_greater_than_hdsize, no_fqdn_from_dhcp, diff --git a/proxmox-auto-installer/tests/resources/parse_answer/ipv4_and_subnet_31.json b/proxmox-auto-installer/tests/resources/parse_answer/ipv4_and_subnet_31.json deleted file mode 100644 index 2a475fe..0000000 --- a/proxmox-auto-installer/tests/resources/parse_answer/ipv4_and_subnet_31.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "autoreboot": 1, - "cidr": "10.10.10.10/31", - "country": "at", - "dns": "10.10.10.1", - "domain": "testinstall", - "filesys": "ext4", - "gateway": "10.10.10.1", - "hdsize": 223.57088470458984, - "existing_storage_auto_rename": 1, - "hostname": "pveauto", - "keymap": "de", - "mailto": "mail@no.invalid", - "mngmt_nic": "enp129s0f1np1", - "root_password": { "plain": "12345678" }, - "target_hd": "/dev/sda", - "timezone": "Europe/Vienna", - "first_boot": { "enabled": 0 } -} diff --git a/proxmox-auto-installer/tests/resources/parse_answer/ipv4_and_subnet_31.toml b/proxmox-auto-installer/tests/resources/parse_answer/ipv4_and_subnet_31.toml deleted file mode 100644 index 0ca6ca5..0000000 --- a/proxmox-auto-installer/tests/resources/parse_answer/ipv4_and_subnet_31.toml +++ /dev/null @@ -1,18 +0,0 @@ -[global] -keyboard = "de" -country = "at" -fqdn = "pveauto.testinstall" -mailto = "mail@no.invalid" -timezone = "Europe/Vienna" -root_password = "12345678" - -[network] -source = "from-answer" -cidr = "10.10.10.10/31" -dns = "10.10.10.1" -gateway = "10.10.10.1" -filter.ID_NET_NAME = "enp129s0f1np1" - -[disk-setup] -filesystem = "ext4" -disk_list = ["sda"] diff --git a/proxmox-auto-installer/tests/resources/parse_answer_fail/ipv4_and_subnet_addr_is_network.json b/proxmox-auto-installer/tests/resources/parse_answer_fail/ipv4_and_subnet_addr_is_network.json deleted file mode 100644 index b28699d..0000000 --- a/proxmox-auto-installer/tests/resources/parse_answer_fail/ipv4_and_subnet_addr_is_network.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "parse-error": "error parsing answer.toml: Invalid CIDR: address is a network address" -} diff --git a/proxmox-auto-installer/tests/resources/parse_answer_fail/ipv4_and_subnet_addr_is_network.toml b/proxmox-auto-installer/tests/resources/parse_answer_fail/ipv4_and_subnet_addr_is_network.toml deleted file mode 100644 index 7a9141b..0000000 --- a/proxmox-auto-installer/tests/resources/parse_answer_fail/ipv4_and_subnet_addr_is_network.toml +++ /dev/null @@ -1,18 +0,0 @@ -[global] -keyboard = "de" -country = "at" -fqdn = "pveauto.testinstall" -mailto = "mail@no.invalid" -timezone = "Europe/Vienna" -root_password = "12345678" - -[network] -source = "from-answer" -cidr = "10.10.10.32/27" -dns = "10.10.10.1" -gateway = "10.10.10.1" -filter.ID_NET_NAME = "enp129s0f1np1" - -[disk-setup] -filesystem = "ext4" -disk_list = ["sda"] diff --git a/proxmox-installer-common/src/utils.rs b/proxmox-installer-common/src/utils.rs index 929cc6b..054a0fd 100644 --- a/proxmox-installer-common/src/utils.rs +++ b/proxmox-installer-common/src/utils.rs @@ -16,10 +16,6 @@ pub enum CidrAddressParseError { InvalidAddr(AddrParseError), /// The mask could not be parsed. InvalidMask(Box<dyn Error>), - /// The IP address is a network address. - IsNetworkAddr, - /// The IP address is a broadcast address. - IsBroadcastAddr, } impl fmt::Display for CidrAddressParseError { @@ -32,8 +28,6 @@ impl fmt::Display for CidrAddressParseError { } CidrAddressParseError::InvalidAddr(err) => write!(f, "{err}"), CidrAddressParseError::InvalidMask(err) => write!(f, "{err}"), - CidrAddressParseError::IsNetworkAddr => write!(f, "address is a network address"), - CidrAddressParseError::IsBroadcastAddr => write!(f, "address is a broadcast address"), } } } @@ -68,7 +62,6 @@ impl CidrAddress { let addr = addr.into(); check_mask_limit(&addr, mask)?; - check_addr_valid_in_subnet(&addr, mask)?; Ok(Self { addr, mask }) } @@ -109,7 +102,6 @@ impl FromStr for CidrAddress { .map_err(|err| CidrAddressParseError::InvalidMask(Box::new(err)))?; check_mask_limit(&addr, mask)?; - check_addr_valid_in_subnet(&addr, mask)?; Ok(Self { addr, mask }) } @@ -148,33 +140,6 @@ fn check_mask_limit(addr: &IpAddr, mask: usize) -> Result<(), CidrAddressParseEr }; } -fn check_addr_valid_in_subnet(addr: &IpAddr, mask: usize) -> Result<(), CidrAddressParseError> { - match &addr { - IpAddr::V4(addr_v4) => { - if mask >= 31 { - return Ok(()); - } - - let num_host_bits = 32 - mask; - let host_part_mask = (1u32 << num_host_bits) - 1; - - let ip_bits = u32::from_be_bytes(addr_v4.octets()); - - let network_addr = ip_bits & !host_part_mask; - let broadcast_addr = network_addr | host_part_mask; - - if ip_bits == network_addr { - Err(CidrAddressParseError::IsNetworkAddr) - } else if ip_bits == broadcast_addr { - Err(CidrAddressParseError::IsBroadcastAddr) - } else { - Ok(()) - } - } - IpAddr::V6(_) => Ok(()), - } -} - /// Possible errors that might occur when parsing FQDNs. #[derive(Debug, Eq, PartialEq)] pub enum FqdnParseError { -- 2.47.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel