summaryrefslogtreecommitdiff
path: root/python/vyos/nat.py
diff options
context:
space:
mode:
authorNicolas Fort <nicolasfort1988@gmail.com>2023-10-10 17:35:30 +0000
committerNicolas Fort <nicolasfort1988@gmail.com>2023-10-11 09:44:28 +0000
commit2f2c3fa22478c7ba2e116486d655e07df878cdf4 (patch)
treef0c400df61a910651e4b890a583b88a3746cd8ab /python/vyos/nat.py
parent9ceba9ede21f4f89bd0b4ee614178b82cddb7d41 (diff)
downloadvyos-1x-2f2c3fa22478c7ba2e116486d655e07df878cdf4.tar.gz
vyos-1x-2f2c3fa22478c7ba2e116486d655e07df878cdf4.zip
T5643: nat: add interface-groups to nat. Use same cli structure for interface-name|interface-group as in firewall.
Diffstat (limited to 'python/vyos/nat.py')
-rw-r--r--python/vyos/nat.py32
1 files changed, 26 insertions, 6 deletions
diff --git a/python/vyos/nat.py b/python/vyos/nat.py
index 9cbc2b96e..0887bfdf1 100644
--- a/python/vyos/nat.py
+++ b/python/vyos/nat.py
@@ -32,14 +32,34 @@ def parse_nat_rule(rule_conf, rule_id, nat_type, ipv6=False):
translation_str = ''
if 'inbound_interface' in rule_conf:
- ifname = rule_conf['inbound_interface']
- if ifname != 'any':
- output.append(f'iifname "{ifname}"')
+ operator = ''
+ if 'interface_name' in rule_conf['inbound_interface']:
+ iiface = rule_conf['inbound_interface']['interface_name']
+ if iiface[0] == '!':
+ operator = '!='
+ iiface = iiface[1:]
+ output.append(f'iifname {operator} {{{iiface}}}')
+ else:
+ iiface = rule_conf['inbound_interface']['interface_group']
+ if iiface[0] == '!':
+ operator = '!='
+ iiface = iiface[1:]
+ output.append(f'iifname {operator} @I_{iiface}')
if 'outbound_interface' in rule_conf:
- ifname = rule_conf['outbound_interface']
- if ifname != 'any':
- output.append(f'oifname "{ifname}"')
+ operator = ''
+ if 'interface_name' in rule_conf['outbound_interface']:
+ oiface = rule_conf['outbound_interface']['interface_name']
+ if oiface[0] == '!':
+ operator = '!='
+ oiface = oiface[1:]
+ output.append(f'oifname {operator} {{{oiface}}}')
+ else:
+ oiface = rule_conf['outbound_interface']['interface_group']
+ if oiface[0] == '!':
+ operator = '!='
+ oiface = oiface[1:]
+ output.append(f'oifname {operator} @I_{oiface}')
if 'protocol' in rule_conf and rule_conf['protocol'] != 'all':
protocol = rule_conf['protocol']