@@ -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
610633def main (argv ):
0 commit comments