Skip to content

Commit

Permalink
NAT: T6371: fix NAT op mode display of configured ports when comma ss…
Browse files Browse the repository at this point in the history
…perated list of ports/ranges exists
  • Loading branch information
Giggum committed May 27, 2024
1 parent 48e5266 commit 1697c95
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions src/op_mode/nat.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,33 @@ def _get_formatted_output_rules(data, direction, family):
elif my_dict['field'] == 'daddr':
daddr = f'{op}{my_dict["prefix"]["addr"]}/{my_dict["prefix"]["len"]}'
elif my_dict['field'] == 'sport':
# Port range or single port
if jmespath.search('set[*].range', my_dict):
sport = my_dict['set'][0]['range']
sport = '-'.join(map(str, sport))
else:
sport = my_dict.get('set')
sport = ','.join(map(str, sport))
# Get all configured sport ranges or single ports
for index, port in enumerate(my_dict['set']):
if 'range' in str(my_dict['set'][index]):
temp = my_dict['set'][index]['range']
temp = '-'.join(map(str, temp))
else:
temp = str(port)
if index == 0:
sport = str(temp)
else:
sport = ','.join([sport,temp])
if my_dict['op'] == '!=':
sport = '!' + sport
elif my_dict['field'] == 'dport':
# Port range or single port
if jmespath.search('set[*].range', my_dict):
dport = my_dict["set"][0]["range"]
dport = '-'.join(map(str, dport))
else:
dport = my_dict.get('set')
dport = ','.join(map(str, dport))
# Get all configured dport ranges or single ports
for index, port in enumerate(my_dict['set']):
if 'range' in str(my_dict['set'][index]):
temp = my_dict['set'][index]['range']
temp = '-'.join(map(str, temp))
else:
temp = str(port)
if index == 0:
dport = str(temp)
else:
dport = ','.join([dport,temp])
if my_dict['op'] == '!=':
dport = '!' + dport
else:
field = jmespath.search('left.payload.field', match)
if field == 'saddr':
Expand Down

0 comments on commit 1697c95

Please sign in to comment.