@@ -793,6 +793,12 @@ def getGuestIp(self):
793793
794794 return None
795795
796+ def getGuestIpByIp (self , ipa ):
797+ for interface in self .config .address ().get_interfaces ():
798+ if interface .ip_in_subnet (ipa ):
799+ return interface .get_ip ()
800+ return None
801+
796802 def getDeviceByIp (self , ipa ):
797803 for interface in self .config .address ().get_interfaces ():
798804 if interface .ip_in_subnet (ipa ):
@@ -930,8 +936,20 @@ def forward_vpc(self, rule):
930936 if not rule ["internal_ports" ] == "any" :
931937 fw_output_rule += ":" + self .portsToString (rule ["internal_ports" ], "-" )
932938
939+ fw_postrout_rule2 = "-j SNAT --to-source %s -A POSTROUTING -s %s -d %s/32 -o %s -p %s -m %s --dport %s" % \
940+ (
941+ self .getGuestIpByIp (rule ['internal_ip' ]),
942+ self .getNetworkByIp (rule ['internal_ip' ]),
943+ rule ['internal_ip' ],
944+ self .getDeviceByIp (rule ['internal_ip' ]),
945+ rule ['protocol' ],
946+ rule ['protocol' ],
947+ self .portsToString (rule ['internal_ports' ], ':' )
948+ )
949+
933950 self .fw .append (["nat" , "" , fw_prerout_rule ])
934951 self .fw .append (["nat" , "" , fw_postrout_rule ])
952+ self .fw .append (["nat" , "" , fw_postrout_rule2 ])
935953 self .fw .append (["nat" , "" , fw_output_rule ])
936954
937955 def processStaticNatRule (self , rule ):
0 commit comments