@@ -793,6 +793,12 @@ def getGuestIp(self):
793
793
794
794
return None
795
795
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
+
796
802
def getDeviceByIp (self , ipa ):
797
803
for interface in self .config .address ().get_interfaces ():
798
804
if interface .ip_in_subnet (ipa ):
@@ -930,8 +936,20 @@ def forward_vpc(self, rule):
930
936
if not rule ["internal_ports" ] == "any" :
931
937
fw_output_rule += ":" + self .portsToString (rule ["internal_ports" ], "-" )
932
938
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
+
933
950
self .fw .append (["nat" , "" , fw_prerout_rule ])
934
951
self .fw .append (["nat" , "" , fw_postrout_rule ])
952
+ self .fw .append (["nat" , "" , fw_postrout_rule2 ])
935
953
self .fw .append (["nat" , "" , fw_output_rule ])
936
954
937
955
def processStaticNatRule (self , rule ):
0 commit comments