diff options
author | Christian Breunig <christian@breunig.cc> | 2023-10-24 06:17:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-24 06:17:12 +0200 |
commit | 90bcb2f96f32f20c355ce4223d0afe89fb12271f (patch) | |
tree | 8060558921386c3fc22efdd935f4adc4b4c0b2a6 /python/vyos/nat.py | |
parent | 9c029b71cbf8bd61c6e37789ba8da170e6282761 (diff) | |
parent | 2f2c3fa22478c7ba2e116486d655e07df878cdf4 (diff) | |
download | vyos-1x-90bcb2f96f32f20c355ce4223d0afe89fb12271f.tar.gz vyos-1x-90bcb2f96f32f20c355ce4223d0afe89fb12271f.zip |
Merge pull request #2355 from nicolas-fort/T5643
T5643: nat: add interface-groups to nat. Use same cli structure for i…
Diffstat (limited to 'python/vyos/nat.py')
-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'] |