(table, batch_rules, ipv6=False)
Add multiple rules to a table with format (chain, rule_d, position)
Add multiple rules to a table with format (chain, rule_d, position)
Add multiple rules to a table with format ( chain rule_d position )
def batch_add_rules(table, batch_rules, ipv6=False):
    """ Add multiple rules to a table with format (chain, rule_d, position) """
    iptc_table = _batch_begin_table(table, ipv6)
    for (chain, rule_d, position) in batch_rules:
        iptc_chain = Chain(iptc_table, chain)
        iptc_rule  = encode_iptc_rule(rule_d, ipv6)
        if position == 0:
            # Insert rule in last position -> append
            iptc_chain.append_rule(iptc_rule)
        elif position > 0:
            # Insert rule in given position -> adjusted as iptables CLI
            iptc_chain.insert_rule(iptc_rule, position-1)
        elif position < 0:
            # Insert rule in given position starting from bottom -> not available in iptables CLI
            nof_rules = len(iptc_chain.rules)
            iptc_chain.insert_rule(iptc_rule, position + nof_rules)
    _batch_end_table(table, ipv6)
def batch_add_rules ( table , batch_rules , ipv6 = False ) : iptc_table = _batch_begin_table ( table , ipv6 ) for ( chain , rule_d , position ) in batch_rules : iptc_chain = Chain ( iptc_table , chain ) iptc_rule = encode_iptc_rule ( rule_d , ipv6 ) if position == 0 : # Insert rule in last position -> append iptc_chain . append_rule ( iptc_rule ) elif position > 0 : # Insert rule in given position -> adjusted as iptables CLI iptc_chain . insert_rule ( iptc_rule , position - 1 ) elif position < 0 : # Insert rule in given position starting from bottom -> not available in iptables CLI nof_rules = len ( iptc_chain . rules ) iptc_chain . insert_rule ( iptc_rule , position + nof_rules ) _batch_end_table ( table , ipv6 )