Skip to content

Commit 0ce1d4f

Browse files
ustcweizhouchipchilders
authored andcommitted
CLOUDSTACK-1668: Fix IP conflict in VPC tier
Currently, allPossibleIps return the Ip lists which include the gateway, so we need to remove gateway ip from this list. Now, for non-VPC network it works, because NetUtils.getAllIpsFromCidr return the Ip lists which do not include the first IP of the network (like 192.168.0.1). We need too add the first IP into the returned Ip list, because it can be used for VM if it is not the gateway IP (for example, VPC networks). The corresponding patch for 4.0.1 has been posted on https://reviews.apache.org/r/9923/ Signed-off-by: Chip Childers <chip.childers@gmail.com>
1 parent 7802a62 commit 0ce1d4f

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎server/src/com/cloud/network/NetworkModelImpl.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,11 @@ public Set<Long> getAvailableIps(Network network, String requestedIp) {
16391639
if (usedIps.size() != 0) {
16401640
allPossibleIps.removeAll(usedIps);
16411641
}
1642+
1643+
String gateway = network.getGateway();
1644+
if ((gateway != null) && (allPossibleIps.contains(NetUtils.ip2Long(gateway))))
1645+
allPossibleIps.remove(NetUtils.ip2Long(gateway));
1646+
16421647
return allPossibleIps;
16431648
}
16441649

‎server/src/com/cloud/network/NetworkServiceImpl.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,6 +1751,11 @@ protected Set<Long> getAvailableIps(Network network, String requestedIp) {
17511751
if (usedIps.size() != 0) {
17521752
allPossibleIps.removeAll(usedIps);
17531753
}
1754+
1755+
String gateway = network.getGateway();
1756+
if ((gateway != null) && (allPossibleIps.contains(NetUtils.ip2Long(gateway))))
1757+
allPossibleIps.remove(NetUtils.ip2Long(gateway));
1758+
17541759
return allPossibleIps;
17551760
}
17561761

‎utils/src/com/cloud/utils/net/NetUtils.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ public static Set<Long> getAllIpsFromCidr(String cidr, long size) {
632632
Set<Long> result = new TreeSet<Long>();
633633
long ip = ip2Long(cidr);
634634
long startNetMask = ip2Long(getCidrNetmask(size));
635-
long start = (ip & startNetMask) + 2;
635+
long start = (ip & startNetMask) + 1;
636636
long end = start;
637637

638638
end = end >> (32 - size);

0 commit comments

Comments
 (0)