Skip to content

Commit

Permalink
dhcp: address issue found by @marjohn56
Browse files Browse the repository at this point in the history
PR: #2077

(cherry picked from commit c62f01f)
(cherry picked from commit 018bea3)
(cherry picked from commit 639bc74)
(cherry picked from commit ceedb10)
  • Loading branch information
fichtner committed Jan 12, 2018
1 parent 43a64ca commit 3914236
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion plist
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@
/usr/local/opnsense/scripts/OPNsense/CaptivePortal/sql/init.sql
/usr/local/opnsense/scripts/OPNsense/CaptivePortal/strip_template.py
/usr/local/opnsense/scripts/dhcp/get_leases.py
/usr/local/opnsense/scripts/dhcp/prefixes.php
/usr/local/opnsense/scripts/dns/unbound_dhcpd.py
/usr/local/opnsense/scripts/filter/delete_table.py
/usr/local/opnsense/scripts/filter/download_geoip.py
Expand Down Expand Up @@ -950,7 +951,6 @@
/usr/local/sbin/ppp-linkup
/usr/local/sbin/ppp-log-uptime.sh
/usr/local/sbin/ppp-uptime.sh
/usr/local/sbin/prefixes.php
/usr/local/wizard/openvpn.xml
/usr/local/wizard/system.xml
/usr/local/www/carp_status.php
Expand Down
5 changes: 4 additions & 1 deletion src/etc/inc/services.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,10 @@ EOD;
/* fire up dhcpd in a chroot */
if (count($dhcpdv6ifs) > 0) {
mwexec('/usr/local/sbin/dhcpd -6 -user dhcpd -group dhcpd -chroot /var/dhcpd -cf /etc/dhcpdv6.conf -pf /var/run/dhcpdv6.pid ' . join(' ', $dhcpdv6ifs));
mwexec('/usr/local/sbin/dhcpleases6 -c "/usr/local/bin/php -f /usr/local/sbin/prefixes.php|/bin/sh" -l /var/dhcpd/var/db/dhcpd6.leases');
mwexecf('/usr/local/sbin/dhcpleases6 -c %s -l %s', array(
'/usr/local/sbin/configctl dhcpd update prefixes',
'/var/dhcpd/var/db/dhcpd6.leases',
));
}

if ($verbose) {
Expand Down
11 changes: 6 additions & 5 deletions src/sbin/prefixes.php → src/opnsense/scripts/dhcp/prefixes.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/usr/local/bin/php
<?php

require_once 'util.inc';

$leases_file = "/var/dhcpd/var/db/dhcpd6.leases";
if (!file_exists($leases_file)) {
exit(1);
}

$duid_arr = array();
foreach (file($leases_file) as $line) {
// echo "$line";
if (preg_match("/^(ia-[np][ad])[ ]+\"(.*?)\"/i ", $line, $duidmatch)) {
$type = $duidmatch[1];
$duid = $duidmatch[2];
Expand Down Expand Up @@ -57,10 +59,10 @@
array_shift($duid_arr);
}

// echo "add routes\n";
if (count($routes) > 0) {
foreach ($routes as $address => $prefix) {
echo "/sbin/route change -inet6 {$prefix} {$address}\n";
mwexecf('/sbin/route delete -inet6 %s %s', array($prefix, $address), true);
mwexecf('/sbin/route add -inet6 %s %s', array($prefix, $address));
}
}

Expand All @@ -86,11 +88,10 @@
array_shift($clog);
}

// echo "remove routes\n";
if (count($expires) > 0) {
foreach ($expires as $prefix) {
if (isset($prefix['prefix'])) {
echo "/sbin/route delete -inet6 {$prefix['prefix']}\n";
mwexecf('/sbin/route delete -inet6 %s', array($prefix['prefix']), true);
}
}
}
6 changes: 6 additions & 0 deletions src/opnsense/service/conf/actions.d/actions_dhcpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ command:/usr/local/opnsense/scripts/dhcp/get_leases.py /inactive %s
parameters:%s
type:script_output
message:list dhcp leases %s

[update.prefixes]
command:/usr/local/opnsense/scripts/dhcp/prefixes.php
parameters:
type:script
message:update IPv6 prefixes

0 comments on commit 3914236

Please sign in to comment.