Skip to content

Conversation

omertuc
Copy link
Contributor

@omertuc omertuc commented Nov 17, 2022

b0489a5 introduced a regression where
the calculation for the number of IPv6 IP addresses always yields a
negative or 0 value, causing users to always encounter the following
error when creating IPv6 libvirt networks:

netmask seems to be too strict: only <0 or negative> IPs available (ipv6)

(An example is available at the end of this CI log)

That commit attempted to fix the wrong use of the ^ operator in the
calculation, which was truely wrong. But it was just wrong in a
relatively "harmless" way, as it wasn't completely blocking users.

The fix in that commit had its own bug - a 1 shifted by 128 always
gives 0, and not the desired 2 to the power of 128, because the
latter doesn't fit in a primitive integer type.

To fix this, I've changed the calculation to simply consider the number
of bits available for the subnet, rather than the number of IP addresses
available for the subnet, as that is obviously a much smaller number,
one that the primitive Go integer types can handle

b0489a5 introduced a regression where
the calculation for the number of IPv6 IP addresses always yields a
negative or 0 value, causing users to *always* encounter the following
error when creating IPv6 libvirt networks:

`netmask seems to be too strict: only <0 or negative> IPs available (ipv6)`

That commit attempted to fix the wrong use of the `^` operator in the
calculation, which was truely wrong. But it was just wrong in a
relatively "harmless" way, as it wasn't completely blocking users.

The fix in that commit had its own bug - a `1` shifted by `128` always
gives `0`, and not the desired `2 to the power of 128`, because the
latter doesn't fit in a primitive integer type.

To fix this, I've changed the calculation to simply consider the number
of bits available for the subnet, rather than the number of IP addresses
available for the subnet, as that is obviously a much smaller number,
one that the primitive Go integer types can handle
@osherdp
Copy link

osherdp commented Nov 28, 2022

@dmacvicar just FYI as it's currently a blocker for our usage of the new version v0.7.0

@dmacvicar dmacvicar merged commit 105ef85 into dmacvicar:main Dec 27, 2022
@dmacvicar
Copy link
Owner

Thanks for the patch @omertuc

@dmacvicar
Copy link
Owner

This is included in 0.7.1

@osherdp
Copy link

osherdp commented Dec 27, 2022

Thank you very much!
I'll test it right away

dmacvicar pushed a commit to jimnydev/terraform-provider-libvirt that referenced this pull request Sep 28, 2024
b0489a5 introduced a regression where
the calculation for the number of IPv6 IP addresses always yields a
negative or 0 value, causing users to *always* encounter the following
error when creating IPv6 libvirt networks:

`netmask seems to be too strict: only <0 or negative> IPs available (ipv6)`

That commit attempted to fix the wrong use of the `^` operator in the
calculation, which was truely wrong. But it was just wrong in a
relatively "harmless" way, as it wasn't completely blocking users.

The fix in that commit had its own bug - a `1` shifted by `128` always
gives `0`, and not the desired `2 to the power of 128`, because the
latter doesn't fit in a primitive integer type.

To fix this, I've changed the calculation to simply consider the number
of bits available for the subnet, rather than the number of IP addresses
available for the subnet, as that is obviously a much smaller number,
one that the primitive Go integer types can handle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants