[pve-devel] [PATCH proxmox v4 1/5] network-types: initial commit

Wolfgang Bumiller w.bumiller at proxmox.com
Fri Jul 4 09:55:51 CEST 2025


On Thu, Jul 03, 2025 at 03:48:43PM +0200, Stefan Hanreich wrote:
> 
> 
> 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

Or mask the mask with `& 31` ;-)

But it doesn't really matter, the code is fine as it is.




More information about the pve-devel mailing list