Skip to content
This repository was archived by the owner on Jan 15, 2020. It is now read-only.

Commit cb2b9e8

Browse files
Fixing the communication with VM via Public IP
- Pub IP port forwarding and static NAT fixed for single VPCs - Pub IP port forwarding fixed for redundant VPCs [wip] fix static NAT for redundant VPCs This closes apache#150
1 parent aada8fe commit cb2b9e8

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

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

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ def process(self):
414414
self.deletevpn(ip)
415415

416416
def deletevpn(self, ip):
417-
logging.info("Removinf VPN configuration for %s", ip)
417+
logging.info("Removing VPN configuration for %s", ip)
418418
CsHelper.execute("ipsec auto --down vpn-%s" % ip)
419419
CsHelper.execute("ipsec auto --delete vpn-%s" % ip)
420420
vpnconffile = "%s/ipsec.vpn-%s.conf" % (self.VPNCONFDIR, ip)
@@ -586,15 +586,36 @@ def forward_vr(self, rule):
586586
self.fw.append(["nat", "", fw6])
587587

588588
def forward_vpc(self, rule):
589-
fwrule = "-A PREROUTING -d %s/32" % rule["public_ip"]
589+
fw_prerout_rule = "-A PREROUTING -d %s/32 -i %s" % (rule["public_ip"], self.getDeviceByIp(rule['public_ip']))
590590
if not rule["protocol"] == "any":
591-
fwrule += " -m %s -p %s" % (rule["protocol"], rule["protocol"])
591+
fw_prerout_rule += " -m %s -p %s" % (rule["protocol"], rule["protocol"])
592592
if not rule["public_ports"] == "any":
593-
fwrule += " --dport %s" % self.portsToString(rule["public_ports"], ":")
594-
fwrule += " -j DNAT --to-destination %s" % rule["internal_ip"]
593+
fw_prerout_rule += " --dport %s" % self.portsToString(rule["public_ports"], ":")
594+
fw_prerout_rule += " -j DNAT --to-destination %s" % rule["internal_ip"]
595595
if not rule["internal_ports"] == "any":
596-
fwrule += ":" + self.portsToString(rule["internal_ports"], "-")
597-
self.fw.append(["nat", "", fwrule])
596+
fw_prerout_rule += ":" + self.portsToString(rule["internal_ports"], "-")
597+
598+
fw_postrout_rule = "-A POSTROUTING -d %s/32 " % rule["public_ip"]
599+
if not rule["protocol"] == "any":
600+
fw_postrout_rule += " -m %s -p %s" % (rule["protocol"], rule["protocol"])
601+
if not rule["public_ports"] == "any":
602+
fw_postrout_rule += " --dport %s" % self.portsToString(rule["public_ports"], ":")
603+
fw_postrout_rule += " -j SNAT --to-source %s" % rule["internal_ip"]
604+
if not rule["internal_ports"] == "any":
605+
fw_postrout_rule += ":" + self.portsToString(rule["internal_ports"], "-")
606+
607+
fw_output_rule = "-A OUTPUT -d %s/32" % rule["public_ip"]
608+
if not rule["protocol"] == "any":
609+
fw_output_rule += " -m %s -p %s" % (rule["protocol"], rule["protocol"])
610+
if not rule["public_ports"] == "any":
611+
fw_output_rule += " --dport %s" % self.portsToString(rule["public_ports"], ":")
612+
fw_output_rule += " -j DNAT --to-destination %s" % rule["internal_ip"]
613+
if not rule["internal_ports"] == "any":
614+
fw_output_rule += ":" + self.portsToString(rule["internal_ports"], "-")
615+
616+
self.fw.append(["nat", "", fw_prerout_rule])
617+
self.fw.append(["nat", "", fw_postrout_rule])
618+
self.fw.append(["nat", "", fw_output_rule])
598619

599620
def processStaticNatRule(self, rule):
600621
# FIXME this needs ordering with the VPN no nat rule
@@ -605,6 +626,8 @@ def processStaticNatRule(self, rule):
605626
"-A PREROUTING -d %s/32 -j DNAT --to-destination %s" % (rule["public_ip"], rule["internal_ip"])])
606627
self.fw.append(["nat", "front",
607628
"-A POSTROUTING -o %s -s %s/32 -j SNAT --to-source %s" % (device, rule["internal_ip"], rule["public_ip"])])
629+
self.fw.append(["nat", "front",
630+
"-A OUTPUT -d %s/32 -j DNAT --to-destination %s" % (rule["public_ip"], rule["internal_ip"])])
608631

609632

610633
def main(argv):

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,11 @@ def get_gateway(self):
129129
if self.config.is_vpc():
130130
return self.get_attr("gateway")
131131
else:
132-
if self.config.cmdline().is_redundant():
133-
return self.config.cmdline().get_guest_gw()
134-
else:
135-
return self.get_ip()
132+
return self.config.cmdline().get_guest_gw()
133+
# if self.config.cmdline().is_redundant():
134+
# return self.config.cmdline().get_guest_gw()
135+
# else:
136+
# return self.get_ip()
136137

137138
def ip_in_subnet(self, ip):
138139
ipo = IPAddress(ip)

systemvm/patches/debian/config/opt/cloud/templates/keepalived.conf.templ

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ global_defs {
1919
router_id [ROUTER_ID]
2020
}
2121

22-
!vrrp_script check_bumpup {
23-
!script "[RROUTER_BIN_PATH]/check_bumpup.sh"
24-
!interval 5
25-
!weight [DELTA]
26-
!}
27-
2822
vrrp_script heartbeat {
2923
script "[RROUTER_BIN_PATH]/heartbeat.sh"
3024
interval 10
@@ -48,7 +42,6 @@ vrrp_instance inside_network {
4842
}
4943

5044
track_script {
51-
!check_bumpup
5245
heartbeat
5346
}
5447

0 commit comments

Comments
 (0)