X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=mbd%2Fmbd.pl;fp=mbd%2Fmbd.pl;h=fe89d49edfcfa0810f0a8c3abc6770698d4bd812;hb=b06be4a65b35cf2b38e240edaaf1225d945c22ed;hp=7fcc8d8100a3a67e6e2f41bd763d797c684e4a06;hpb=79467e2953b1c64668151dd09a1421f06334c0d7;p=nms 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;