Пример #1
0
 def _validate_port_range(self, rule):
     """Check that port_range is valid."""
     if (rule['port_range_min'] is None and rule['port_range_max'] is None):
         return
     if not rule['protocol']:
         raise ext_sg.SecurityGroupProtocolRequiredWithPorts()
     ip_proto = self._get_ip_proto_number(rule['protocol'])
     if ip_proto in [constants.PROTO_NUM_TCP, constants.PROTO_NUM_UDP]:
         if rule['port_range_min'] == 0 or rule['port_range_max'] == 0:
             raise ext_sg.SecurityGroupInvalidPortValue(port=0)
         elif (rule['port_range_min'] is not None
               and rule['port_range_max'] is not None
               and rule['port_range_min'] <= rule['port_range_max']):
             pass
         else:
             raise ext_sg.SecurityGroupInvalidPortRange()
     elif ip_proto == constants.PROTO_NUM_ICMP:
         for attr, field in [('port_range_min', 'type'),
                             ('port_range_max', 'code')]:
             if rule[attr] is not None and not (0 <= rule[attr] <= 255):
                 raise ext_sg.SecurityGroupInvalidIcmpValue(
                     field=field, attr=attr, value=rule[attr])
         if (rule['port_range_min'] is None
                 and rule['port_range_max'] is not None):
             raise ext_sg.SecurityGroupMissingIcmpType(
                 value=rule['port_range_max'])
Пример #2
0
 def _validate_port_range(self, rule):
     """Check that port_range is valid."""
     if (rule['port_range_min'] is None and rule['port_range_max'] is None):
         return
     if not rule['protocol']:
         raise ext_sg.SecurityGroupProtocolRequiredWithPorts()
     ip_proto = self._get_ip_proto_number(rule['protocol'])
     # Not all firewall_driver support all these protocols,
     # but being strict here doesn't hurt.
     if ip_proto in [
             constants.PROTO_NUM_DCCP, constants.PROTO_NUM_SCTP,
             constants.PROTO_NUM_TCP, constants.PROTO_NUM_UDP,
             constants.PROTO_NUM_UDPLITE
     ]:
         if rule['port_range_min'] == 0 or rule['port_range_max'] == 0:
             raise ext_sg.SecurityGroupInvalidPortValue(port=0)
         elif (rule['port_range_min'] is not None
               and rule['port_range_max'] is not None
               and rule['port_range_min'] <= rule['port_range_max']):
             pass
         else:
             raise ext_sg.SecurityGroupInvalidPortRange()
     elif ip_proto in [
             constants.PROTO_NUM_ICMP, constants.PROTO_NUM_IPV6_ICMP
     ]:
         for attr, field in [('port_range_min', 'type'),
                             ('port_range_max', 'code')]:
             if rule[attr] is not None and not (0 <= rule[attr] <= 255):
                 raise ext_sg.SecurityGroupInvalidIcmpValue(
                     field=field, attr=attr, value=rule[attr])
         if (rule['port_range_min'] is None
                 and rule['port_range_max'] is not None):
             raise ext_sg.SecurityGroupMissingIcmpType(
                 value=rule['port_range_max'])
Пример #3
0
 def _validate_port_range(self, rule):
     """Check that port_range is valid."""
     if rule['port_range_min'] is None and rule['port_range_max'] is None:
         return
     if not rule['protocol']:
         raise ext_sg.SecurityGroupProtocolRequiredWithPorts()
     ip_proto = self._get_ip_proto_number(rule['protocol'])
     # Not all firewall_driver support all these protocols,
     # but being strict here doesn't hurt.
     if (ip_proto in const.SG_PORT_PROTO_NUMS
             or ip_proto in const.SG_PORT_PROTO_NAMES):
         if rule['port_range_min'] == 0 or rule['port_range_max'] == 0:
             raise ext_sg.SecurityGroupInvalidPortValue(port=0)
         if (rule['port_range_min'] is not None
                 and rule['port_range_max'] is not None
                 and rule['port_range_min'] <= rule['port_range_max']):
             # When min/max are the same it is just a single port
             pass
         else:
             raise ext_sg.SecurityGroupInvalidPortRange()
     elif ip_proto in [
             constants.PROTO_NUM_ICMP, constants.PROTO_NUM_IPV6_ICMP
     ]:
         for attr, field in [('port_range_min', 'type'),
                             ('port_range_max', 'code')]:
             if rule[attr] is not None and not (0 <= rule[attr] <= 255):
                 raise ext_sg.SecurityGroupInvalidIcmpValue(
                     field=field, attr=attr, value=rule[attr])
         if (rule['port_range_min'] is None
                 and rule['port_range_max'] is not None):
             raise ext_sg.SecurityGroupMissingIcmpType(
                 value=rule['port_range_max'])
     else:
         # Only the protocols above support ports, raise otherwise.
         if (rule['port_range_min'] is not None
                 or rule['port_range_max'] is not None):
             port_protocols = (', '.join(
                 s.upper() for s in const.SG_PORT_PROTO_NAMES))
             raise ext_sg.SecurityGroupInvalidProtocolForPort(
                 protocol=ip_proto, valid_port_protocols=port_protocols)