@@ -141,12 +141,14 @@ class ServiceMap(object):
141141 def __init__ (self ):
142142 self .entries = {}
143143
144- def get_service_name (self , term_name , src_ports , ports , protocol ):
144+ def get_service_name (self , term_name , src_ports , ports , protocol , prefix = None ):
145145 """Returns service name based on the provided ports and protocol."""
146146 if (src_ports , ports , protocol ) in self .entries :
147147 return self .entries [(src_ports , ports , protocol )]["name" ]
148148
149- service_name = "service-%s-%s" % (term_name , protocol )
149+ if prefix is None :
150+ prefix = "service-"
151+ service_name = "%s%s-%s" % (prefix , term_name , protocol )
150152
151153 if len (service_name ) > 63 :
152154 raise PaloAltoFWNameTooLongError (
@@ -268,6 +270,21 @@ def pan_ports(ports):
268270 if service_name not in self .options ["service" ]:
269271 self .options ["service" ].append (service_name )
270272
273+ elif "tcp" in term .protocol or "udp" in term .protocol :
274+ for p in term .protocol :
275+ if p not in ["tcp" , "udp" ]:
276+ logging .warning (
277+ "WARNING: Term %s in policy %s>%s contains port-less tcp "
278+ "and/or udp with protocol %s. Move %s to another term." ,
279+ term .name , self .options ["from_zone" ][0 ],
280+ self .options ["to_zone" ][0 ], p , p )
281+ continue
282+ ports = pan_ports ([("0" , "65535" )])
283+ # use prefix "" to avoid service name clash with term named "any"
284+ service_name = service_map .get_service_name ("any" , (), ports , p , "" )
285+ if service_name not in self .options ["service" ]:
286+ self .options ["service" ].append (service_name )
287+
271288 if term .protocol :
272289 # Add application "any" to all terms, unless ICMP/ICMPv6
273290 for proto_name in term .protocol :
0 commit comments