summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErmal LUÇI <eri@pfsense.org>2015-01-08 23:57:47 +0100
committerErmal LUÇI <eri@pfsense.org>2015-01-08 23:58:02 +0100
commitd97dd424371014e766f63cbbffa0e92e0748f38e (patch)
treec53c7b5b6518b2f188366c9b1ee9dc97dfc628eb
parentac8f75f1e046b32c88693ff0c6854b7f641cf206 (diff)
downloadpfsense-d97dd424371014e766f63cbbffa0e92e0748f38e.zip
pfsense-d97dd424371014e766f63cbbffa0e92e0748f38e.tar.gz
Make this code less memory hungry and fix route command generation
-rw-r--r--usr/local/sbin/prefixes.php36
1 files changed, 17 insertions, 19 deletions
diff --git a/usr/local/sbin/prefixes.php b/usr/local/sbin/prefixes.php
index 7c924c8..85cb496 100644
--- a/usr/local/sbin/prefixes.php
+++ b/usr/local/sbin/prefixes.php
@@ -5,10 +5,12 @@ if(!file_exists($leases_file)) {
exit(1);
}
+$fd = fopen($leases_file, 'r');
+
$duid_arr = array();
-foreach(file($leases_file) as $line) {
+while (( $line = fgets($fd, 4096)) !== false) {
// echo "$line";
- if(preg_match("/^(ia-[np][ad])[ ]+\"(.*?)\"/i ", $line, $duidmatch)) {
+ if(preg_match("/^(ia-[np][ad])[ ]+\"(.*?)\"/i", $line, $duidmatch)) {
$type = $duidmatch[1];
$duid = $duidmatch[2];
continue;
@@ -31,7 +33,7 @@ foreach(file($leases_file) as $line) {
}
/* closing bracket */
- if(preg_match("/^}/i ", $line)) {
+ if(preg_match("/^}/i", $line)) {
switch($type) {
case "ia-na":
$duid_arr[$duid][$type] = $ia_na;
@@ -48,13 +50,13 @@ foreach(file($leases_file) as $line) {
continue;
}
}
+fclose($fd);
$routes = array();
foreach ($duid_arr as $entry) {
- if($entry['ia-pd'] <> "") {
+ if(!empty($entry['ia-pd'])) {
$routes[$entry['ia-na']] = $entry['ia-pd'];
}
- array_shift($duid_arr);
}
// echo "add routes\n";
@@ -66,28 +68,24 @@ if(count($routes) > 0) {
/* get clog from dhcpd */
$dhcpdlogfile = "/var/log/dhcpd.log";
-$clog = array();
-if(file_exists($dhcpdlogfile))
- exec("clog $dhcpdlogfile", $clog, $ret);
-
-if($ret > 0)
- $clog = array();
-
$expires = array();
-foreach($clog as $line) {
- if(preg_match("/releases[ ]+prefix[ ]+([0-9a-f:]+\/[0-9]+)/i", $line, $expire)) {
- if(in_array($expire[1], $routes))
- continue;
- $expires[$expire[1]] = $expire[1];
+if(file_exists($dhcpdlogfile)) {
+ $fd = popen("clog $dhcpdlogfile", 'r');
+ while (($line = fgets($fd)) !== false) {
+ //echo $line;
+ if(preg_match("/releases[ ]+prefix[ ]+([0-9a-f:]+\/[0-9]+)/i", $line, $expire)) {
+ if(in_array($expire[1], $routes))
+ continue;
+ $expires[$expire[1]] = $expire[1];
+ }
}
- array_shift($clog);
+ pclose($fd);
}
// echo "remove routes\n";
if(count($expires) > 0) {
foreach ($expires as $prefix) {
echo "/sbin/route delete -inet6 {$prefix['prefix']}\n";
- array_shift($expires);
}
}
OpenPOWER on IntegriCloud