CLOUDSTACK-9853: Add support for Secondary IPv6 Addresses and Subnets (#2028)

This commit adds support for passing IPv6 Addresses and/or Subnets as
Secondary IPs.

This is groundwork for CLOUDSTACK-9853 where IPv6 Subnets have to be
allowed in the Security Groups of Instances to we can add DHCPv6
Prefix Delegation.

Use ; instead of : for separating addresses, otherwise it would cause
problems with IPv6 Addresses.

Signed-off-by: Wido den Hollander <wido@widodh.nl>
This commit is contained in:
Wido den Hollander 2017-11-22 13:00:33 +01:00 committed by Rohit Yadav
parent 421517f949
commit 632479d8f8
9 changed files with 29 additions and 10 deletions

View File

@ -34,6 +34,8 @@ public interface NicSecondaryIp extends ControlledEntity, Identity, InternalIden
String getIp4Address();
String getIp6Address();
long getNetworkId();
long getVmId();

View File

@ -35,7 +35,7 @@ import com.cloud.utils.net.NetUtils;
public class SecurityGroupRulesCmd extends Command {
private static final String CIDR_LENGTH_SEPARATOR = "/";
private static final char RULE_TARGET_SEPARATOR = ',';
private static final char RULE_COMMAND_SEPARATOR = ':';
private static final char RULE_COMMAND_SEPARATOR = ';';
protected static final String EGRESS_RULE = "E:";
protected static final String INGRESS_RULE = "I:";
private static final Logger LOGGER = Logger.getLogger(SecurityGroupRulesCmd.class);

View File

@ -86,7 +86,7 @@ public class SecurityGroupRulesCmdTest {
*/
@Test
public void testCompressStringifiedRules() throws Exception {
final String compressed = "eJzztEpMSrYytDKyMtQz0jPWM9E31THTM9ez0LPUN9Dxc40IUXAlrAQAPdoP3Q==";
final String compressed = "eJzztEpMSrY2tDayNtQz0jPWM9E31THTM9ez0LPUN9Dxc40IUXAlrAQAPusP4w==";
final String a = securityGroupRulesCmd.compressStringifiedRules();
assertTrue(compressed.equals(a));
}

View File

@ -20,6 +20,7 @@ import java.util.ArrayList;
import java.util.List;
import com.cloud.utils.StringUtils;
import org.springframework.stereotype.Component;
import com.cloud.utils.db.GenericDaoBase;
@ -106,7 +107,13 @@ public class NicSecondaryIpDaoImpl extends GenericDaoBase<NicSecondaryIpVO, Long
List<NicSecondaryIpVO> results = search(sc, null);
List<String> ips = new ArrayList<String>(results.size());
for (NicSecondaryIpVO result : results) {
ips.add(result.getIp4Address());
if (StringUtils.isNotBlank(result.getIp4Address())) {
ips.add(result.getIp4Address());
}
if (StringUtils.isNotBlank(result.getIp6Address())) {
ips.add(result.getIp6Address());
}
}
return ips;
}

View File

@ -42,6 +42,16 @@ public class NicSecondaryIpVO implements NicSecondaryIp {
this.networkId = networkId;
}
public NicSecondaryIpVO(long nicId, String ip4Address, String ip6Address, long vmId, long accountId, long domainId, long networkId) {
this.nicId = nicId;
this.vmId = vmId;
this.ip4Address = ip4Address;
this.ip6Address = ip6Address;
this.accountId = accountId;
this.domainId = domainId;
this.networkId = networkId;
}
protected NicSecondaryIpVO() {
}

View File

@ -102,11 +102,11 @@ public final class LibvirtStartCommandWrapper extends CommandWrapper<StartComman
final StringBuilder sb = new StringBuilder();
if (nicSecIps != null) {
for (final String ip : nicSecIps) {
sb.append(ip).append(":");
sb.append(ip).append(";");
}
secIpsStr = sb.toString();
} else {
secIpsStr = "0:";
secIpsStr = "0;";
}
libvirtComputingResource.defaultNetworkRules(conn, vmName, nic, vmSpec.getId(), secIpsStr);
}

View File

@ -178,11 +178,11 @@ public final class CitrixStartCommandWrapper extends CommandWrapper<StartCommand
final StringBuilder sb = new StringBuilder();
if (nicSecIps != null) {
for (final String ip : nicSecIps) {
sb.append(ip).append(":");
sb.append(ip).append(";");
}
secIpsStr = sb.toString();
} else {
secIpsStr = "0:";
secIpsStr = "0;";
}
result = citrixResourceBase.callHostPlugin(conn, "vmops", "default_network_rules", "vmName", vmName, "vmIP", nic.getIp(), "vmMAC", nic.getMac(),
"vmID", Long.toString(vmSpec.getId()), "secIps", secIpsStr);
@ -221,4 +221,4 @@ public final class CitrixStartCommandWrapper extends CommandWrapper<StartCommand
}
}
}
}
}

View File

@ -826,7 +826,7 @@ def default_network_rules(session, args):
#add secodnary nic ips to ipset
secIpSet = "1"
ips = sec_ips.split(':')
ips = sec_ips.split(';')
ips.pop()
if ips[0] == "0":
secIpSet = "0";

View File

@ -485,7 +485,7 @@ def default_network_rules(vm_name, vm_id, vm_ip, vm_ip6, vm_mac, vif, brname, se
#add secodnary nic ips to ipset
secIpSet = "1"
ips = sec_ips.split(':')
ips = sec_ips.split(';')
ips.pop()
if ips[0] == "0":
secIpSet = "0";