(iptc_rule, ipv6=False)
return _filter_empty_field(d)
Return a dictionary representation of the Rule(6) object
    Note: host IP addresses are appended their corresponding CIDR
Return a dictionary representation of the Rule(6) object
    Note: host IP addresses are appended their corresponding CIDR
Return a dictionary representation of the Rule ( 6 ) object Note : host IP addresses are appended their corresponding CIDR
def decode_iptc_rule(iptc_rule, ipv6=False):
    """ Return a dictionary representation of the Rule(6) object
    Note: host IP addresses are appended their corresponding CIDR """
    d = {}
    if ipv6==False and iptc_rule.src != '0.0.0.0/0.0.0.0':
        _ip, _netmask = iptc_rule.src.split('/')
        _netmask = _netmask_v4_to_cidr(_netmask)
        d['src'] = '{}/{}'.format(_ip, _netmask)
    elif ipv6==True and iptc_rule.src != '::/0':
        d['src'] = iptc_rule.src
    if ipv6==False and iptc_rule.dst != '0.0.0.0/0.0.0.0':
        _ip, _netmask = iptc_rule.dst.split('/')
        _netmask = _netmask_v4_to_cidr(_netmask)
        d['dst'] = '{}/{}'.format(_ip, _netmask)
    elif ipv6==True and iptc_rule.dst != '::/0':
        d['dst'] = iptc_rule.dst
    if iptc_rule.protocol != 'ip':
        d['protocol'] = iptc_rule.protocol
    if iptc_rule.in_interface is not None:
        d['in-interface'] = iptc_rule.in_interface
    if iptc_rule.out_interface is not None:
        d['out-interface'] = iptc_rule.out_interface
    if ipv6 == False and iptc_rule.fragment:
        d['fragment'] = iptc_rule.fragment
    for m in iptc_rule.matches:
        if m.name not in d:
            d[m.name] = m.get_all_parameters()
        elif isinstance(d[m.name], list):
            d[m.name].append(m.get_all_parameters())
        else:
            d[m.name] = [d[m.name], m.get_all_parameters()]
    if iptc_rule.target and iptc_rule.target.name and len(iptc_rule.target.get_all_parameters()):
        name = iptc_rule.target.name.replace('-', '_')
        d['target'] = {name:iptc_rule.target.get_all_parameters()}
    elif iptc_rule.target and iptc_rule.target.name:
        if iptc_rule.target.goto:
            d['target'] = {'goto':iptc_rule.target.name}
        else:
            d['target'] = iptc_rule.target.name
    # Get counters
    d['counters'] = iptc_rule.counters
    # Return a filtered dictionary
    return _filter_empty_field(d)
def decode_iptc_rule ( iptc_rule , ipv6 = False ) : d = { } if ipv6 == False and iptc_rule . src != '0.0.0.0/0.0.0.0' : _ip , _netmask = iptc_rule . src . split ( '/' ) _netmask = _netmask_v4_to_cidr ( _netmask ) d [ 'src' ] = '{}/{}' . format ( _ip , _netmask ) elif ipv6 == True and iptc_rule . src != '::/0' : d [ 'src' ] = iptc_rule . src if ipv6 == False and iptc_rule . dst != '0.0.0.0/0.0.0.0' : _ip , _netmask = iptc_rule . dst . split ( '/' ) _netmask = _netmask_v4_to_cidr ( _netmask ) d [ 'dst' ] = '{}/{}' . format ( _ip , _netmask ) elif ipv6 == True and iptc_rule . dst != '::/0' : d [ 'dst' ] = iptc_rule . dst if iptc_rule . protocol != 'ip' : d [ 'protocol' ] = iptc_rule . protocol if iptc_rule . in_interface is not None : d [ 'in-interface' ] = iptc_rule . in_interface if iptc_rule . out_interface is not None : d [ 'out-interface' ] = iptc_rule . out_interface if ipv6 == False and iptc_rule . fragment : d [ 'fragment' ] = iptc_rule . fragment for m in iptc_rule . matches : if m . name not in d : d [ m . name ] = m . get_all_parameters ( ) elif isinstance ( d [ m . name ] , list ) : d [ m . name ] . append ( m . get_all_parameters ( ) ) else : d [ m . name ] = [ d [ m . name ] , m . get_all_parameters ( ) ] if iptc_rule . target and iptc_rule . target . name and len ( iptc_rule . target . get_all_parameters ( ) ) : name = iptc_rule . target . name . replace ( '-' , '_' ) d [ 'target' ] = { name : iptc_rule . target . get_all_parameters ( ) } elif iptc_rule . target and iptc_rule . target . name : if iptc_rule . target . goto : d [ 'target' ] = { 'goto' : iptc_rule . target . name } else : d [ 'target' ] = iptc_rule . target . name # Get counters d [ 'counters' ] = iptc_rule . counters # Return a filtered dictionary return _filter_empty_field ( d )