From 1f74bdf65791ee8d18d8cfc914e81b25cef9a6c8 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Tue, 21 Sep 2010 21:16:02 -0700 Subject: * move count_iptables_rule to Iptables::Mgr and update it's usage --- lib/Vyatta/IpTables/Mgr.pm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib/Vyatta') diff --git a/lib/Vyatta/IpTables/Mgr.pm b/lib/Vyatta/IpTables/Mgr.pm index 9247a44..ff468cb 100755 --- a/lib/Vyatta/IpTables/Mgr.pm +++ b/lib/Vyatta/IpTables/Mgr.pm @@ -29,7 +29,7 @@ use warnings; use base 'Exporter'; our @EXPORT = qw(ipt_find_chain_rule ipt_enable_conntrack - ipt_disable_conntrack); + ipt_disable_conntrack count_iptables_rules); sub ipt_find_chain_rule { @@ -104,4 +104,14 @@ sub ipt_disable_conntrack { return 0; } +sub count_iptables_rules { + my ($command, $table, $chain) = @_; + my @lines = `sudo $command -t $table -L $chain -n --line`; + my $cnt = 0; + foreach my $line (@lines) { + $cnt++ if $line =~ /^\d/; + } + return $cnt; +} + 1; -- cgit v1.2.3