(rule_d, ipv6=False)
return iptc_rule
Return a Rule(6) object from the input dictionary
Return a Rule(6) object from the input dictionary
Return a Rule ( 6 ) object from the input dictionary
def encode_iptc_rule(rule_d, ipv6=False):
    """ Return a Rule(6) object from the input dictionary """
    # Sanity check
    assert(isinstance(rule_d, dict))
    # Basic rule attributes
    rule_attr = ('src', 'dst', 'protocol', 'in-interface', 'out-interface', 'fragment')
    iptc_rule = Rule6() if ipv6 else Rule()
    # Set default target
    rule_d.setdefault('target', '')
    # Avoid issues with matches that require basic parameters to be configured first
    for name in rule_attr:
        if name in rule_d:
            setattr(iptc_rule, name.replace('-', '_'), rule_d[name])
    for name, value in rule_d.items():
        try:
            if name in rule_attr:
                continue
            elif name == 'counters':
                _iptc_setcounters(iptc_rule, value)
            elif name == 'target':
                _iptc_settarget(iptc_rule, value)
            else:
                _iptc_setmatch(iptc_rule, name, value)
        except Exception as e:
            #print('Ignoring unsupported field <{}:{}>'.format(name, value))
            continue
    return iptc_rule
def encode_iptc_rule ( rule_d , ipv6 = False ) : # Sanity check assert ( isinstance ( rule_d , dict ) ) # Basic rule attributes rule_attr = ( 'src' , 'dst' , 'protocol' , 'in-interface' , 'out-interface' , 'fragment' ) iptc_rule = Rule6 ( ) if ipv6 else Rule ( ) # Set default target rule_d . setdefault ( 'target' , '' ) # Avoid issues with matches that require basic parameters to be configured first for name in rule_attr : if name in rule_d : setattr ( iptc_rule , name . replace ( '-' , '_' ) , rule_d [ name ] ) for name , value in rule_d . items ( ) : try : if name in rule_attr : continue elif name == 'counters' : _iptc_setcounters ( iptc_rule , value ) elif name == 'target' : _iptc_settarget ( iptc_rule , value ) else : _iptc_setmatch ( iptc_rule , name , value ) except Exception as e : #print('Ignoring unsupported field <{}:{}>'.format(name, value)) continue return iptc_rule