@@ -126,21 +126,35 @@ def _get_formatted_output_rules(data, direction, family):
126
126
elif my_dict ['field' ] == 'daddr' :
127
127
daddr = f'{ op } { my_dict ["prefix" ]["addr" ]} /{ my_dict ["prefix" ]["len" ]} '
128
128
elif my_dict ['field' ] == 'sport' :
129
- # Port range or single port
130
- if jmespath .search ('set[*].range' , my_dict ):
131
- sport = my_dict ['set' ][0 ]['range' ]
132
- sport = '-' .join (map (str , sport ))
133
- else :
134
- sport = my_dict .get ('set' )
135
- sport = ',' .join (map (str , sport ))
129
+ # Get all configured sport ranges or single ports
130
+ for index , port in enumerate (my_dict ['set' ]):
131
+ if 'range' in str (my_dict ['set' ][index ]):
132
+ temp = my_dict ['set' ][index ]['range' ]
133
+ temp = '-' .join (map (str , temp ))
134
+ else :
135
+ temp = str (port )
136
+ if index == 0 :
137
+ sport = str (temp )
138
+ else :
139
+ sport = ',' .join ([sport ,temp ])
140
+ if my_dict ['op' ] == '!=' :
141
+ sport = '!' + sport
136
142
elif my_dict ['field' ] == 'dport' :
137
- # Port range or single port
138
- if jmespath .search ('set[*].range' , my_dict ):
139
- dport = my_dict ["set" ][0 ]["range" ]
140
- dport = '-' .join (map (str , dport ))
141
- else :
142
- dport = my_dict .get ('set' )
143
- dport = ',' .join (map (str , dport ))
143
+ # Get all configured dport ranges or single ports
144
+ for index , port in enumerate (my_dict ['set' ]):
145
+ if 'range' in str (my_dict ['set' ][index ]):
146
+ temp = my_dict ['set' ][index ]['range' ]
147
+ temp = '-' .join (map (str , temp ))
148
+ else :
149
+ temp = str (port )
150
+
151
+ if index == 0 :
152
+ dport = str (temp )
153
+ else :
154
+ dport = ',' .join ([dport ,temp ])
155
+
156
+ if my_dict ['op' ] == '!=' :
157
+ dport = '!' + dport
144
158
else :
145
159
field = jmespath .search ('left.payload.field' , match )
146
160
if field == 'saddr' :
0 commit comments