diff options
author | smos <seth.mos@dds.nl> | 2012-04-06 20:08:09 +0200 |
---|---|---|
committer | smos <seth.mos@dds.nl> | 2012-04-06 20:08:09 +0200 |
commit | 092462dc10d1a429d14fa9c783307e4be8b84910 (patch) | |
tree | 08c38a796ca83b4fe55dce5fe834608c30c7919b /usr | |
parent | 0416d9a0eb3a0bee08fa09d151344452f288bdef (diff) | |
download | pfsense-092462dc10d1a429d14fa9c783307e4be8b84910.zip pfsense-092462dc10d1a429d14fa9c783307e4be8b84910.tar.gz |
Add a dhcpleases monitor to the DHCPv6 server which will trigger automatic creation of routes into the routing table so that prefix delegation will just work.
Redmine ticket #2347
Diffstat (limited to 'usr')
-rw-r--r-- | usr/local/sbin/prefixes.php | 85 |
1 files changed, 85 insertions, 0 deletions
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"; +} + +?> |