From: root Date: Wed, 4 Apr 2007 11:09:03 +0000 (+0200) Subject: Add a cache to MBD. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=b06be4a65b35cf2b38e240edaaf1225d945c22ed;p=nms Add a cache to MBD. --- diff --git a/mbd/mbd.pl b/mbd/mbd.pl index 7fcc8d8..fe89d49 100644 --- a/mbd/mbd.pl +++ b/mbd/mbd.pl @@ -16,6 +16,28 @@ sub fhbits { return $bits; } +my %cidrcache = (); +sub cache_cidrlookup { + my ($addr, $net) = @_; + my $key = $addr . " " . $net; + + if (!exists($cidrcache{$key})) { + $cidrcache{$key} = Net::CIDR::cidrlookup($addr, $net); + } + return $cidrcache{$key}; +} + +my %rangecache = (); +sub cache_cidrrange { + my ($net) = @_; + + if (!exists($rangecache{$net})) { + ($rangecache{$net}) = Net::CIDR::cidr2range($net); + } + + return $rangecache{$net}; +} + open LOG, ">>", "mbd.log"; my @ports = mbd::find_all_ports(); @@ -73,9 +95,9 @@ while (1) { next unless $pass; for my $net (@Config::networks) { - next if (Net::CIDR::cidrlookup(inet_ntoa($saddr), $net)); + next if (cache_cidrlookup(inet_ntoa($saddr), $net)); - my ($range) = Net::CIDR::cidr2range($net); + my ($range) = cache_cidrrange($net); $range =~ /-(.*?)$/; my $broadcast = $1;