]> git.sesse.net Git - nms/blobdiff - mbd/mbd.pl
Various MBD survey changes.
[nms] / mbd / mbd.pl
index 4843b0bb60cfea9a62388340e854749a8a3b3d4a..6a7b767ca184053cec8f58ae0cecebc1855957ce 100644 (file)
@@ -77,8 +77,8 @@ while (1) {
        for my $sport (keys %active_surveys) {
                my $age = Time::HiRes::tv_interval($active_surveys{$sport}{start}, $now);
                if ($age > $Config::survey_time && $active_surveys{$sport}{active}) {
-                       print "Survey for port " . $active_surveys{$sport}{dport} . ": " .
-                               $active_surveys{$sport}{num} . " active servers.\n";
+                       print "Survey for '" . $Config::access_list[$active_surveys{$sport}{entry}]->{name} . "'/" .
+                               $active_surveys{$sport}{dport} . ": " .  $active_surveys{$sport}{num} . " active servers.\n";
                        $active_surveys{$sport}{active} = 0;
                }
                if ($age > $Config::survey_time * 3.0) {
@@ -124,7 +124,10 @@ while (1) {
                # We don't get the packet's destination address, but I guess this should do...
                # Check against the ACL.
                my $pass = 0;
+               my $entry = -1;
                for my $rule (@Config::access_list) {
+                       ++$entry;
+
                        next unless (mbd::match_ranges($dport, $rule->{'ports'}));
                        next unless (mbd::match_ranges($size, $rule->{'sizes'}));
 
@@ -148,8 +151,8 @@ while (1) {
                # The packet is OK! Do we already have a recent enough survey
                # for this port, or should we use this packet?
                my $survey = 1;
-               if (exists($last_survey{$dport})) {
-                       my $age = Time::HiRes::tv_interval($last_survey{$dport}, $now);
+               if (exists($last_survey{$entry . "/" . $dport})) {
+                       my $age = Time::HiRes::tv_interval($last_survey{$entry . "/" . $dport}, $now);
                        if ($age < $Config::survey_freq) {
                                $survey = 0;
                        }
@@ -157,25 +160,28 @@ while (1) {
 
                # New survey; find an unused port
                my $survey_sport;
-               for my $port ($Config::survey_port_low..$Config::survey_port_high) {
-                       if (!exists($active_surveys{$port})) {
-                               $survey_sport = $port;
-
-                               $active_surveys{$port} = {
-                                       start => $now,
-                                       active => 1,
-                                       dport => $dport,
-                                       num => 0
-                               };
-                               $last_survey{$dport} = $now;
-
-                               last;
+               if ($survey) {
+                       for my $port ($Config::survey_port_low..$Config::survey_port_high) {
+                               if (!exists($active_surveys{$port})) {
+                                       $survey_sport = $port;
+
+                                       $active_surveys{$port} = {
+                                               start => $now,
+                                               active => 1,
+                                               dport => $dport,
+                                               entry => $entry,
+                                               num => 0
+                                       };
+                                       $last_survey{$entry . "/" . $dport} = $now;
+
+                                       last;
+                               }
                        }
-               }
 
-               if (!defined($survey_sport)) {
-                       print "WARNING: no free survey source ports, not surveying.\n";
-                       $survey = 0;
+                       if (!defined($survey_sport)) {
+                               print "WARNING: no free survey source ports, not surveying.\n";
+                               $survey = 0;
+                       }
                }
 
                my $num_nets = 0;