summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--etc/inc/services.inc2
-rw-r--r--usr/local/sbin/prefixes.php85
2 files changed, 87 insertions, 0 deletions
diff --git a/etc/inc/services.inc b/etc/inc/services.inc
index e41f5ed..b5f84f4 100644
--- a/etc/inc/services.inc
+++ b/etc/inc/services.inc
@@ -264,6 +264,7 @@ function services_dhcpd_configure() {
fwrite($fd, "cp /lib/libc.so.* {$g['dhcpd_chroot_path']}/lib/\n");
fwrite($fd, "cp /usr/local/sbin/dhcpd {$g['dhcpd_chroot_path']}/usr/local/sbin/\n");
fwrite($fd, "chmod a+rx {$g['dhcpd_chroot_path']}/usr/local/sbin/dhcpd\n");
+
if(!trim($status))
fwrite($fd, "mount -t devfs devfs {$g['dhcpd_chroot_path']}/dev\n");
fclose($fd);
@@ -1005,6 +1006,7 @@ EOD;
if(count($dhcpdv6ifs) > 0) {
mwexec("/usr/local/sbin/dhcpd -6 -user dhcpd -group _dhcp -chroot {$g['dhcpd_chroot_path']} -cf /etc/dhcpdv6.conf -pf {$g['varrun_path']}/dhcpdv6.pid " .
join(" ", $dhcpdv6ifs));
+ mwexec("/usr/local/sbin/dhcpleases -c "/usr/local/bin/php -f /usr/local/sbin/prefixes.php|/bin/sh" -p {$g['dhcpd_chroot_path']}/var/run/dhcpd6.pid -l {$g['dhcpd_chroot_path']}/var/db/dhcpd6.leases");
}
if ($g['booting']) {
diff --git a/usr/local/sbin/prefixes.php b/usr/local/sbin/prefixes.php
new file mode 100644
index 0000000..4a1f7e0
--- /dev/null
+++ b/usr/local/sbin/prefixes.php
@@ -0,0 +1,85 @@
+<?php
+
+$leases_file = "/var/dhcpd/var/db/dhcpd6.leases";
+$leasefile = file($leases_file);
+
+foreach($leasefile as $line) {
+ // echo "$line";
+ if(preg_match("/^(ia-[np][ad])[ ]+\"(.*?)\"/i ", $line, $duidmatch)) {
+ $type = $duidmatch[1];
+ $duid = $duidmatch[2];
+ continue;
+ }
+
+ /* is it active? otherwise just discard */
+ if(preg_match("/binding state active/i", $line, $activematch)) {
+ $active = true;
+ continue;
+ }
+
+ if(preg_match("/iaaddr[ ]+([0-9a-f:]+)[ ]+/i", $line, $addressmatch)) {
+ $ia_na = $addressmatch[1];
+ continue;
+ }
+
+ if(preg_match("/iaprefix[ ]+([0-9a-f:\/]+)[ ]+/i", $line, $prefixmatch)) {
+ $ia_pd = $prefixmatch[1];
+ continue;
+ }
+
+ /* closing bracket */
+ if(preg_match("/^}/i ", $line)) {
+ switch($type) {
+ case "ia-na":
+ $duid_arr[$duid][$type] = $ia_na;
+ break;
+ case "ia-pd":
+ $duid_arr[$duid][$type] = $ia_pd;
+ break;
+ }
+ unset($type);
+ unset($duid);
+ unset($active);
+ unset($ia_na);
+ unset($ia_pd);
+ continue;
+ }
+ array_shift($leasefile);
+}
+
+$routes = array();
+foreach ($duid_arr as $entry) {
+ if($entry['ia-pd'] <> "") {
+ $routes[$entry['ia-na']] = $entry['ia-pd'];
+ }
+}
+
+// echo "add routes\n";
+foreach ($routes as $address => $prefix) {
+ echo "/sbin/route change -inet6 {$prefix} {$address}\n";
+}
+
+/* get clog from dhcpd */
+$dhcpdlogfile = "/var/log/dhcpd.log";
+$clog = array();
+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];
+ }
+ array_shift($clog);
+}
+
+// echo "remove routes\n";
+foreach ($expires as $prefix) {
+ echo "/sbin/route delete -inet6 {$prefix['prefix']}\n";
+}
+
+?>
OpenPOWER on IntegriCloud