mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
CLOUDSTACK-1762 Fixed assigning network or broadcast ip to nic
This commit is contained in:
parent
68406ba29d
commit
cd6e6a4d3c
@ -1644,6 +1644,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
|
||||
Set<Long> availableIps = _networkModel.getAvailableIps(network, requestedIp);
|
||||
|
||||
if (availableIps == null || availableIps.isEmpty()) {
|
||||
s_logger.debug("There are no free ips in the network " + network );
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -1656,9 +1657,11 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
|
||||
if (!isSameCidr) {
|
||||
s_logger.warn("Requested ip address " + requestedIp + " doesn't belong to the network " + network + " cidr");
|
||||
return null;
|
||||
} else {
|
||||
return requestedIp;
|
||||
} else if (NetUtils.IsIpEqualToNetworkOrBroadCastIp(requestedIp, cidr[0], Integer.parseInt(cidr[1]))) {
|
||||
s_logger.warn("Requested ip address " + requestedIp + " is equal to the to the network/broadcast ip of the network" + network);
|
||||
return null;
|
||||
}
|
||||
return requestedIp;
|
||||
}
|
||||
|
||||
String result;
|
||||
|
||||
@ -1427,4 +1427,26 @@ public class NetUtils {
|
||||
SubnetUtils subnetUtils = new SubnetUtils(cidr);
|
||||
return subnetUtils.getInfo().isInRange(ipAddress);
|
||||
}
|
||||
|
||||
public static Boolean IsIpEqualToNetworkOrBroadCastIp(String requestedIp, String cidr, long size) {
|
||||
assert (size < 32) : "You do know this is not for ipv6 right? Keep it smaller than 32 but you have " + size;
|
||||
|
||||
long ip = ip2Long(cidr);
|
||||
long startNetMask = ip2Long(getCidrNetmask(size));
|
||||
|
||||
long start = (ip & startNetMask);
|
||||
long end = start;
|
||||
|
||||
end = end >> (32 - size);
|
||||
|
||||
end++;
|
||||
end = (end << (32 - size)) - 1;
|
||||
|
||||
long reqIp = ip2Long(requestedIp);
|
||||
if (reqIp == start || reqIp == end) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user