@@ -144,6 +144,8 @@ def _get_ports_for_output(rules):
144144 if 'expr' in rule ['rule' ]:
145145 interface = rule .get ('rule' ).get ('expr' )[0 ].get ('match' ).get ('right' ) \
146146 if jmespath .search ('rule.expr[*].match.left.meta' , rule ) else 'any'
147+ if interface [0 ] == '@' :
148+ interface = interface [3 :]
147149 for index , match in enumerate (jmespath .search ('rule.expr[*].match' , rule )):
148150 if 'payload' in match ['left' ]:
149151 # Handle NAT rule containing comma-seperated list of ports
@@ -154,7 +156,10 @@ def _get_ports_for_output(rules):
154156 my_dict = {** match ['left' ]['payload' ], ** match ['right' ]}
155157 my_dict ['op' ] = match ['op' ]
156158 op = '!' if my_dict .get ('op' ) == '!=' else ''
157- proto = my_dict .get ('protocol' ).upper ()
159+ if my_dict ['field' ] in ['sport' , 'dport' ]:
160+ proto = my_dict .get ('protocol' ).upper ()
161+ if proto == 'TH' :
162+ proto = 'TCP, UDP'
158163 if my_dict ['field' ] == 'saddr' :
159164 saddr = f'{ op } { my_dict ["prefix" ]["addr" ]} /{ my_dict ["prefix" ]["len" ]} '
160165 elif my_dict ['field' ] == 'daddr' :
@@ -166,6 +171,10 @@ def _get_ports_for_output(rules):
166171 # Handle NAT rule containing a single port
167172 else :
168173 field = jmespath .search ('left.payload.field' , match )
174+ if field in ['sport' , 'dport' ]:
175+ proto = jmespath .search ('left.payload.protocol' , match ).upper ()
176+ if proto == 'TH' :
177+ proto = 'TCP, UDP'
169178 if field == 'saddr' :
170179 saddr = match .get ('right' )
171180 elif field == 'daddr' :
@@ -186,8 +195,12 @@ def _get_ports_for_output(rules):
186195 destination = f'''{ daddr }
187196dport { dport } '''
188197
189- if jmespath .search ('left.payload.field' , match ) == 'protocol' :
190- field_proto = match .get ('right' ).upper ()
198+ if jmespath .search ('left.meta.key' , match ) == 'l4proto' :
199+ right = match .get ('right' )
200+ if isinstance (right , dict ) and 'set' in right :
201+ proto = ', ' .join (right ['set' ])
202+ elif isinstance (right , str ):
203+ proto = right .upper ()
191204
192205 for expr in rule .get ('rule' ).get ('expr' ):
193206 if 'snat' in expr :
0 commit comments