-
Notifications
You must be signed in to change notification settings - Fork 74
Description
Hi SeancFoley,
Maven jar Version : 5.3.1
i was trying to get two subnets of mask 25 from IPv6 CIDR "7c40:100::/24".
which will result this ("7c40:100::/25", "7c40:180::/25")
I am able to get the first subnet of 25 using addr.getNetworkSection(25)
And for second subnet of same mask i.e 25 using addr.getNetworkSection(25).getUpper().increment(1) which is throwing Below mentioned exception
Exception in thread "main" inet.ipaddr.AddressValueException: 1, IP Address error: exceeds address size
at inet.ipaddr.format.standard.AddressDivisionGrouping.checkOverflow(AddressDivisionGrouping.java:1209)
at inet.ipaddr.ipv6.IPv6AddressSection.increment(IPv6AddressSection.java:1333)
at inet.ipaddr.ipv6.IPv6AddressSection.increment(IPv6AddressSection.java:99)
at com.ipam.mgmt.util.IpBlockUtils.getSubnet(IpBlockUtils.java:157)
at com.ipam.mgmt.util.IpBlockUtils.main(Unknown Source)
Doing some debugging i do found the root cause of the problem and solution for it too.
ROOT Cause: in IPv6AddressSection.java while checking the checkOverflow condition exception is thrown and reason why it throws exception is it get MAX_VALUES_BY_SEGMENT for segment 2 as -1
Solution : The IPv6AddressSection.java contains a BigInteger Array as pasted below
private static final BigInteger MAX_VALUES_BY_SEGMENT[] = {
BigInteger.ZERO,
BigInteger.valueOf(IPv6Address.MAX_VALUE_PER_SEGMENT),
BigInteger.valueOf(0xffffffff),
BigInteger.valueOf(0xffffffffffffL),
BigInteger.valueOf(1).shiftLeft(16 * 4).subtract(BigInteger.ONE),
BigInteger.valueOf(1).shiftLeft(16 * 5).subtract(BigInteger.ONE),
BigInteger.valueOf(1).shiftLeft(16 * 6).subtract(BigInteger.ONE),
BigInteger.valueOf(1).shiftLeft(16 * 7).subtract(BigInteger.ONE),
BigInteger.valueOf(1).shiftLeft(16 * 8).subtract(BigInteger.ONE),
};
The implementation of "BigInteger.valueOf(0xffffffff)" at index 3 is returning -1 whereas it was supposed to return "4294967295".
which can be fixed by correcting the Value at 3rd Index by adding L as shown below
"BigInteger.valueOf(0xffffffff)" -> BigInteger.valueOf(0xffffffffL)
"BigInteger.valueOf(0xffffffff)" gives -1
"BigInteger.valueOf(0xffffffffL)" gives 4294967295
Please fix it and provide new Hotfix for it.