Skip to content

Commit 0e4dde9

Browse files
Netris FR1b: Support Remote Access VPN and Site-to-Site VPN in VPC VR (#41)
* Static Routes: support nexthop * Update api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateStaticRouteCmd.java Co-authored-by: Pearl Dsilva <[email protected]> * PR#10064 VR: apply iptables rules when add/remove static routes * PR#10065 UI: fix cannot open 'Edit tags' modal for static routes * PR#10066 Static Routes: fix check on wrong global configuration * PR#10067 VR: fix site-2-site VPN if split connections is enabled * PR#10081 server: do not allocate nic on public network for NSX VPC VR * PR#10082 UI: create VPC network offering with conserve mode * PR#10083 VR: allow outgoing traffic from RAS/VPN clients * PR#10086 server: fix typo removeaccessvpn in VirtualRouterElement * server: Add check on Public IP for remote access VPN * Revert "PR#10083 VR: allow outgoing traffic from RAS/VPN clients" This reverts commit 2f9b9f428947cac91de322fbdf4a980902a1c0a0. * VPC: fetch same used IP for domain router if VR is not Source NAT * VR: pass has_public_network to VR and configure RA/S2S VPN left peers * Revert "PR#10081 server: do not allocate nic on public network for NSX VPC VR" This reverts commit 809e269ed6b361d9df1fcef6537762c5612863e0. * VPC: fetch same used IP for domain router if VR is not Source NAT (v2) * VR: fix /etc/hosts and nameservers in dnsmasq.conf if VPC VR is not guest gateway prior to this PR ``` root@r-1167-VM:~# cat /etc/hosts 127.0.0.1 localhost 127.0.1.1 r-1167-VM ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters 172.21.1.33 dummy-vpc-vpn-001 172.21.1.1 r-1167-VM data-server root@r-1167-VM:~# cat /etc/dnsmasq.d/cloud.conf dhcp-hostsfile=/etc/dhcphosts.txt listen-address=127.0.0.1,172.21.1.234 dhcp-range=set:interface-eth1-0,172.21.1.234,static dhcp-option=tag:interface-eth1-0,15,cs2cloud.internal dhcp-option=tag:interface-eth1-0,6,172.21.1.1,10.0.32.1,8.8.8.8 dhcp-option=tag:interface-eth1-0,3,172.21.1.1 dhcp-option=eth1,26,1500 dhcp-option=tag:interface-eth1-0,1,255.255.255.0 ``` the lines should be ``` 172.21.1.234 r-1167-VM data-server dhcp-option=tag:interface-eth1-0,6,10.0.32.1,8.8.8.8 ``` * server: Enable static NAT for Domain router if it is not Source NAT * server: Enable static NAT for Domain router on UI * server: assign Public IP to VPC VR and enable static nat if VR is not Source NAT * server: configure dns1 if VR is not Source NAT * server: remove check on Firewall service when list network service providers * UI: remove dot from message.enabled.vpn * systemvm: add default route via first guest gateway if VR does not have public IP/interface * VR: add fw_dhcpserver for shared network * VR: pass has_public_network to VR and configure RA/S2S VPN left peers (v2) * UI: fix request error when create a VPC tier in a non-Netris/NSX env * systemvm: add default route via first guest gateway (v2) * VR: configure iptables rules for S2S vpn on first guest interface * VR: allow FORWARD to guest interfaces if VR is not Public * VR: configure remote access vpn on first guest interface if not public * VR: fix error 789 in RA VPN client when both RA and S2S are configured * server: Apply Static Route for RA/S2S VPN in VPC VR * VR: do not set mark for Public interface when VR is not really public * VPN: do not disable static nat if it is used by a RA/S2S VPN * server: skip check on network conserve mode if disable/enable RA VPN on Router IP * server: set forRouter to false when release a IP * VR: diable IP spoofing protection on default guest network * VR: fix iptables rules only when only S2S vpn is enabled * UI: show 'VPN Connections' section * VPC: new methods to configure/reconfigure Static NAT for VPC VR * API: set Type in ip address response to DomainRouter if it is used by VR * server: do not allow IP release if it is used by RA or S2S VPN gateway * VR: check if interface is added * VR: add default route only when ip is associated to first guest interface * VR: fix ipsec conf for l2tp and s2s vpn * server: save placeholder IP for VPC VR to fix the new VR IP when vpc tier is auto-shutdown * server: get non-placeholder NIC for VPC VR * VR: wait 15 seconds after starting password server * server: fix unable to configure static nat due to 'invalid virtual machine id' * UI: fix link of router in info card * VPC: apply static route for VPC VPN if needed (refactoring) * server: fix VR IP of first VPC tier is the VM gateway * server: update or remove all existing static routes when shutdown a network * server: update ipaddress after disabling static nat to fix vpc deletion issue * servr: disable remote access VPN as part of VPC dstroy * server: apply static routes when implement a vpc tier * server: apply static routes even if next hop is null * server: fix Cannot invoke "com.cloud.vm.NicProfile.getRequestedIPv4()" because "requested" is null * Netris: Update Vpn provider to VpcVirtualRouter * Netris: Add Vpn service to network offerings and networks * server: fix CIDR of VPN ip range * server: set isVrGuestGateway by SoureNat/Gateway service with Provider.VPCVirtualRouter * VR: password server takes 10-15 seconds to start if VR IP is not configured in /etc/hosts * Netris: add back routesPutBody.setStateStatus * engine/schema: remove SQL changes in schema-41910to42000.sql --------- Co-authored-by: Pearl Dsilva <[email protected]>
1 parent 465965a commit 0e4dde9

File tree

54 files changed

+1144
-184
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1144
-184
lines changed

api/src/main/java/com/cloud/network/IpAddress.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,5 @@ enum Purpose {
9999

100100
boolean isForSystemVms();
101101

102+
boolean isForRouter();
102103
}

api/src/main/java/com/cloud/network/Site2SiteVpnConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
public interface Site2SiteVpnConnection extends ControlledEntity, InternalIdentity, Displayable {
2626
enum State {
27-
Pending, Connecting, Connected, Disconnected, Error,
27+
Pending, Connecting, Connected, Disconnected, Error, Removed
2828
}
2929

3030
@Override

api/src/main/java/com/cloud/network/vpc/StaticRoute.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ enum State {
3333
/**
3434
* @return
3535
*/
36-
long getVpcGatewayId();
36+
Long getVpcGatewayId();
37+
38+
String getNextHop();
3739

3840
/**
3941
* @return

api/src/main/java/com/cloud/network/vpc/StaticRouteProfile.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public class StaticRouteProfile implements StaticRoute {
2323
private String targetCidr;
2424
private long accountId;
2525
private long domainId;
26-
private long gatewayId;
26+
private Long gatewayId;
27+
private String nextHop;
2728
private StaticRoute.State state;
2829
private long vpcId;
2930
String vlanTag;
@@ -46,6 +47,18 @@ public StaticRouteProfile(StaticRoute staticRoute, VpcGateway gateway) {
4647
ipAddress = gateway.getIp4Address();
4748
}
4849

50+
public StaticRouteProfile(StaticRoute staticRoute) {
51+
id = staticRoute.getId();
52+
uuid = staticRoute.getUuid();
53+
targetCidr = staticRoute.getCidr();
54+
accountId = staticRoute.getAccountId();
55+
domainId = staticRoute.getDomainId();
56+
gatewayId = staticRoute.getVpcGatewayId();
57+
state = staticRoute.getState();
58+
vpcId = staticRoute.getVpcId();
59+
gateway = staticRoute.getNextHop();
60+
}
61+
4962
@Override
5063
public long getAccountId() {
5164
return accountId;
@@ -57,10 +70,15 @@ public long getDomainId() {
5770
}
5871

5972
@Override
60-
public long getVpcGatewayId() {
73+
public Long getVpcGatewayId() {
6174
return gatewayId;
6275
}
6376

77+
@Override
78+
public String getNextHop() {
79+
return nextHop;
80+
}
81+
6482
@Override
6583
public String getCidr() {
6684
return targetCidr;

api/src/main/java/com/cloud/network/vpc/VpcService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ Pair<List<? extends Vpc>, Integer> listVpcs(Long id, String vpcName, String disp
238238
* @param cidr
239239
* @return
240240
*/
241-
StaticRoute createStaticRoute(long gatewayId, String cidr) throws NetworkRuleConflictException;
241+
StaticRoute createStaticRoute(Long gatewayId, Long vpcId, String nextHop, String cidr) throws NetworkRuleConflictException;
242242

243243
/**
244244
* Lists static routes based on parameters passed to the call

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ public class ApiConstants {
257257
public static final String PREVIOUS_OWNER_ID = "previousownerid";
258258
public static final String PREVIOUS_OWNER_NAME = "previousownername";
259259
public static final String NEXT_ACL_RULE_ID = "nextaclruleid";
260+
public static final String NEXT_HOP = "nexthop";
260261
public static final String MOVE_ACL_CONSISTENCY_HASH = "aclconsistencyhash";
261262
public static final String IMAGE_PATH = "imagepath";
262263
public static final String INSTANCE_CONVERSION_SUPPORTED = "instanceconversionsupported";
@@ -876,6 +877,8 @@ public class ApiConstants {
876877
public static final String NETWORK = "network";
877878
public static final String VPC_ID = "vpcid";
878879
public static final String VPC_NAME = "vpcname";
880+
public static final String VPC_GATEWAY_ID = "vpcgatewayid";
881+
public static final String VPC_GATEWAY_IP = "vpcgatewayip";
879882
public static final String GATEWAY_ID = "gatewayid";
880883
public static final String CAN_USE_FOR_DEPLOY = "canusefordeploy";
881884
public static final String RESOURCE_IDS = "resourceids";

api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateStaticRouteCmd.java

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.cloudstack.api.ServerApiException;
2828
import org.apache.cloudstack.api.response.PrivateGatewayResponse;
2929
import org.apache.cloudstack.api.response.StaticRouteResponse;
30+
import org.apache.cloudstack.api.response.VpcResponse;
3031
import org.apache.cloudstack.context.CallContext;
3132

3233
import com.cloud.event.EventTypes;
@@ -45,20 +46,38 @@ public class CreateStaticRouteCmd extends BaseAsyncCreateCmd {
4546
@Parameter(name = ApiConstants.GATEWAY_ID,
4647
type = CommandType.UUID,
4748
entityType = PrivateGatewayResponse.class,
48-
required = true,
49-
description = "the gateway id we are creating static route for")
49+
description = "the gateway id we are creating static route for. Mutually exclusive with the nexthop parameter")
5050
private Long gatewayId;
5151

52+
@Parameter(name = ApiConstants.VPC_ID,
53+
type = CommandType.UUID,
54+
entityType = VpcResponse.class,
55+
description = "the vpc id for which the static route is created. This is required for nexthop parameter")
56+
private Long vpcId;
57+
58+
@Parameter(name = ApiConstants.NEXT_HOP,
59+
type = CommandType.STRING,
60+
description = "the next hop of static route. Mutually exclusive with the gatewayid parameter")
61+
private String nextHop;
62+
5263
@Parameter(name = ApiConstants.CIDR, required = true, type = CommandType.STRING, description = "static route cidr")
5364
private String cidr;
5465

5566
/////////////////////////////////////////////////////
5667
/////////////////// Accessors ///////////////////////
5768
/////////////////////////////////////////////////////
58-
public long getGatewayId() {
69+
public Long getGatewayId() {
5970
return gatewayId;
6071
}
6172

73+
public Long getVpcId() {
74+
return vpcId;
75+
}
76+
77+
public String getNextHop() {
78+
return nextHop;
79+
}
80+
6281
public String getCidr() {
6382
return cidr;
6483
}
@@ -69,7 +88,7 @@ public String getCidr() {
6988
@Override
7089
public void create() throws ResourceAllocationException {
7190
try {
72-
StaticRoute result = _vpcService.createStaticRoute(getGatewayId(), getCidr());
91+
StaticRoute result = _vpcService.createStaticRoute(getGatewayId(), getVpcId(), getNextHop(), getCidr());
7392
setEntityId(result.getId());
7493
setEntityUuid(result.getUuid());
7594
} catch (NetworkRuleConflictException ex) {
@@ -114,11 +133,8 @@ public void execute() throws ResourceUnavailableException {
114133

115134
@Override
116135
public long getEntityOwnerId() {
117-
VpcGateway gateway = _entityMgr.findById(VpcGateway.class, gatewayId);
118-
if (gateway == null) {
119-
throw new InvalidParameterValueException("Invalid gateway id is specified");
120-
}
121-
return _entityMgr.findById(Vpc.class, gateway.getVpcId()).getAccountId();
136+
Long vpcId = getSyncObjId();
137+
return _entityMgr.findById(Vpc.class, vpcId).getAccountId();
122138
}
123139

124140
@Override
@@ -128,11 +144,20 @@ public String getSyncObjType() {
128144

129145
@Override
130146
public Long getSyncObjId() {
131-
VpcGateway gateway = _entityMgr.findById(VpcGateway.class, gatewayId);
132-
if (gateway == null) {
133-
throw new InvalidParameterValueException("Invalid id is specified for the gateway");
147+
if (gatewayId != null) {
148+
VpcGateway gateway = _entityMgr.findById(VpcGateway.class, gatewayId);
149+
if (gateway == null) {
150+
throw new InvalidParameterValueException("Invalid id is specified for the gateway");
151+
}
152+
return gateway.getVpcId();
153+
} else if (vpcId != null) {
154+
Vpc vpc = _entityMgr.findById(Vpc.class, vpcId);
155+
if (vpc == null) {
156+
throw new InvalidParameterValueException("Invalid vpc id is specified");
157+
}
158+
return vpc.getId();
134159
}
135-
return gateway.getVpcId();
160+
throw new InvalidParameterValueException("One of vpcId or gatewayId must be specified");
136161
}
137162

138163
@Override

api/src/main/java/org/apache/cloudstack/api/response/StaticRouteResponse.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,17 @@ public class StaticRouteResponse extends BaseResponse implements ControlledEntit
4242
@Param(description = "VPC the static route belongs to")
4343
private String vpcId;
4444

45-
@SerializedName(ApiConstants.GATEWAY_ID)
45+
@SerializedName(ApiConstants.VPC_GATEWAY_ID)
4646
@Param(description = "VPC gateway the route is created for")
47-
private String gatewayId;
47+
private String vpcGatewayId;
48+
49+
@SerializedName(ApiConstants.VPC_GATEWAY_IP)
50+
@Param(description = "IP of VPC gateway the route is created for")
51+
private String vpcGatewayIp;
52+
53+
@SerializedName(ApiConstants.NEXT_HOP)
54+
@Param(description = "Next hop of the static route")
55+
private String nextHop;
4856

4957
@SerializedName(ApiConstants.CIDR)
5058
@Param(description = "static route CIDR")
@@ -95,8 +103,16 @@ public void setVpcId(String vpcId) {
95103
this.vpcId = vpcId;
96104
}
97105

98-
public void setGatewayId(String gatewayId) {
99-
this.gatewayId = gatewayId;
106+
public void setVpcGatewayId(String vpcGatewayId) {
107+
this.vpcGatewayId = vpcGatewayId;
108+
}
109+
110+
public void setVpcGatewayIp(String vpcGatewayIp) {
111+
this.vpcGatewayIp = vpcGatewayIp;
112+
}
113+
114+
public void setNextHop(String nextHop) {
115+
this.nextHop = nextHop;
100116
}
101117

102118
public void setCidr(String cidr) {

engine/components-api/src/main/java/com/cloud/network/addr/PublicIp.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,5 +275,9 @@ public boolean isForSystemVms() {
275275
return false;
276276
}
277277

278+
@Override
279+
public boolean isForRouter() {
280+
return _addr.isForRouter();
281+
}
278282

279283
}

engine/components-api/src/main/java/com/cloud/network/rules/RulesManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ FirewallRule[] reservePorts(IpAddress ip, String protocol, FirewallRule.Purpose
5454

5555
boolean disableStaticNat(long ipAddressId, Account caller, long callerUserId, boolean releaseIpIfElastic) throws ResourceUnavailableException;
5656

57+
boolean applyStaticNatForIp(long sourceIpId, boolean continueOnError, Account caller, boolean forRevoke);
58+
5759
/**
5860
* @param networkId
5961
* @param continueOnError

0 commit comments

Comments
 (0)