[pve-devel] [PATCH proxmox v4 1/5] network-types: initial commit
Stefan Hanreich
s.hanreich at proxmox.com
Thu Jul 3 15:48:43 CEST 2025
On 7/3/25 15:46, Stefan Hanreich wrote:
> On 7/3/25 15:11, Wolfgang Bumiller wrote:
>>> + /// checks whether this CIDR contains an IPv4 address.
>>> + pub fn contains_address(&self, other: &Ipv4Addr) -> bool {
>>> + let bits = u32::from_be_bytes(self.addr.octets());
>>> + let other_bits = u32::from_be_bytes(other.octets());
>>> +
>>> + let shift_amount: u32 = IPV4_LENGTH.saturating_sub(self.mask).into();
>>> +
>>> + bits.checked_shr(shift_amount).unwrap_or(0)
>>> + == other_bits.checked_shr(shift_amount).unwrap_or(0)
>>
>> ^ Could IMO just use `>>` since `IPV4_LENGTH.saturating_sub(self.mask)`
>> is always <= the number of bits or an u32.
>
> shift_amount can be 32 and >> needs the shift amount to be strictly
> smaller than the width of the integer, see [1].
>
> We could short-circuit when mask == width instead?
mask == 0, ofc
More information about the pve-devel
mailing list