diff options
author | Stig Thormodsrud <stig@io.vyatta.com> | 2009-02-13 15:22:10 -0800 |
---|---|---|
committer | Stig Thormodsrud <stig@io.vyatta.com> | 2009-02-13 15:22:10 -0800 |
commit | 4d030e8c3c0f289de8471b91bc6b789592254b46 (patch) | |
tree | fea2a3e48f1121b351f2e5152088ab66c3f73903 /lib/Vyatta/IpTables | |
parent | de14ea1af63db350e7174f75c9ace4fb13ded6bd (diff) | |
download | vyatta-cfg-firewall-4d030e8c3c0f289de8471b91bc6b789592254b46.tar.gz vyatta-cfg-firewall-4d030e8c3c0f289de8471b91bc6b789592254b46.zip |
Cache exists() to reduce calls to external /usr/sbin/ipset.
Diffstat (limited to 'lib/Vyatta/IpTables')
-rwxr-xr-x | lib/Vyatta/IpTables/IpSet.pm | 9 |
1 files changed, 6 insertions, 3 deletions
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; } |