Skip to content
This repository was archived by the owner on Jan 15, 2020. It is now read-only.

Commit 86a2a75

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 2bebb12 commit 86a2a75

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
@@ -1644,6 +1644,11 @@ public Set<Long> getAvailableIps(Network network, String requestedIp) {
16441644
if (usedIps.size() != 0) {
16451645
allPossibleIps.removeAll(usedIps);
16461646
}
1647+
1648+
String gateway = network.getGateway();
1649+
if ((gateway != null) && (allPossibleIps.contains(NetUtils.ip2Long(gateway))))
1650+
allPossibleIps.remove(NetUtils.ip2Long(gateway));
1651+
16471652
return allPossibleIps;
16481653
}
16491654

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,6 +2046,11 @@ protected Set<Long> getAvailableIps(Network network, String requestedIp) {
20462046
if (usedIps.size() != 0) {
20472047
allPossibleIps.removeAll(usedIps);
20482048
}
2049+
2050+
String gateway = network.getGateway();
2051+
if ((gateway != null) && (allPossibleIps.contains(NetUtils.ip2Long(gateway))))
2052+
allPossibleIps.remove(NetUtils.ip2Long(gateway));
2053+
20492054
return allPossibleIps;
20502055
}
20512056

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)