From 2fb056d81ae0a45bea2c759b8ce3079441cd4eef Mon Sep 17 00:00:00 2001 From: Seth Mos Date: Wed, 4 May 2011 10:58:40 +0200 Subject: More DHCPv6 server fixes, split the function out into seperate v4 and v6. Make the router advertisement stand alone on the dhcp server page. --- usr/local/www/services_dhcpv6.php | 158 +++++++++++--------------------------- 1 file changed, 44 insertions(+), 114 deletions(-) (limited to 'usr/local/www/services_dhcpv6.php') diff --git a/usr/local/www/services_dhcpv6.php b/usr/local/www/services_dhcpv6.php index ee03adb..d05839d 100644 --- a/usr/local/www/services_dhcpv6.php +++ b/usr/local/www/services_dhcpv6.php @@ -56,52 +56,6 @@ if(!$g['services_dhcp_server_enable']) { */ ini_set("memory_limit","64M"); -/* This function will remove entries from dhcpd.leases that would otherwise - * overlap with static DHCP reservations. If we don't clean these out, - * then DHCP will print a warning in the logs about a duplicate lease - */ -function dhcp_clean_leases() { - global $g, $config; - $leasesfile = "{$g['dhcpd_chroot_path']}/var/db/dhcpdv6.leases"; - if (!file_exists($leasesfile)) - return; - /* Build list of static MACs */ - $staticmacs = array(); - foreach($config['interfaces'] as $ifname => $ifarr) - if (is_array($config['dhcpdv6'][$ifname]['staticmap'])) - foreach($config['dhcpdv6'][$ifname]['staticmap'] as $static) - $staticmacs[] = $static['mac']; - /* Read existing leases */ - $leases_contents = explode("\n", file_get_contents($leasesfile)); - $newleases_contents = array(); - $i=0; - while ($i < count($leases_contents)) { - /* Find a lease definition */ - if (substr($leases_contents[$i], 0, 6) == "lease ") { - $templease = array(); - $thismac = ""; - /* Read to the end of the lease declaration */ - do { - if (substr($leases_contents[$i], 0, 20) == " hardware ethernet ") - $thismac = substr($leases_contents[$i], 20, 17); - $templease[] = $leases_contents[$i]; - $i++; - } while ($leases_contents[$i-1] != "}"); - /* Check for a matching MAC address and if not present, keep it. */ - if (! in_array($thismac, $staticmacs)) - $newleases_contents = array_merge($newleases_contents, $templease); - } else { - /* It's a line we want to keep, copy it over. */ - $newleases_contents[] = $leases_contents[$i]; - $i++; - } - } - /* Write out the new leases file */ - $fd = fopen($leasesfile, 'w'); - fwrite($fd, implode("\n", $newleases_contents)); - fclose($fd); -} - $if = $_GET['if']; if ($_POST['if']) $if = $_POST['if']; @@ -148,7 +102,6 @@ if (is_array($config['dhcpdv6'][$if])){ list($pconfig['dns1'],$pconfig['dns2']) = $config['dhcpdv6'][$if]['dnsserver']; $pconfig['enable'] = isset($config['dhcpdv6'][$if]['enable']); $pconfig['denyunknown'] = isset($config['dhcpdv6'][$if]['denyunknown']); - $pconfig['staticarp'] = isset($config['dhcpdv6'][$if]['staticarp']); $pconfig['ddnsdomain'] = $config['dhcpdv6'][$if]['ddnsdomain']; $pconfig['ddnsupdate'] = isset($config['dhcpdv6'][$if]['ddnsupdate']); list($pconfig['ntp1'],$pconfig['ntp2']) = $config['dhcpdv6'][$if]['ntpserver']; @@ -193,7 +146,7 @@ function is_inrange($test, $start, $end) { return false; } -$modes = array("unmanaged" => "Unmanaged", "managed" => "Managed", "assist" => "Assisted"); +$advertise_modes = array("disabled" => "Disabled", "unmanaged" => "Unmanaged", "managed" => "Managed", "assist" => "Assisted"); if ($_POST) { @@ -263,9 +216,6 @@ if ($_POST) { foreach ($a_maps as $map) if (empty($map['ipaddrv6'])) $noip = true; - if ($_POST['staticarp'] && $noip) - $input_errors[] = "Cannot enable static ARP when you have static map entries without IP addresses. Ensure all static maps have IPv6 addresses and try again."; - if (!$input_errors) { /* make sure the range lies within the current subnet */ /* FIXME change for ipv6 subnet */ @@ -334,7 +284,6 @@ if ($_POST) { $config['dhcpdv6'][$if]['domainsearchlist'] = $_POST['domainsearchlist']; $config['dhcpdv6'][$if]['denyunknown'] = ($_POST['denyunknown']) ? true : false; $config['dhcpdv6'][$if]['enable'] = ($_POST['enable']) ? true : false; - $config['dhcpdv6'][$if]['staticarp'] = ($_POST['staticarp']) ? true : false; $config['dhcpdv6'][$if]['ddnsdomain'] = $_POST['ddnsdomain']; $config['dhcpdv6'][$if]['ddnsupdate'] = ($_POST['ddnsupdate']) ? true : false; @@ -363,8 +312,8 @@ if ($_POST) { $retvaldhcp = 0; $retvaldns = 0; /* Stop DHCPv6 so we can cleanup leases */ - killbyname("dhcpdv6"); - dhcp_clean_leases(); + killbyname("dhcpd -6"); + // dhcp_clean_leases(); /* dnsmasq_configure calls dhcpd_configure */ /* no need to restart dhcpd twice */ if (isset($config['dnsmasq']['regdhcpstatic'])) { @@ -399,7 +348,7 @@ if ($_GET['act'] == "del") { } $pgtitle = array(gettext("Services"),gettext("DHCPv6 server")); -$statusurl = "status_dhcp_leases.php"; +$statusurl = "status_dhcpv6_leases.php"; $logurl = "diag_logs_dhcp.php"; include("head.inc"); @@ -419,30 +368,30 @@ include("head.inc");