Beispiel #1
0
 def _get_ip_version(rule):
     """Determine IP version of rule.
     Extracted from ufw.parser.UFWCommandRule.parse
     """
     # Determine src type
     if rule.src == ANY_ADDR:
         from_type = 'any'
     else:
         from_type = ('v6' if valid_address(rule.src, '6') else 'v4')
     # Determine dst type
     if rule.dst == ANY_ADDR:
         to_type = 'any'
     else:
         to_type = ('v6' if valid_address(rule.dst, '6') else 'v4')
     # Figure out the type of rule (IPv4, IPv6, or both)
     if from_type == 'any' and to_type == 'any':
         ip_version = 'both'
     elif from_type != 'any' and to_type != 'any' and from_type != to_type:
         err_msg = _("Mixed IP versions for 'from' and 'to'")
         raise ufw.common.UFWError(err_msg)
     elif from_type != 'any':
         ip_version = from_type
     elif to_type != 'any':
         ip_version = to_type
     return ip_version
Beispiel #2
0
 def _get_ip_version(rule):
     """Determine IP version of rule.
     Extracted from ufw.parser.UFWCommandRule.parse
     """
     # Determine src type
     if rule.src == ANY_ADDR:
         from_type = 'any'
     else:
         from_type = ('v6' if valid_address(rule.src, '6') else 'v4')
     # Determine dst type
     if rule.dst == ANY_ADDR:
         to_type = 'any'
     else:
         to_type = ('v6' if valid_address(rule.dst, '6') else 'v4')
     # Figure out the type of rule (IPv4, IPv6, or both)
     if from_type == 'any' and to_type == 'any':
         ip_version = 'both'
     elif from_type != 'any' and to_type != 'any' and from_type != to_type:
         err_msg = _("Mixed IP versions for 'from' and 'to'")
         raise ufw.common.UFWError(err_msg)
     elif from_type != 'any':
         ip_version = from_type
     elif to_type != 'any':
         ip_version = to_type
     return ip_version
def getProtocol(rule):
    """Determine protocol of rule.
    Taken from ufw.parser.UFWCommandRule.parse
    """
    # Determine src type
    if rule.src == ANY_ADDR:
        from_type = 'any'
    else:
        from_type = ('v6' if valid_address(rule.src, '6') else 'v4')
    # Determine dst type
    if rule.dst == ANY_ADDR:
        to_type = 'any'
    else:
        to_type = ('v6' if valid_address(rule.dst, '6') else 'v4')
    # Figure out the type of rule (IPv4, IPv6, or both)
    if from_type == ANY_PROTOCOL and to_type == ANY_PROTOCOL:
        protocol = 'both'
    elif from_type != ANY_PROTOCOL and to_type != ANY_PROTOCOL and from_type != to_type:
        err_msg = _("Mixed IP versions for 'from' and 'to'")
        raise ufw.common.UFWError(err_msg)
    elif from_type != ANY_PROTOCOL:
        protocol = from_type
    elif to_type != ANY_PROTOCOL:
        protocol = to_type
    return protocol