Skip to content

Commit ca5c6d5

Browse files
author
Sheng Yang
committed
CLOUDSTACK-1219, CLOUDSTACK-1220: Fix IPv6 error messages
1 parent cf7ac9d commit ca5c6d5

6 files changed

Lines changed: 50 additions & 17 deletions

File tree

api/src/com/cloud/network/NetworkModel.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,6 @@ Map<PublicIpAddress, Set<Service>> getIpToServices(List<? extends PublicIpAddres
255255
boolean isIP6AddressAvailableInVlan(long vlanId);
256256

257257
void checkIp6Parameters(String startIPv6, String endIPv6, String ip6Gateway, String ip6Cidr) throws InvalidParameterValueException;
258+
259+
void checkRequestedIpAddresses(long networkId, String ip4, String ip6) throws InvalidParameterValueException;
258260
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public UserIpv6Address assignDirectIp6Address(long dcId, Account owner, Long net
8080
}
8181
List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(networkId);
8282
if (vlans == null) {
83-
s_logger.debug("Cannot find related vlan or too many vlan attached to network " + networkId);
83+
s_logger.debug("Cannot find related vlan attached to network " + networkId);
8484
return null;
8585
}
8686
String ip = null;
@@ -109,7 +109,7 @@ public UserIpv6Address assignDirectIp6Address(long dcId, Account owner, Long net
109109
}
110110
}
111111
if (ip == null) {
112-
throw new InsufficientAddressCapacityException("Cannot find a usable IP in the network " + network.getName() + " after network.ipv6.search.retry.max = " + _ipv6RetryMax + " times retry!",
112+
throw new InsufficientAddressCapacityException("Cannot find a usable IP in the network " + network.getName() + " after " + _ipv6RetryMax + "(network.ipv6.search.retry.max) times retry!",
113113
DataCenter.class, network.getDataCenterId());
114114
}
115115
} else {

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,4 +1923,36 @@ public void checkIp6Parameters(String startIPv6, String endIPv6,
19231923
throw new InvalidParameterValueException("The cidr size of IPv6 network must be no less than 64 bits!");
19241924
}
19251925
}
1926+
1927+
@Override
1928+
public void checkRequestedIpAddresses(long networkId, String ip4, String ip6) throws InvalidParameterValueException {
1929+
if (ip4 != null) {
1930+
if (!NetUtils.isValidIp(ip4)) {
1931+
throw new InvalidParameterValueException("Invalid specified IPv4 address " + ip4);
1932+
}
1933+
//Other checks for ipv4 are done in assignPublicIpAddress()
1934+
}
1935+
if (ip6 != null) {
1936+
if (!NetUtils.isValidIpv6(ip6)) {
1937+
throw new InvalidParameterValueException("Invalid specified IPv6 address " + ip6);
1938+
}
1939+
if (_ipv6Dao.findByNetworkIdAndIp(networkId, ip6) != null) {
1940+
throw new InvalidParameterValueException("The requested IP is already taken!");
1941+
}
1942+
List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(networkId);
1943+
if (vlans == null) {
1944+
throw new CloudRuntimeException("Cannot find related vlan attached to network " + networkId);
1945+
}
1946+
Vlan ipVlan = null;
1947+
for (Vlan vlan : vlans) {
1948+
if (NetUtils.isIp6InRange(ip6, vlan.getIp6Range())) {
1949+
ipVlan = vlan;
1950+
break;
1951+
}
1952+
}
1953+
if (ipVlan == null) {
1954+
throw new InvalidParameterValueException("Requested IPv6 is not in the predefined range!");
1955+
}
1956+
}
1957+
}
19261958
}

server/src/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3299,7 +3299,7 @@ protected UserVm createVirtualMachine(DataCenter zone, ServiceOffering serviceOf
32993299
if (requestedIpPair == null) {
33003300
requestedIpPair = new IpAddresses(null, null);
33013301
} else {
3302-
checkRequestedIpAddresses(requestedIpPair.getIp4Address(), requestedIpPair.getIp6Address());
3302+
_networkModel.checkRequestedIpAddresses(network.getId(), requestedIpPair.getIp4Address(), requestedIpPair.getIp6Address());
33033303
}
33043304

33053305
NicProfile profile = new NicProfile(requestedIpPair.getIp4Address(), requestedIpPair.getIp6Address());
@@ -3308,7 +3308,7 @@ protected UserVm createVirtualMachine(DataCenter zone, ServiceOffering serviceOf
33083308
defaultNetworkNumber++;
33093309
// if user requested specific ip for default network, add it
33103310
if (defaultIps.getIp4Address() != null || defaultIps.getIp6Address() != null) {
3311-
checkRequestedIpAddresses(defaultIps.getIp4Address(), defaultIps.getIp6Address());
3311+
_networkModel.checkRequestedIpAddresses(network.getId(), defaultIps.getIp4Address(), defaultIps.getIp6Address());
33123312
profile = new NicProfile(defaultIps.getIp4Address(), defaultIps.getIp6Address());
33133313
}
33143314

@@ -3486,19 +3486,6 @@ protected UserVm createVirtualMachine(DataCenter zone, ServiceOffering serviceOf
34863486
return vm;
34873487
}
34883488

3489-
private void checkRequestedIpAddresses(String ip4, String ip6) throws InvalidParameterValueException {
3490-
if (ip4 != null) {
3491-
if (!NetUtils.isValidIp(ip4)) {
3492-
throw new InvalidParameterValueException("Invalid specified IPv4 address " + ip4);
3493-
}
3494-
}
3495-
if (ip6 != null) {
3496-
if (!NetUtils.isValidIpv6(ip6)) {
3497-
throw new InvalidParameterValueException("Invalid specified IPv6 address " + ip6);
3498-
}
3499-
}
3500-
}
3501-
35023489
private void validateUserData(String userData) {
35033490
byte[] decodedUserData = null;
35043491
if (userData != null) {

server/test/com/cloud/network/MockNetworkModelImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,4 +829,10 @@ public void checkIp6Parameters(String startIPv6, String endIPv6,
829829
// TODO Auto-generated method stub
830830

831831
}
832+
833+
@Override
834+
public void checkRequestedIpAddresses(long networkId, String ip4, String ip6)
835+
throws InvalidParameterValueException {
836+
// TODO Auto-generated method stub
837+
}
832838
}

server/test/com/cloud/vpc/MockNetworkModelImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,4 +842,10 @@ public void checkIp6Parameters(String startIPv6, String endIPv6, String ip6Gatew
842842
// TODO Auto-generated method stub
843843
}
844844

845+
@Override
846+
public void checkRequestedIpAddresses(long networkId, String ip4, String ip6)
847+
throws InvalidParameterValueException {
848+
// TODO Auto-generated method stub
849+
}
850+
845851
}

0 commit comments

Comments
 (0)