Skip to content

Commit 972fe01

Browse files
author
Alena Prokharchyk
committed
VPC: more validation for static route rules: 1) Can't belong to guest cidr defined on Vpc 2) Can't belong to link local cidr
Conflicts: server/src/com/cloud/network/vpc/VpcManagerImpl.java
1 parent 435480c commit 972fe01

3 files changed

Lines changed: 26 additions & 9 deletions

File tree

‎api/src/com/cloud/api/commands/CreateVPCCmd.java‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd{
5252
"If used with the account parameter returns the VPC associated with the account for the specified domain.")
5353
private Long domainId;
5454

55+
@IdentityMapper(entityTableName="projects")
56+
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="create VPC for the project")
57+
private Long projectId;
58+
5559
@IdentityMapper(entityTableName="data_center")
5660
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="the ID of the availability zone")
5761
private Long zoneId;
@@ -72,7 +76,8 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd{
7276
@Parameter(name=ApiConstants.VPC_OFF_ID, type=CommandType.LONG, required=true, description="the ID of the VPC offering")
7377
private Long vpcOffering;
7478

75-
@Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="network domain")
79+
@Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING,
80+
description="VPC network domain. All networks inside the VPC will belong to this domain")
7681
private String networkDomain;
7782

7883
/////////////////////////////////////////////////////
@@ -174,7 +179,7 @@ public String getCommandName() {
174179

175180
@Override
176181
public long getEntityOwnerId() {
177-
Long accountId = finalyzeAccountId(accountName, domainId, null, true);
182+
Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
178183
if (accountId == null) {
179184
return UserContext.current().getCaller().getId();
180185
}

‎api/src/com/cloud/api/response/VpcResponse.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ public class VpcResponse extends BaseResponse implements ControlledEntityRespons
7474
@SerializedName(ApiConstants.NETWORK) @Param(description="the list of networks belongign to the VPC", responseObject = NetworkResponse.class)
7575
private List<NetworkResponse> networks;
7676

77-
@SerializedName(ApiConstants.RESTART_REQUIRED) @Param(description="true network requires restart")
77+
@SerializedName(ApiConstants.RESTART_REQUIRED) @Param(description="true VPC requires restart")
7878
private Boolean restartRequired;
7979

80-
@SerializedName(ApiConstants.NETWORK_DOMAIN) @Param(description="the network domain")
80+
@SerializedName(ApiConstants.NETWORK_DOMAIN) @Param(description="the network domain of the VPC")
8181
private String networkDomain;
8282

8383
@SerializedName(ApiConstants.TAGS) @Param(description="the list of resource tags associated with the project", responseObject = ResourceTagResponse.class)

‎server/src/com/cloud/network/vpc/VpcManagerImpl.java‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,11 +1376,12 @@ public List<PrivateGateway> listPrivateGateway(ListPrivateGatewaysCmd cmd) {
13761376
Account caller = UserContext.current().getCaller();
13771377
List<Long> permittedAccounts = new ArrayList<Long>();
13781378
String state = cmd.getState();
1379-
1379+
Long projectId = cmd.getProjectId();
1380+
13801381
Filter searchFilter = new Filter(VpcGatewayVO.class, "id", false, cmd.getStartIndex(), cmd.getPageSizeVal());
13811382
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean,
13821383
ListProjectResourcesCriteria>(domainId, isRecursive, null);
1383-
_accountMgr.buildACLSearchParameters(caller, null, accountName, null, permittedAccounts, domainIdRecursiveListProject,
1384+
_accountMgr.buildACLSearchParameters(caller, id, accountName, projectId, permittedAccounts, domainIdRecursiveListProject,
13841385
listAll, false);
13851386
domainId = domainIdRecursiveListProject.first();
13861387
isRecursive = domainIdRecursiveListProject.second();
@@ -1553,7 +1554,17 @@ public StaticRoute createStaticRoute(long gatewayId, String cidr) throws Network
15531554
throw new InvalidParameterValueException("Invalid format for cidr " + cidr);
15541555
}
15551556

1556-
//TODO - check cidr for the conflicts
1557+
//validate the cidr
1558+
//1) CIDR should be outside of VPC cidr for guest networks
1559+
if (NetUtils.isNetworksOverlap(vpc.getCidr(), cidr)) {
1560+
throw new InvalidParameterValueException("CIDR should be outside of VPC cidr " + vpc.getCidr());
1561+
}
1562+
1563+
//2) CIDR should be outside of link-local cidr
1564+
if (NetUtils.isNetworksOverlap(vpc.getCidr(), NetUtils.getLinkLocalCIDR())) {
1565+
throw new InvalidParameterValueException("CIDR should be outside of link local cidr " + NetUtils.getLinkLocalCIDR());
1566+
}
1567+
15571568
Transaction txn = Transaction.currentTxn();
15581569
txn.start();
15591570

@@ -1585,10 +1596,11 @@ public List<? extends StaticRoute> listStaticRoutes(ListStaticRoutesCmd cmd) {
15851596
Account caller = UserContext.current().getCaller();
15861597
List<Long> permittedAccounts = new ArrayList<Long>();
15871598
Map<String, String> tags = cmd.getTags();
1588-
1599+
Long projectId = cmd.getProjectId();
1600+
15891601
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean,
15901602
ListProjectResourcesCriteria>(domainId, isRecursive, null);
1591-
_accountMgr.buildACLSearchParameters(caller, id, accountName, null, permittedAccounts, domainIdRecursiveListProject,
1603+
_accountMgr.buildACLSearchParameters(caller, id, accountName, projectId, permittedAccounts, domainIdRecursiveListProject,
15921604
listAll, false);
15931605
domainId = domainIdRecursiveListProject.first();
15941606
isRecursive = domainIdRecursiveListProject.second();

0 commit comments

Comments
 (0)