Commit 105ef85
authored
Fix IPv6 subnet size regression (#983)
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 handle1 parent 07cb1ec commit 105ef85
1 file changed
+9
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
119 | | - | |
120 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
121 | 127 | | |
122 | 128 | | |
123 | 129 | | |
| |||
0 commit comments