#!/usr/bin/perl -w

use lib '/usr/lib/fwknop';
use IPTables::ChainMgr;
use IPTables::Parse;
use strict;

my $ipt = new IPTables::ChainMgr(
    'iptables' => '/sbin/iptables'
);

my $rv;
my $status_msg;

($rv, $status_msg) = $ipt->create_chain('filter', 'FWKNOP');
print "$status_msg: $rv\n";

($rv, $status_msg) = $ipt->add_jump_rule('filter', 'INPUT', 'FWKNOP');
print "$status_msg: $rv\n";

($rv, $status_msg) = $ipt->add_ip_rule('1.1.1.1', '0.0.0.0/0',
    1, 'filter', 'FWKNOP', 'ACCEPT', {'protocol' => 'tcp'});
print "$status_msg: $rv\n";

$rv = $ipt->find_ip_rule('192.168.10.2', '0.0.0.0/0', 'filter',
    'FWKNOP_INPUT', 'ACCEPT', {'protocol' => 'tcp', 'd_port' => 22});
print "find ip: $rv\n";

($rv, $status_msg) = $ipt->add_ip_rule('192.168.10.2', '0.0.0.0/0', 1,
    'filter', 'FWKNOP_INPUT', 'ACCEPT', {'protocol' => 'tcp', 'd_port' => 22});
print "$status_msg: $rv\n";

($rv, $status_msg) = $ipt->delete_ip_rule('1.1.1.1', '0.0.0.0/0',
    'filter', 'FWKNOP', 'ACCEPT');
print "$status_msg: $rv\n";

($rv, $status_msg) = $ipt->delete_chain('filter', 'INPUT', 'FWKNOP');
print "$status_msg: $rv\n";

#my $aref = ();
#($rv, $aref) = $ipt->run_ipt_cmd_output("/sbin/iptables -n -L INPUT");
#print for @$aref;

exit 0;
