This commit is contained in:
Hugo Levy-Falk 2019-05-06 21:46:13 +02:00 committed by root
parent f0c2d3bf50
commit 578d5aa51a

View file

@ -607,6 +607,12 @@ def get_ip_iterable_from_str(ip):
class NAT:
PROTOCOLS = (
'tcp',
'udp',
'icmp'
)
def __init__(self,
name,
range_in,
@ -648,22 +654,16 @@ class NAT:
grp: The name of the group
ports: The port range (str)
"""
CommandExec.run([
*self.nft,
"add rule ip nat {name}_nat ip saddr @{name}_nat_port_{grp} ip protocol tcp snat ip saddr map @{name}_nat_address : {ports}".format(
name=self.name,
grp=grp,
ports=ports
)
])
CommandExec.run([
*self.nft,
"add rule ip nat {name}_nat ip saddr @{name}_nat_port_{grp} ip protocol udp snat ip saddr map @{name}_nat_address : {ports}".format(
name=self.name,
grp=grp,
ports=ports
)
])
for protocol in self.PROTOCOLS:
CommandExec.run([
*self.nft,
"add rule ip nat {name}_nat ip saddr @{name}_nat_port_{grp} ip protocol {protocol} snat ip saddr map @{name}_nat_address : {ports}".format(
protocol=protocol,
name=self.name,
grp=grp,
ports=ports
)
])
def manage(self):
"""Creates the port sets, ip map and rules