summaryrefslogtreecommitdiff
path: root/src/op_mode/nat.py
diff options
context:
space:
mode:
authorsarthurdev <965089+sarthurdev@users.noreply.github.com>2022-09-28 13:07:33 +0200
committersarthurdev <965089+sarthurdev@users.noreply.github.com>2022-09-28 13:07:33 +0200
commit87fdfa6c6ece87e6f719fc8ba80ae185a9f689c1 (patch)
treee8dd0f44556b31cdef34d8cbf57f4054f8e188a7 /src/op_mode/nat.py
parentf5a50135f07ac4ec8ed431a757b9c56e607d2132 (diff)
downloadvyos-1x-87fdfa6c6ece87e6f719fc8ba80ae185a9f689c1.tar.gz
vyos-1x-87fdfa6c6ece87e6f719fc8ba80ae185a9f689c1.zip
nat: T4713: Fix op-mode nat translation output
Diffstat (limited to 'src/op_mode/nat.py')
-rwxr-xr-xsrc/op_mode/nat.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/op_mode/nat.py b/src/op_mode/nat.py
index a0496dedb..845dbbb2c 100755
--- a/src/op_mode/nat.py
+++ b/src/op_mode/nat.py
@@ -109,7 +109,7 @@ def _get_formatted_output_rules(data, direction, family):
if jmespath.search('rule.expr[*].match.left.meta', rule) else 'any'
for index, match in enumerate(jmespath.search('rule.expr[*].match', rule)):
if 'payload' in match['left']:
- if 'prefix' in match['right'] or 'set' in match['right']:
+ if isinstance(match['right'], dict) and ('prefix' in match['right'] or 'set' in match['right']):
# Merge dict src/dst l3_l4 parameters
my_dict = {**match['left']['payload'], **match['right']}
my_dict['op'] = match['op']
@@ -136,10 +136,15 @@ def _get_formatted_output_rules(data, direction, family):
dport = my_dict.get('set')
dport = ','.join(map(str, dport))
else:
- if jmespath.search('left.payload.field', match) == 'saddr':
+ field = jmespath.search('left.payload.field', match)
+ if field == 'saddr':
saddr = match.get('right')
- if jmespath.search('left.payload.field', match) == 'daddr':
+ elif field == 'daddr':
daddr = match.get('right')
+ elif field == 'sport':
+ sport = match.get('right')
+ elif field == 'dport':
+ dport = match.get('right')
else:
saddr = '::/0' if family == 'inet6' else '0.0.0.0/0'
daddr = '::/0' if family == 'inet6' else '0.0.0.0/0'