Skip to content

Commit e47a910

Browse files
VR: fix issue between VPC VMs and other Public IPs in the same subnet as additional Public IPs (#8599)
* VR: fix issue between VPC VMs and other Public IPs in the same subnet as additional Public IPs * Update PR8599: move to VpcVirtualNetworkApplianceManagerImpl
1 parent 672206c commit e47a910

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

server/src/main/java/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import javax.inject.Inject;
2828
import javax.naming.ConfigurationException;
2929

30+
import org.apache.commons.collections.CollectionUtils;
3031
import org.apache.log4j.Logger;
3132
import org.springframework.stereotype.Component;
3233

@@ -294,7 +295,23 @@ public boolean finalizeVirtualMachineProfile(final VirtualMachineProfile profile
294295
}
295296
}
296297

297-
return super.finalizeVirtualMachineProfile(profile, dest, context);
298+
super.finalizeVirtualMachineProfile(profile, dest, context);
299+
appendSourceNatIpToBootArgs(profile);
300+
return true;
301+
}
302+
303+
private void appendSourceNatIpToBootArgs(final VirtualMachineProfile profile) {
304+
final StringBuilder buf = profile.getBootArgsBuilder();
305+
final DomainRouterVO router = _routerDao.findById(profile.getVirtualMachine().getId());
306+
if (router != null && router.getVpcId() != null) {
307+
List<IPAddressVO> vpcIps = _ipAddressDao.listByAssociatedVpc(router.getVpcId(), true);
308+
if (CollectionUtils.isNotEmpty(vpcIps)) {
309+
buf.append(String.format(" source_nat_ip=%s", vpcIps.get(0).getAddress().toString()));
310+
if (s_logger.isDebugEnabled()) {
311+
s_logger.debug("The final Boot Args for " + profile + ": " + buf);
312+
}
313+
}
314+
}
298315
}
299316

300317
@Override

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,8 @@ def fw_router(self):
453453
["", "", "-A NETWORK_STATS_%s -o %s ! -i eth0 -p tcp" % (self.dev, self.dev)])
454454
self.fw.append(
455455
["", "", "-A NETWORK_STATS_%s -i %s ! -o eth0 -p tcp" % (self.dev, self.dev)])
456-
self.fw.append(["nat", "",
457-
"-A POSTROUTING -o %s -j SNAT --to-source %s" % (self.dev, self.cl.get_eth2_ip())])
456+
self.fw.append(
457+
["nat", "", "-A POSTROUTING -o %s -j SNAT --to-source %s" % (self.dev, self.cl.get_eth2_ip())])
458458
self.fw.append(["mangle", "",
459459
"-A PREROUTING -i %s -m state --state NEW " % self.dev +
460460
"-j CONNMARK --set-xmark %s/0xffffffff" % self.dnum])
@@ -695,6 +695,9 @@ def post_config_change(self, method):
695695
["filter", 3, "-A FORWARD -s %s ! -d %s -j ACCEPT" % (vpccidr, vpccidr)])
696696
self.fw.append(
697697
["nat", "", "-A POSTROUTING -j SNAT -o %s --to-source %s" % (self.dev, self.address['public_ip'])])
698+
elif cmdline.get_source_nat_ip() and not self.is_private_gateway():
699+
self.fw.append(
700+
["nat", "", "-A POSTROUTING -j SNAT -o %s --to-source %s" % (self.dev, cmdline.get_source_nat_ip())])
698701

699702
def list(self):
700703
self.iplist = {}

systemvm/debian/opt/cloud/bin/cs/CsDatabag.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ def get_dev_ip6prelen(self, devname):
181181
return False
182182
return "%s/%s" % (self.idata()[ipkey], self.idata()[prelenkey])
183183

184+
def get_source_nat_ip(self):
185+
if "source_nat_ip" in self.idata():
186+
return self.idata()['source_nat_ip']
187+
return False
188+
189+
184190
class CsGuestNetwork(CsDataBag):
185191
""" Get guestnetwork config parameters """
186192

0 commit comments

Comments
 (0)