From b06be4a65b35cf2b38e240edaaf1225d945c22ed Mon Sep 17 00:00:00 2001 From: root Date: Wed, 4 Apr 2007 13:09:03 +0200 Subject: [PATCH] Add a cache to MBD. --- mbd/mbd.pl | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) 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; -- 2.39.2