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