1
|
<?php
|
2
|
|
3
|
$leases_file = "/var/dhcpd/var/db/dhcpd6.leases";
|
4
|
if(!file_exists($leases_file)) {
|
5
|
exit(1);
|
6
|
}
|
7
|
|
8
|
foreach(file($leases_file) as $line) {
|
9
|
// echo "$line";
|
10
|
if(preg_match("/^(ia-[np][ad])[ ]+\"(.*?)\"/i ", $line, $duidmatch)) {
|
11
|
$type = $duidmatch[1];
|
12
|
$duid = $duidmatch[2];
|
13
|
continue;
|
14
|
}
|
15
|
|
16
|
/* is it active? otherwise just discard */
|
17
|
if(preg_match("/binding state active/i", $line, $activematch)) {
|
18
|
$active = true;
|
19
|
continue;
|
20
|
}
|
21
|
|
22
|
if(preg_match("/iaaddr[ ]+([0-9a-f:]+)[ ]+/i", $line, $addressmatch)) {
|
23
|
$ia_na = $addressmatch[1];
|
24
|
continue;
|
25
|
}
|
26
|
|
27
|
if(preg_match("/iaprefix[ ]+([0-9a-f:\/]+)[ ]+/i", $line, $prefixmatch)) {
|
28
|
$ia_pd = $prefixmatch[1];
|
29
|
continue;
|
30
|
}
|
31
|
|
32
|
/* closing bracket */
|
33
|
if(preg_match("/^}/i ", $line)) {
|
34
|
switch($type) {
|
35
|
case "ia-na":
|
36
|
$duid_arr[$duid][$type] = $ia_na;
|
37
|
break;
|
38
|
case "ia-pd":
|
39
|
$duid_arr[$duid][$type] = $ia_pd;
|
40
|
break;
|
41
|
}
|
42
|
unset($type);
|
43
|
unset($duid);
|
44
|
unset($active);
|
45
|
unset($ia_na);
|
46
|
unset($ia_pd);
|
47
|
continue;
|
48
|
}
|
49
|
}
|
50
|
|
51
|
$routes = array();
|
52
|
foreach ($duid_arr as $entry) {
|
53
|
if($entry['ia-pd'] <> "") {
|
54
|
$routes[$entry['ia-na']] = $entry['ia-pd'];
|
55
|
}
|
56
|
array_shift($duid_arr);
|
57
|
}
|
58
|
|
59
|
// echo "add routes\n";
|
60
|
if(count($routes) > 0) {
|
61
|
foreach ($routes as $address => $prefix) {
|
62
|
echo "/sbin/route change -inet6 {$prefix} {$address}\n";
|
63
|
}
|
64
|
}
|
65
|
|
66
|
/* get clog from dhcpd */
|
67
|
$dhcpdlogfile = "/var/log/dhcpd.log";
|
68
|
$clog = array();
|
69
|
if(file_exists(dhcpdlogfile))
|
70
|
exec("clog $dhcpdlogfile", $clog, $ret);
|
71
|
|
72
|
if($ret > 0)
|
73
|
$clog = array();
|
74
|
|
75
|
$expires = array();
|
76
|
foreach($clog as $line) {
|
77
|
if(preg_match("/releases[ ]+prefix[ ]+([0-9a-f:]+\/[0-9]+)/i", $line, $expire)) {
|
78
|
if(in_array($expire[1], $routes))
|
79
|
continue;
|
80
|
$expires[$expire[1]] = $expire[1];
|
81
|
}
|
82
|
array_shift($clog);
|
83
|
}
|
84
|
|
85
|
// echo "remove routes\n";
|
86
|
if(count($expires) > 0) {
|
87
|
foreach ($expires as $prefix) {
|
88
|
echo "/sbin/route delete -inet6 {$prefix['prefix']}\n";
|
89
|
array_shift($expires);
|
90
|
}
|
91
|
}
|
92
|
|
93
|
?>
|