Commit 9867dcc7 authored by Franco Fichtner's avatar Franco Fichtner

services: more dynamic dns for dhcp #1023

(cherry picked from commit ae6b495e)
(cherry picked from commit 4dde1f08)
(cherry picked from commit e287db60)
parent 5cde5855
...@@ -432,6 +432,7 @@ function is_dhcpv4_server_enabled() ...@@ -432,6 +432,7 @@ function is_dhcpv4_server_enabled()
function services_dhcpdv4_configure() function services_dhcpdv4_configure()
{ {
global $config, $g; global $config, $g;
$need_ddns_updates = false; $need_ddns_updates = false;
$ddns_zones = array(); $ddns_zones = array();
...@@ -566,8 +567,8 @@ EOPP; ...@@ -566,8 +567,8 @@ EOPP;
$Iflist = get_configured_interface_list(); $Iflist = get_configured_interface_list();
foreach ($config['dhcpd'] as $dhcpif => $dhcpifconf) { foreach ($config['dhcpd'] as $dhcpif => $dhcpifconf) {
$newzone = array();
$ifcfg = $config['interfaces'][$dhcpif]; $ifcfg = $config['interfaces'][$dhcpif];
$newzone = array();
if (!isset($dhcpifconf['enable']) || !isset($Iflist[$dhcpif])) { if (!isset($dhcpifconf['enable']) || !isset($Iflist[$dhcpif])) {
continue; continue;
...@@ -599,7 +600,6 @@ EOPP; ...@@ -599,7 +600,6 @@ EOPP;
if (isset($dhcpifconf['ddnsupdate'])) { if (isset($dhcpifconf['ddnsupdate'])) {
$need_ddns_updates = true; $need_ddns_updates = true;
$newzone = array();
if (!empty($dhcpifconf['ddnsdomain'])) { if (!empty($dhcpifconf['ddnsdomain'])) {
$newzone['domain-name'] = $dhcpifconf['ddnsdomain']; $newzone['domain-name'] = $dhcpifconf['ddnsdomain'];
$dnscfg .= " ddns-domainname \"{$dhcpifconf['ddnsdomain']}\";\n"; $dnscfg .= " ddns-domainname \"{$dhcpifconf['ddnsdomain']}\";\n";
...@@ -953,18 +953,19 @@ EOD; ...@@ -953,18 +953,19 @@ EOD;
$dhcpdifs[] = get_real_interface($dhcpif); $dhcpdifs[] = get_real_interface($dhcpif);
if (!empty($newzone['domain-name'])) { if (!empty($newzone['domain-name'])) {
if ($need_ddns_updates) { if (isset($dhcpifconf['ddnsupdate'])) {
$newzone['dns-servers'] = array($dhcpifconf['ddnsdomainprimary']); $newzone['dns-servers'] = array($dhcpifconf['ddnsdomainprimary']);
} $newzone['ddnsdomainkeyname'] = $dhcpifconf['ddnsdomainkeyname'];
$newzone['ddnsdomainkey'] = $dhcpifconf['ddnsdomainkey'];
$ddns_zones[] = $newzone; $ddns_zones[] = $newzone;
} }
} }
}
if ($need_ddns_updates) { if ($need_ddns_updates) {
$dhcpdconf .= "ddns-update-style interim;\n"; $dhcpdconf .= "ddns-update-style interim;\n";
$dhcpdconf .= "update-static-leases on;\n"; $dhcpdconf .= "update-static-leases on;\n";
$dhcpdconf .= dhcpdkey($dhcpifconf); $dhcpdconf .= services_dhcpd_zones($ddns_zones);
$dhcpdconf .= dhcpdzones($ddns_zones, $dhcpifconf);
} }
/* write dhcpd.conf */ /* write dhcpd.conf */
...@@ -994,29 +995,18 @@ EOD; ...@@ -994,29 +995,18 @@ EOD;
return 0; return 0;
} }
function dhcpdkey($dhcpifconf) function services_dhcpd_zones($ddns_zones)
{
$dhcpdconf = "";
if ($dhcpifconf['ddnsdomainkeyname'] <> "" && $dhcpifconf['ddnsdomainkey'] <> "") {
$dhcpdconf .= "key {$dhcpifconf['ddnsdomainkeyname']} {\n";
$dhcpdconf .= " algorithm hmac-md5;\n";
$dhcpdconf .= " secret {$dhcpifconf['ddnsdomainkey']};\n";
$dhcpdconf .= "}\n";
}
return $dhcpdconf;
}
function dhcpdzones($ddns_zones, $dhcpifconf)
{ {
$dhcpdconf = ""; $dhcpdconf = '';
if (is_array($ddns_zones)) { if (is_array($ddns_zones)) {
$added_zones = array(); $added_zones = array();
$added_keys = array();
foreach ($ddns_zones as $zone) { foreach ($ddns_zones as $zone) {
if (!is_array($zone) || empty($zone) || !is_array($zone['dns-servers'])) { if (!is_array($zone) || empty($zone) || !is_array($zone['dns-servers'])) {
continue; continue;
} }
$primary = $zone['dns-servers'][0]; $primary = $zone['dns-servers'][0];
$secondary = empty($zone['dns-servers'][1]) ? "" : $zone['dns-servers'][1]; $secondary = empty($zone['dns-servers'][1]) ? "" : $zone['dns-servers'][1];
...@@ -1031,29 +1021,28 @@ function dhcpdzones($ddns_zones, $dhcpifconf) ...@@ -1031,29 +1021,28 @@ function dhcpdzones($ddns_zones, $dhcpifconf)
} }
// We don't need to add zones multiple times. // We don't need to add zones multiple times.
if ($zone['domain-name'] && !in_array($zone['domain-name'], $added_zones)) { foreach (array($zone['domain-name'], $zone['ptr-domain']) as $domain) {
$dhcpdconf .= "zone {$zone['domain-name']}. {\n"; if (!empty($domain) && !in_array($domain, $added_zones)) {
$dhcpdconf .= " primary {$primary};\n"; /* dhcpdconf2 is injected *after* the key */
$dhcpdconf2 = "zone {$domain}. {\n";
$dhcpdconf2 .= " primary {$primary};\n";
if (is_ipaddrv4($secondary)) { if (is_ipaddrv4($secondary)) {
$dhcpdconf .= " secondary {$secondary};\n"; $dhcpdconf2 .= " secondary {$secondary};\n";
}
if ($dhcpifconf['ddnsdomainkeyname'] <> "" && $dhcpifconf['ddnsdomainkey'] <> "") {
$dhcpdconf .= " key {$dhcpifconf['ddnsdomainkeyname']};\n";
} }
if (!empty($zone['ddnsdomainkeyname']) && !empty($zone['ddnsdomainkey'])) {
if (!in_array($zone['ddnsdomainkeyname'], $added_keys)) {
$dhcpdconf .= "key {$zone['ddnsdomainkeyname']} {\n";
$dhcpdconf .= " algorithm hmac-md5;\n";
$dhcpdconf .= " secret {$zone['ddnsdomainkey']};\n";
$dhcpdconf .= "}\n"; $dhcpdconf .= "}\n";
$added_zones[] = $zone['domain-name']; $added_keys[] = $zone['ddnsdomainkeyname'];
} }
if ($zone['ptr-domain'] && !in_array($zone['ptr-domain'], $added_zones)) { $dhcpdconf2 .= " key {$zone['ddnsdomainkeyname']};\n";
$dhcpdconf .= "zone {$zone['ptr-domain']} {\n";
$dhcpdconf .= " primary {$primary};\n";
if (is_ipaddrv4($secondary)) {
$dhcpdconf .= " secondary {$secondary};\n";
} }
if ($dhcpifconf['ddnsdomainkeyname'] <> "" && $dhcpifconf['ddnsdomainkey'] <> "") { $dhcpdconf2 .= "}\n";
$dhcpdconf .= " key {$dhcpifconf['ddnsdomainkeyname']};\n"; $dhcpdconf .= $dhcpdconf2;
$added_zones[] = $domain;
} }
$dhcpdconf .= "}\n";
$added_zones[] = $zone['ptr-domain'];
} }
} }
} }
...@@ -1197,13 +1186,13 @@ authoritative; ...@@ -1197,13 +1186,13 @@ authoritative;
EOD; EOD;
$dhcpdv6ifs = array(); $dhcpdv6ifs = array();
$dhcpv6num = 0; $ddns_zones = array();
$nsupdate = false; $nsupdate = false;
$dhcpv6num = 0;
foreach ($dhcpdv6cfg as $dhcpv6if => $dhcpv6ifconf) { foreach ($dhcpdv6cfg as $dhcpv6if => $dhcpv6ifconf) {
$ddns_zones = array();
$ifcfgv6 = $config['interfaces'][$dhcpv6if]; $ifcfgv6 = $config['interfaces'][$dhcpv6if];
$newzone = array();
if (!isset($dhcpv6ifconf['enable']) || !isset($Iflist[$dhcpv6if])) { if (!isset($dhcpv6ifconf['enable']) || !isset($Iflist[$dhcpv6if])) {
continue; continue;
...@@ -1222,10 +1211,13 @@ EOD; ...@@ -1222,10 +1211,13 @@ EOD;
} }
if (isset($dhcpv6ifconf['ddnsupdate'])) { if (isset($dhcpv6ifconf['ddnsupdate'])) {
if ($dhcpv6ifconf['ddnsdomain'] <> "") { if (!empty($dhcpv6ifconf['ddnsdomain'])) {
$dnscfgv6 .= " ddns-domainname \"{$dhcpv6ifconf['ddnsdomain']}\";\n"; $dnscfgv6 .= " ddns-domainname \"{$dhcpv6ifconf['ddnsdomain']}\";\n";
$newzone['domain-name'] = $dhcpv6ifconf['ddnsdomain'];
} else {
$newzone['domain-name'] = $config['system']['domain'];
} }
$dnscfgv6 .= " ddns-update-style interim;\n";
$nsupdate = true; $nsupdate = true;
} }
...@@ -1245,13 +1237,6 @@ EOD; ...@@ -1245,13 +1237,6 @@ EOD;
} }
} }
if (!empty($dhcpv6ifconf['domain'])) {
$newzone = array();
$newzone['domain-name'] = $dhcpv6ifconf['domain'];
$newzone['dns-servers'][] = $dhcpv6ifconf['ddnsdomainprimary'];
$ddns_zones[] = $newzone;
}
if (is_ipaddrv6($ifcfgipv6)) { if (is_ipaddrv6($ifcfgipv6)) {
$dhcpdv6conf .= "subnet6 {$subnetv6}/{$ifcfgsnv6}"; $dhcpdv6conf .= "subnet6 {$subnetv6}/{$ifcfgsnv6}";
} else { } else {
...@@ -1349,9 +1334,13 @@ EOD; ...@@ -1349,9 +1334,13 @@ EOD;
} }
} }
if (!empty($dhcpv6ifconf['domain'])) { if (!empty($newzone['domain-name'])) {
$dhcpdv6conf .= dhcpdkey($dhcpv6ifconf); if (isset($dhcpv6ifconf['ddnsupdate'])) {
$dhcpdv6conf .= dhcpdzones($ddns_zones, $dhcpv6ifconf); $newzone['dns-servers'] = array($dhcpv6ifconf['ddnsdomainprimary']);
$newzone['ddnsdomainkeyname'] = $dhcpv6ifconf['ddnsdomainkeyname'];
$newzone['ddnsdomainkey'] = $dhcpv6ifconf['ddnsdomainkey'];
$ddns_zones[] = $newzone;
}
} }
if (isset($config['dhcpdv6'][$dhcpv6if]['ramode']) && $config['dhcpdv6'][$dhcpv6if]['ramode'] <> "unmanaged") { if (isset($config['dhcpdv6'][$dhcpv6if]['ramode']) && $config['dhcpdv6'][$dhcpv6if]['ramode'] <> "unmanaged") {
...@@ -1374,6 +1363,7 @@ EOD; ...@@ -1374,6 +1363,7 @@ EOD;
if ($nsupdate) { if ($nsupdate) {
$dhcpdv6conf .= "ddns-update-style interim;\n"; $dhcpdv6conf .= "ddns-update-style interim;\n";
$dhcpdv6conf .= services_dhcpd_zones($ddns_zones);
} else { } else {
$dhcpdv6conf .= "ddns-update-style none;\n"; $dhcpdv6conf .= "ddns-update-style none;\n";
} }
......
...@@ -1126,13 +1126,12 @@ include("head.inc"); ...@@ -1126,13 +1126,12 @@ include("head.inc");
</td> </td>
</tr> </tr>
<tr> <tr>
<td>&nbsp;</td> <td colspan="2">
<td> <p><?=gettext("Note:");?><br /> <?= sprintf(gettext('The DNS servers entered in %sSystem: ' .
<?=sprintf(gettext("The DNS servers entered in %sSystem: " . 'General setup%s (or the %sDNS forwarder%s, if enabled), ' .
"General setup%s (or the %sDNS forwarder%s, if enabled), will be assigned to clients by the DHCP server."),'<a href="system_general.php">','</a>','<a href="services_dnsmasq.php">','</a>'); ?><br /> 'will be assigned to clients by the DHCP server.'),
<br /> '<a href="system_general.php">', '</a>',
<?=sprintf(gettext("The DHCP lease table can be viewed on the %sStatus: DHCP leases%s page."),'<a href="status_dhcp_leases.php">','</a>') ?><br /> '<a href="services_dnsmasq.php">','</a>'); ?>
</p>
</td> </td>
</tr> </tr>
</table> </table>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment