Skip to content

Commit 4420f48

Browse files
committed
Merge pull request apache#882 from jayapalu/CLOUDSTACK-8881
CLOUDSTACK-8881: Fixed Static and PF configuration issue1. For static nat filter rules are not configured in VR. 2. Corrected vm ip in PF rule. * pr/882: CLOUDSTACK-8881: Fixed Static and PF configuration issue Signed-off-by: Remi Bergsma <github@remi.nl>
2 parents 649a4bd + 40138d2 commit 4420f48

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

systemvm/patches/debian/config/opt/cloud/bin/configure.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,20 @@ def process(self):
663663
elif rule["type"] == "staticnat":
664664
self.processStaticNatRule(rule)
665665

666+
#return the VR guest interface ipo
667+
def getGuestIp(self):
668+
ipr = []
669+
ipAddr = None
670+
for ip in self.config.address().get_ips():
671+
if ip.is_guest():
672+
ipr.append(ip)
673+
if len(ipr) > 0:
674+
ipAddr = sorted(ipr)[-1]
675+
if ipAddr:
676+
return ipAddr.get_ip()
677+
678+
return None
679+
666680
def getDeviceByIp(self, ipa):
667681
for ip in self.config.address().get_ips():
668682
if ip.ip_in_subnet(ipa):
@@ -726,7 +740,7 @@ def forward_vr(self, rule):
726740
)
727741
fw4 = "-j SNAT --to-source %s -A POSTROUTING -s %s -d %s/32 -o %s -p %s -m %s --dport %s" % \
728742
(
729-
self.getGatewayByIp(rule['internal_ip']),
743+
self.getGuestIp(),
730744
self.getNetworkByIp(rule['internal_ip']),
731745
rule['internal_ip'],
732746
self.getDeviceByIp(rule['internal_ip']),
@@ -810,6 +824,14 @@ def processStaticNatRule(self, rule):
810824
"-A POSTROUTING -o %s -s %s/32 -j SNAT --to-source %s" % (device, rule["internal_ip"], rule["public_ip"])])
811825
self.fw.append(["nat", "front",
812826
"-A OUTPUT -d %s/32 -j DNAT --to-destination %s" % (rule["public_ip"], rule["internal_ip"])])
827+
self.fw.append(["filter", "",
828+
"-A FORWARD -i %s -o eth0 -d %s -m state --state NEW -j ACCEPT " % (device, rule["internal_ip"])])
829+
830+
#configure the hairpin nat
831+
self.fw.append(["nat", "front",
832+
"-A PREROUTING -d %s -i eth0 -j DNAT --to-destination %s" % (rule["public_ip"], rule["internal_ip"])])
833+
834+
self.fw.append(["nat", "front", "-A POSTROUTING -s %s -d %s -j SNAT -o eth0 --to-source %s" % (self.getNetworkByIp(rule['internal_ip']),rule["internal_ip"], self.getGuestIp())])
813835

814836

815837
def main(argv):

0 commit comments

Comments
 (0)