diff options
author | Nicolas Fort <nicolasfort1988@gmail.com> | 2023-10-10 17:35:30 +0000 |
---|---|---|
committer | Mergify <37929162+mergify[bot]@users.noreply.github.com> | 2023-10-24 04:18:48 +0000 |
commit | 94c98a78717293deb6a9863e40280565d0b47271 (patch) | |
tree | 1dd9c3124a87cc5dd3b7a1f22fa01f3ef1b401f3 /python | |
parent | b15dbec9b5df507ee31f8e029c5a1c58762a6e43 (diff) | |
download | vyos-1x-94c98a78717293deb6a9863e40280565d0b47271.tar.gz vyos-1x-94c98a78717293deb6a9863e40280565d0b47271.zip |
T5643: nat: add interface-groups to nat. Use same cli structure for interface-name|interface-group as in firewall.
(cherry picked from commit 2f2c3fa22478c7ba2e116486d655e07df878cdf4)
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/nat.py | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/python/vyos/nat.py b/python/vyos/nat.py index cc3c8103d..e32b5ae74 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'] |