Skip to content

Commit fe11fa8

Browse files
CLOUDSTACK-5687 [Hyper-V] Remote Access VPN fails with Unsupported command while trying to configure VPN users
1 parent 6ba9754 commit fe11fa8

1 file changed

Lines changed: 92 additions & 1 deletion

File tree

plugins/hypervisors/hyperv/src/com/cloud/hypervisor/hyperv/resource/HypervDirectConnectResource.java

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.net.URISyntaxException;
2525
import java.net.URL;
2626
import java.nio.channels.SocketChannel;
27+
import java.rmi.RemoteException;
2728
import java.util.HashMap;
2829
import java.util.List;
2930
import java.util.Map;
@@ -77,6 +78,7 @@
7778
import com.cloud.agent.api.routing.IpAssocCommand;
7879
import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
7980
import com.cloud.agent.api.routing.NetworkElementCommand;
81+
import com.cloud.agent.api.routing.RemoteAccessVpnCfgCommand;
8082
import com.cloud.agent.api.routing.SavePasswordCommand;
8183
import com.cloud.agent.api.routing.SetFirewallRulesAnswer;
8284
import com.cloud.agent.api.routing.SetFirewallRulesCommand;
@@ -91,6 +93,7 @@
9193
import com.cloud.agent.api.routing.SetStaticRouteCommand;
9294
import com.cloud.agent.api.routing.Site2SiteVpnCfgCommand;
9395
import com.cloud.agent.api.routing.VmDataCommand;
96+
import com.cloud.agent.api.routing.VpnUsersCfgCommand;
9497
import com.cloud.agent.api.to.DhcpTO;
9598
import com.cloud.agent.api.to.FirewallRuleTO;
9699
import com.cloud.agent.api.to.IpAddressTO;
@@ -381,7 +384,11 @@ public final Answer executeRequest(final Command cmd) {
381384
} else if (clazz == Site2SiteVpnCfgCommand.class) {
382385
answer = execute((Site2SiteVpnCfgCommand)cmd);
383386
} else if (clazz == CheckS2SVpnConnectionsCommand.class) {
384-
answer = execute((CheckS2SVpnConnectionsCommand)cmd);
387+
answer = execute((CheckS2SVpnConnectionsCommand) cmd);
388+
} else if (clazz == RemoteAccessVpnCfgCommand.class) {
389+
answer = execute((RemoteAccessVpnCfgCommand) cmd);
390+
} else if (clazz == VpnUsersCfgCommand.class) {
391+
answer = execute((VpnUsersCfgCommand) cmd);
385392
} else if (clazz == SetStaticRouteCommand.class) {
386393
answer = execute((SetStaticRouteCommand) cmd);
387394
} else if (clazz == SetMonitorServiceCommand.class) {
@@ -416,7 +423,91 @@ public final Answer executeRequest(final Command cmd) {
416423
}
417424
return answer;
418425
}
426+
427+
protected Answer execute(final RemoteAccessVpnCfgCommand cmd) {
428+
String controlIp = getRouterSshControlIp(cmd);
429+
StringBuffer argsBuf = new StringBuffer();
430+
if (cmd.isCreate()) {
431+
argsBuf.append(" -r ").append(cmd.getIpRange()).append(" -p ").append(cmd.getPresharedKey()).append(" -s ").append(cmd.getVpnServerIp()).append(" -l ").append(cmd.getLocalIp())
432+
.append(" -c ");
433+
434+
} else {
435+
argsBuf.append(" -d ").append(" -s ").append(cmd.getVpnServerIp());
436+
}
437+
argsBuf.append(" -C ").append(cmd.getLocalCidr());
438+
argsBuf.append(" -i ").append(cmd.getPublicInterface());
439+
440+
try {
441+
442+
if (s_logger.isDebugEnabled()) {
443+
s_logger.debug("Executing /opt/cloud/bin/vpn_lt2p.sh ");
444+
}
445+
446+
Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/opt/cloud/bin/vpn_l2tp.sh " + argsBuf.toString());
447+
448+
if (!result.first()) {
449+
s_logger.error("RemoteAccessVpnCfg command on domR failed, message: " + result.second());
450+
451+
return new Answer(cmd, false, "RemoteAccessVpnCfg command failed due to " + result.second());
452+
}
453+
454+
if (s_logger.isInfoEnabled()) {
455+
s_logger.info("RemoteAccessVpnCfg command on domain router " + argsBuf.toString() + " completed");
456+
}
457+
458+
} catch (Throwable e) {
459+
if (e instanceof RemoteException) {
460+
s_logger.warn(e.getMessage());
461+
}
462+
463+
String msg = "RemoteAccessVpnCfg command failed due to " + e.getMessage();
464+
s_logger.error(msg, e);
465+
return new Answer(cmd, false, msg);
466+
}
467+
468+
return new Answer(cmd);
469+
}
470+
471+
protected Answer execute(final VpnUsersCfgCommand cmd) {
472+
473+
String controlIp = getRouterSshControlIp(cmd);
474+
for (VpnUsersCfgCommand.UsernamePassword userpwd : cmd.getUserpwds()) {
475+
StringBuffer argsBuf = new StringBuffer();
476+
if (!userpwd.isAdd()) {
477+
argsBuf.append(" -U ").append(userpwd.getUsername());
478+
} else {
479+
argsBuf.append(" -u ").append(userpwd.getUsernamePassword());
480+
}
481+
482+
try {
483+
484+
if (s_logger.isDebugEnabled()) {
485+
s_logger.debug("Executing /opt/cloud/bin/vpn_lt2p.sh ");
486+
}
487+
488+
Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/opt/cloud/bin/vpn_l2tp.sh " + argsBuf.toString());
489+
490+
if (!result.first()) {
491+
s_logger.error("VpnUserCfg command on domR failed, message: " + result.second());
492+
493+
return new Answer(cmd, false, "VpnUserCfg command failed due to " + result.second());
494+
}
495+
} catch (Throwable e) {
496+
if (e instanceof RemoteException) {
497+
s_logger.warn(e.getMessage());
498+
}
499+
500+
String msg = "VpnUserCfg command failed due to " + e.getMessage();
501+
s_logger.error(msg, e);
502+
return new Answer(cmd, false, msg);
503+
}
504+
}
505+
506+
return new Answer(cmd);
507+
}
419508

509+
510+
420511
private SetStaticRouteAnswer execute(SetStaticRouteCommand cmd) {
421512
if (s_logger.isInfoEnabled()) {
422513
s_logger.info("Executing resource SetStaticRouteCommand: " + s_gson.toJson(cmd));

0 commit comments

Comments
 (0)