Skip to content

Commit 7228216

Browse files
authored
Merge pull request #1606 from myENA/upstream/vpc-cgn
Allow CGN (RFC6598) to be used within a VPC
2 parents bdc4fd7 + 2a48f65 commit 7228216

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

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

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

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

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

11491150
if (!isValidCIDR(cidr)) {
11501151
s_logger.warn("Cidr " + cidr + " is not valid");
11511152
return false;
11521153
}
11531154

1154-
if (isNetworkAWithinNetworkB(cidr, cidr1) || isNetworkAWithinNetworkB(cidr, cidr2) || isNetworkAWithinNetworkB(cidr, cidr3)) {
1155-
return true;
1156-
} else {
1157-
s_logger.warn("cidr " + cidr + " is not RFC 1918 compliant");
1158-
return false;
1155+
for (String block: allowedNetBlocks) {
1156+
if (isNetworkAWithinNetworkB(cidr, block)) {
1157+
return true;
1158+
}
11591159
}
1160+
1161+
// not in allowedNetBlocks - return false
1162+
s_logger.warn("cidr " + cidr + " is not RFC 1918 or 6598 compliant");
1163+
return false;
11601164
}
11611165

11621166
public static boolean verifyInstanceName(final String instanceName) {
@@ -1165,7 +1169,6 @@ public static boolean verifyInstanceName(final String instanceName) {
11651169
s_logger.warn("Instance name can not contain hyphen, spaces and \"+\" char");
11661170
return false;
11671171
}
1168-
11691172
return true;
11701173
}
11711174

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

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

302302
@Test
303303
public void testValidateGuestCidr() throws Exception {
304-
final String guestCidr = "192.168.1.0/24";
304+
final String[] validCidrs = {"10.1.1.1/16", "172.16.1.0/16", "192.168.1.0/24", "100.64.1.0/24"};
305+
final String[] invalidCidrs = {"172.33.1.0/16", "100.128.1.0/10"};
305306

306-
assertTrue(NetUtils.validateGuestCidr(guestCidr));
307+
for (String cidr: validCidrs) {
308+
assertTrue(NetUtils.validateGuestCidr(cidr));
309+
}
310+
for (String cidr: invalidCidrs) {
311+
assertFalse(NetUtils.validateGuestCidr(cidr));
312+
}
307313
}
308314

309315
@Test

0 commit comments

Comments
 (0)