[pve-devel] [RFC PATCH pve-installer v2 6/6] common: add checks for valid subnet mask and IPv4 address within subnet
Michael Köppl
m.koeppl at proxmox.com
Fri May 9 10:51:07 CEST 2025
On 5/6/25 11:21, Christoph Heiss wrote:
> Apart from the one inline comment, looks good to me.
>
> IMO it's not too restrictive, since IPv4 network/broadcast addresses
> shouldn't really be used (and probably introduce subtle breakages)
> outside of /31 prefixes anyway.
>
> On Tue Apr 29, 2025 at 4:09 PM CEST, Michael Köppl wrote:
>> Add checks for valid subnet mask (greater than /0 and at most /32 for
>> IPv4). In addition, check if the address entered by the user is valid
>> within the given subnet, i.e. not a network address or broadcast
>> address. /31 is considered an exception in accordance with RFC3021 [0],
>> considering any of the 2 available addresses to be valid host addresses.
>>
>> [0] https://datatracker.ietf.org/doc/html/rfc3021
>>
>> Signed-off-by: Michael Köppl <m.koeppl at proxmox.com>
>> ---
>> [..]
>> diff --git a/proxmox-installer-common/src/utils.rs b/proxmox-installer-common/src/utils.rs
>> index 1fe6a74..fea98db 100644
>> --- a/proxmox-installer-common/src/utils.rs
>> +++ b/proxmox-installer-common/src/utils.rs
>> [..]
>> @@ -133,6 +137,43 @@ fn mask_limit(addr: &IpAddr) -> usize {
>> if addr.is_ipv4() { 32 } else { 128 }
>> }
>>
>> +fn check_mask_limit(addr: &IpAddr, mask: usize) -> Result<(), CidrAddressParseError> {
>> + return if mask > mask_limit(&addr) {
>> + Err(CidrAddressParseError::InvalidMask(
>> + "mask cannot be greater than 32".into(),
>
> s/32/mask_limit(&addr)/g
Will update this bit when I send a v3 including a better solution for
the maxroot check. Thanks!
>
>> + ))
>> + } else {
>> + Ok(())
>> + };
>> +}
More information about the pve-devel
mailing list