Skip to content

Commit 3f7fca0

Browse files
committed
Merge release branch 4.9 to master
* 4.9: cleanup trailing space for checkstyle Expanded tests of RFC1918 and RFC6598 validation code. Allow CGN (RFC6598) to be used within a VPC
2 parents 45f62c3 + 7228216 commit 3f7fca0

3 files changed

Lines changed: 22 additions & 13 deletions

File tree

engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2213,7 +2213,7 @@ public Network createGuestNetwork(final long networkOfferingId, final String nam
22132213
// Check if cidr is RFC1918 compliant if the network is Guest Isolated for IPv4
22142214
if (cidr != null && ntwkOff.getGuestType() == Network.GuestType.Isolated && ntwkOff.getTrafficType() == TrafficType.Guest) {
22152215
if (!NetUtils.validateGuestCidr(cidr)) {
2216-
throw new InvalidParameterValueException("Virtual Guest Cidr " + cidr + " is not RFC1918 compliant");
2216+
throw new InvalidParameterValueException("Virtual Guest Cidr " + cidr + " is not RFC 1918 or 6598 compliant");
22172217
}
22182218
}
22192219

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,22 +1147,26 @@ public static boolean validateGuestCidr(final String cidr) {
11471147
// 10.0.0.0 - 10.255.255.255 (10/8 prefix)
11481148
// 172.16.0.0 - 172.31.255.255 (172.16/12 prefix)
11491149
// 192.168.0.0 - 192.168.255.255 (192.168/16 prefix)
1150-
1151-
final String cidr1 = "10.0.0.0/8";
1152-
final String cidr2 = "172.16.0.0/12";
1153-
final String cidr3 = "192.168.0.0/16";
1150+
// RFC 6598 - The IETF detailed shared address space for use in ISP CGN
1151+
// deployments and NAT devices that can handle the same addresses occurring both on inbound and outbound interfaces.
1152+
// ARIN returned space to the IANA as needed for this allocation.
1153+
// The allocated address block is 100.64.0.0/10
1154+
final String[] allowedNetBlocks = {"10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "100.64.0.0/10"};
11541155

11551156
if (!isValidCIDR(cidr)) {
11561157
s_logger.warn("Cidr " + cidr + " is not valid");
11571158
return false;
11581159
}
11591160

1160-
if (isNetworkAWithinNetworkB(cidr, cidr1) || isNetworkAWithinNetworkB(cidr, cidr2) || isNetworkAWithinNetworkB(cidr, cidr3)) {
1161-
return true;
1162-
} else {
1163-
s_logger.warn("cidr " + cidr + " is not RFC 1918 compliant");
1164-
return false;
1161+
for (String block: allowedNetBlocks) {
1162+
if (isNetworkAWithinNetworkB(cidr, block)) {
1163+
return true;
1164+
}
11651165
}
1166+
1167+
// not in allowedNetBlocks - return false
1168+
s_logger.warn("cidr " + cidr + " is not RFC 1918 or 6598 compliant");
1169+
return false;
11661170
}
11671171

11681172
public static boolean verifyInstanceName(final String instanceName) {
@@ -1171,7 +1175,6 @@ public static boolean verifyInstanceName(final String instanceName) {
11711175
s_logger.warn("Instance name can not contain hyphen, spaces and \"+\" char");
11721176
return false;
11731177
}
1174-
11751178
return true;
11761179
}
11771180

utils/src/test/java/com/cloud/utils/net/NetUtilsTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,15 @@ public void testSameIsolationId() {
314314

315315
@Test
316316
public void testValidateGuestCidr() throws Exception {
317-
final String guestCidr = "192.168.1.0/24";
317+
final String[] validCidrs = {"10.1.1.1/16", "172.16.1.0/16", "192.168.1.0/24", "100.64.1.0/24"};
318+
final String[] invalidCidrs = {"172.33.1.0/16", "100.128.1.0/10"};
318319

319-
assertTrue(NetUtils.validateGuestCidr(guestCidr));
320+
for (String cidr: validCidrs) {
321+
assertTrue(NetUtils.validateGuestCidr(cidr));
322+
}
323+
for (String cidr: invalidCidrs) {
324+
assertFalse(NetUtils.validateGuestCidr(cidr));
325+
}
320326
}
321327

322328
@Test

0 commit comments

Comments
 (0)