(net_if, cmd)
Add iptables rule

    Args:
        net_if : network interface name
        cmd    : list with iptables command
Add iptables rule
Add iptables rule
def _add_iptables_rule(net_if, cmd):
    """Add iptables rule

    Args:
        net_if : network interface name
        cmd    : list with iptables command

    """
    assert (cmd[0] != "sudo")

    # Set up the iptables rules
    runner.run(cmd, root=True)

    for rule in _get_iptables_rules(net_if):
        print_rule = False

        if (rule['rule'][3] == "ACCEPT" and rule['rule'][6] == cmd[6]
                and rule['rule'][4] == cmd[4]):
            if (cmd[4] == "igmp"):
                print_rule = True
            elif (cmd[4] == "udp" and rule['rule'][12] == cmd[10]):
                print_rule = True

            if (print_rule):
                print("Added iptables rule:\n")
                print(rule['header1'])
                print(rule['header2'])
                print(" ".join(rule['rule']) + "\n")
def _add_iptables_rule ( net_if , cmd ) : assert ( cmd [ 0 ] != "sudo" ) # Set up the iptables rules runner . run ( cmd , root = True ) for rule in _get_iptables_rules ( net_if ) : print_rule = False if ( rule [ 'rule' ] [ 3 ] == "ACCEPT" and rule [ 'rule' ] [ 6 ] == cmd [ 6 ] and rule [ 'rule' ] [ 4 ] == cmd [ 4 ] ) : if ( cmd [ 4 ] == "igmp" ) : print_rule = True elif ( cmd [ 4 ] == "udp" and rule [ 'rule' ] [ 12 ] == cmd [ 10 ] ) : print_rule = True if ( print_rule ) : print ( "Added iptables rule:\n" ) print ( rule [ 'header1' ] ) print ( rule [ 'header2' ] ) print ( " " . join ( rule [ 'rule' ] ) + "\n" )