diff options
author | Viacheslav Hletenko <v.gletenko@vyos.io> | 2023-10-30 17:26:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-30 17:26:48 +0200 |
commit | 2d60bc124447c5f978536b796bda4524b121a03c (patch) | |
tree | b49cfb9430a09874e6f2071a96d35d27bd5f3983 /python | |
parent | 5974491d4b69932876ad697f82e1ef74cd37aa8f (diff) | |
parent | 94c98a78717293deb6a9863e40280565d0b47271 (diff) | |
download | vyos-1x-2d60bc124447c5f978536b796bda4524b121a03c.tar.gz vyos-1x-2d60bc124447c5f978536b796bda4524b121a03c.zip |
Merge pull request #2400 from vyos/mergify/bp/sagitta/pr-2355
T5643: nat: add interface-groups to nat. Use same cli structure for i… (backport #2355)
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'] |