Generalise arp discovery cache; move to common

This commit is contained in:
Paul Gear
2015-07-20 14:02:16 +10:00
parent ceeb362e40
commit 40a1cef050
3 changed files with 24 additions and 27 deletions

View File

@@ -800,6 +800,28 @@ function enable_graphs($device, &$graph_enable)
enable_os_graphs($device['os'], $graph_enable); enable_os_graphs($device['os'], $graph_enable);
} }
//
// maintain a simple cache of objects
//
function object_add_cache($section, $obj)
{
global $object_cache;
$object_cache[$section][$obj] = true;
}
function object_is_cached($section, $obj)
{
global $object_cache;
if (array_key_exists($obj, $object_cache)) {
return $object_cache[$obj];
}
else {
return false;
}
}
/** /**
* Checks if config allows us to ping this device * Checks if config allows us to ping this device
* $attribs contains an array of all of this devices * $attribs contains an array of all of this devices
@@ -812,9 +834,6 @@ function can_ping_device($attribs) {
if ($config['icmp_check'] === true && $attribs['override_icmp_disable'] != "true") { if ($config['icmp_check'] === true && $attribs['override_icmp_disable'] != "true") {
return true; return true;
} }
else {
return false;
}
} // end can_ping_device } // end can_ping_device
/** /**

View File

@@ -60,12 +60,12 @@ foreach (dbFetchRows($sql, array($deviceid)) as $entry) {
} }
// Attempt discovery of each IP only once per run. // Attempt discovery of each IP only once per run.
if (arp_discovery_is_cached($ip)) { if (object_is_cached('arp_discovery', $ip)) {
echo '.'; echo '.';
continue; continue;
} }
arp_discovery_add_cache($ip); object_add_cache('arp_discovery', $ip);
$name = gethostbyaddr($ip); $name = gethostbyaddr($ip);
echo '+'; echo '+';

View File

@@ -704,25 +704,3 @@ function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen
}//end if }//end if
}//end discover_process_ipv6() }//end discover_process_ipv6()
// maintain a simple cache of seen IPs during ARP discovery
function arp_discovery_add_cache($ip) {
global $arp_discovery;
$arp_discovery[$ip] = true;
}//end arp_discovery_add_cache()
function arp_discovery_is_cached($ip) {
global $arp_discovery;
if (array_key_exists($ip, $arp_discovery)) {
return $arp_discovery[$ip];
}
else {
return false;
}
}//end arp_discovery_is_cached()