Skip to content

Commit 980be4d

Browse files
jayapaluRohit Yadav
authored andcommitted
CLOUDSTACK-9757: Fixed issue in traffic from additional public subnet
(cherry picked from commit baac747) Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent a24dfe6 commit 980be4d

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

server/src/com/cloud/network/router/CommandSetupHelper.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,19 +668,38 @@ public void createVpcAssociatePublicIPCommands(final VirtualRouter router, final
668668
for (final Map.Entry<String, ArrayList<PublicIpAddress>> vlanAndIp : vlanIpMap.entrySet()) {
669669
final List<PublicIpAddress> ipAddrList = vlanAndIp.getValue();
670670

671+
// Source nat ip address should always be sent first
672+
Collections.sort(ipAddrList, new Comparator<PublicIpAddress>() {
673+
@Override
674+
public int compare(final PublicIpAddress o1, final PublicIpAddress o2) {
675+
final boolean s1 = o1.isSourceNat();
676+
final boolean s2 = o2.isSourceNat();
677+
return s1 ^ s2 ? s1 ^ true ? 1 : -1 : 0;
678+
}
679+
});
680+
681+
671682
// Get network rate - required for IpAssoc
672683
final Integer networkRate = _networkModel.getNetworkRate(ipAddrList.get(0).getNetworkId(), router.getId());
673684
final Network network = _networkModel.getNetwork(ipAddrList.get(0).getNetworkId());
674685

675686
final IpAddressTO[] ipsToSend = new IpAddressTO[ipAddrList.size()];
676687
int i = 0;
688+
boolean firstIP = true;
677689

678690
for (final PublicIpAddress ipAddr : ipAddrList) {
679691
final boolean add = ipAddr.getState() == IpAddress.State.Releasing ? false : true;
692+
boolean sourceNat = ipAddr.isSourceNat();
693+
/* enable sourceNAT for the first ip of the public interface
694+
* For additional public subnet source nat rule needs to be added for vm to reach ips in that subnet
695+
*/
696+
if (firstIP) {
697+
sourceNat = true;
698+
}
680699

681700
final String macAddress = vlanMacAddress.get(BroadcastDomainType.getValue(BroadcastDomainType.fromString(ipAddr.getVlanTag())));
682701

683-
final IpAddressTO ip = new IpAddressTO(ipAddr.getAccountId(), ipAddr.getAddress().addr(), add, false, ipAddr.isSourceNat(), BroadcastDomainType.fromString(ipAddr.getVlanTag()).toString(), ipAddr.getGateway(),
702+
final IpAddressTO ip = new IpAddressTO(ipAddr.getAccountId(), ipAddr.getAddress().addr(), add, firstIP, sourceNat, BroadcastDomainType.fromString(ipAddr.getVlanTag()).toString(), ipAddr.getGateway(),
684703
ipAddr.getNetmask(), macAddress, networkRate, ipAddr.isOneToOneNat());
685704

686705
ip.setTrafficType(network.getTrafficType());
@@ -690,6 +709,12 @@ public void createVpcAssociatePublicIPCommands(final VirtualRouter router, final
690709
sourceNatIpAdd = new Pair<IpAddressTO, Long>(ip, ipAddr.getNetworkId());
691710
addSourceNat = add;
692711
}
712+
713+
//for additional public subnet on delete it is not sure which ip is set to first ip. So on delete we
714+
//want to set sourcenat to true for all ips to delete source nat rules.
715+
if (!firstIP || add) {
716+
firstIP = false;
717+
}
693718
}
694719
final IpAssocVpcCommand cmd = new IpAssocVpcCommand(ipsToSend);
695720
cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));

systemvm/patches/debian/config/opt/cloud/bin/cs/CsAddress.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ def post_config_change(self, method):
571571
if self.get_type() in ["guest"] and not cmdline.is_redundant():
572572
pwdsvc = CsPasswdSvc(self.address['public_ip']).start()
573573

574-
if self.get_type() == "public" and self.config.is_vpc():
574+
if self.get_type() == "public" and self.config.is_vpc() and method == "add":
575575
if self.address["source_nat"]:
576576
vpccidr = cmdline.get_vpccidr()
577577
self.fw.append(

0 commit comments

Comments
 (0)