From 4d030e8c3c0f289de8471b91bc6b789592254b46 Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Fri, 13 Feb 2009 15:22:10 -0800 Subject: Cache exists() to reduce calls to external /usr/sbin/ipset. --- lib/Vyatta/IpTables/IpSet.pm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/Vyatta') diff --git a/lib/Vyatta/IpTables/IpSet.pm b/lib/Vyatta/IpTables/IpSet.pm index e38e731..1f8e25b 100755 --- a/lib/Vyatta/IpTables/IpSet.pm +++ b/lib/Vyatta/IpTables/IpSet.pm @@ -34,9 +34,10 @@ use strict; use warnings; my %fields = ( - _name => undef, - _type => undef, # vyatta group type, not ipset type - _debug => undef, + _name => undef, + _type => undef, # vyatta group type, not ipset type + _exists => undef, + _debug => undef, ); my %grouptype_hash = ( @@ -71,11 +72,13 @@ sub debug { sub exists { my ($self) = @_; + return 1 if defined $self->{_exists}; return 0 if ! defined $self->{_name}; my $func = (caller(0))[3]; my $cmd = "ipset -L $self->{_name}"; my $rc = system("$cmd > /dev/null &>2"); system("$logger [$func] [$cmd] = [$rc]") if defined $self->{_debug}; + $self->{_exists} = 1 if $rc eq 0; return $rc ? 0 : 1; } -- cgit v1.2.3