Fix IPv6 subnet size regression #983
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thecalculation, 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 by128
alwaysgives
0
, and not the desired2 to the power of 128
, because thelatter 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