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()
function services_dhcpdv4_configure()
{
global $config, $g;
$need_ddns_updates = false;
$ddns_zones = array();
......@@ -566,8 +567,8 @@ EOPP;
$Iflist = get_configured_interface_list();
foreach ($config['dhcpd'] as $dhcpif => $dhcpifconf) {
$newzone = array();
$ifcfg = $config['interfaces'][$dhcpif];
$newzone = array();
if (!isset($dhcpifconf['enable']) || !isset($Iflist[$dhcpif])) {
continue;
......@@ -599,7 +600,6 @@ EOPP;
if (isset($dhcpifconf['ddnsupdate'])) {
$need_ddns_updates = true;
$newzone = array();
if (!empty($dhcpifconf['ddnsdomain'])) {
$newzone['domain-name'] = $dhcpifconf['ddnsdomain'];
$dnscfg .= " ddns-domainname \"{$dhcpifconf['ddnsdomain']}\";\n";
......@@ -953,18 +953,19 @@ EOD;
$dhcpdifs[] = get_real_interface($dhcpif);
if (!empty($newzone['domain-name'])) {
if ($need_ddns_updates) {
if (isset($dhcpifconf['ddnsupdate'])) {
$newzone['dns-servers'] = array($dhcpifconf['ddnsdomainprimary']);
}
$newzone['ddnsdomainkeyname'] = $dhcpifconf['ddnsdomainkeyname'];
$newzone['ddnsdomainkey'] = $dhcpifconf['ddnsdomainkey'];
$ddns_zones[] = $newzone;
}
}
}
if ($need_ddns_updates) {
$dhcpdconf .= "ddns-update-style interim;\n";
$dhcpdconf .= "update-static-leases on;\n";
$dhcpdconf .= dhcpdkey($dhcpifconf);
$dhcpdconf .= dhcpdzones($ddns_zones, $dhcpifconf);
$dhcpdconf .= services_dhcpd_zones($ddns_zones);
}
/* write dhcpd.conf */
......@@ -994,29 +995,18 @@ EOD;
return 0;
}
function dhcpdkey($dhcpifconf)
{
$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)
function services_dhcpd_zones($ddns_zones)
{
$dhcpdconf = "";
$dhcpdconf = '';
if (is_array($ddns_zones)) {
$added_zones = array();
$added_keys = array();
foreach ($ddns_zones as $zone) {
if (!is_array($zone) || empty($zone) || !is_array($zone['dns-servers'])) {
continue;
}
$primary = $zone['dns-servers'][0];
$secondary = empty($zone['dns-servers'][1]) ? "" : $zone['dns-servers'][1];
......@@ -1031,29 +1021,28 @@ function dhcpdzones($ddns_zones, $dhcpifconf)
}
// We don't need to add zones multiple times.
if ($zone['domain-name'] && !in_array($zone['domain-name'], $added_zones)) {
$dhcpdconf .= "zone {$zone['domain-name']}. {\n";
$dhcpdconf .= " primary {$primary};\n";
foreach (array($zone['domain-name'], $zone['ptr-domain']) as $domain) {
if (!empty($domain) && !in_array($domain, $added_zones)) {
/* dhcpdconf2 is injected *after* the key */
$dhcpdconf2 = "zone {$domain}. {\n";
$dhcpdconf2 .= " primary {$primary};\n";
if (is_ipaddrv4($secondary)) {
$dhcpdconf .= " secondary {$secondary};\n";
}
if ($dhcpifconf['ddnsdomainkeyname'] <> "" && $dhcpifconf['ddnsdomainkey'] <> "") {
$dhcpdconf .= " key {$dhcpifconf['ddnsdomainkeyname']};\n";
$dhcpdconf2 .= " secondary {$secondary};\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";
$added_zones[] = $zone['domain-name'];
$added_keys[] = $zone['ddnsdomainkeyname'];
}
if ($zone['ptr-domain'] && !in_array($zone['ptr-domain'], $added_zones)) {
$dhcpdconf .= "zone {$zone['ptr-domain']} {\n";
$dhcpdconf .= " primary {$primary};\n";
if (is_ipaddrv4($secondary)) {
$dhcpdconf .= " secondary {$secondary};\n";
$dhcpdconf2 .= " key {$zone['ddnsdomainkeyname']};\n";
}
if ($dhcpifconf['ddnsdomainkeyname'] <> "" && $dhcpifconf['ddnsdomainkey'] <> "") {
$dhcpdconf .= " key {$dhcpifconf['ddnsdomainkeyname']};\n";
$dhcpdconf2 .= "}\n";
$dhcpdconf .= $dhcpdconf2;
$added_zones[] = $domain;
}
$dhcpdconf .= "}\n";
$added_zones[] = $zone['ptr-domain'];
}
}
}
......@@ -1197,13 +1186,13 @@ authoritative;
EOD;
$dhcpdv6ifs = array();
$dhcpv6num = 0;
$ddns_zones = array();
$nsupdate = false;
$dhcpv6num = 0;
foreach ($dhcpdv6cfg as $dhcpv6if => $dhcpv6ifconf) {
$ddns_zones = array();
$ifcfgv6 = $config['interfaces'][$dhcpv6if];
$newzone = array();
if (!isset($dhcpv6ifconf['enable']) || !isset($Iflist[$dhcpv6if])) {
continue;
......@@ -1222,10 +1211,13 @@ EOD;
}
if (isset($dhcpv6ifconf['ddnsupdate'])) {
if ($dhcpv6ifconf['ddnsdomain'] <> "") {
if (!empty($dhcpv6ifconf['ddnsdomain'])) {
$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;
}
......@@ -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)) {
$dhcpdv6conf .= "subnet6 {$subnetv6}/{$ifcfgsnv6}";
} else {
......@@ -1349,9 +1334,13 @@ EOD;
}
}
if (!empty($dhcpv6ifconf['domain'])) {
$dhcpdv6conf .= dhcpdkey($dhcpv6ifconf);
$dhcpdv6conf .= dhcpdzones($ddns_zones, $dhcpv6ifconf);
if (!empty($newzone['domain-name'])) {
if (isset($dhcpv6ifconf['ddnsupdate'])) {
$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") {
......@@ -1374,6 +1363,7 @@ EOD;
if ($nsupdate) {
$dhcpdv6conf .= "ddns-update-style interim;\n";
$dhcpdv6conf .= services_dhcpd_zones($ddns_zones);
} else {
$dhcpdv6conf .= "ddns-update-style none;\n";
}
......
......@@ -1126,13 +1126,12 @@ include("head.inc");
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td> <p><?=gettext("Note:");?><br />
<?=sprintf(gettext("The DNS servers entered in %sSystem: " .
"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 />
<br />
<?=sprintf(gettext("The DHCP lease table can be viewed on the %sStatus: DHCP leases%s page."),'<a href="status_dhcp_leases.php">','</a>') ?><br />
</p>
<td colspan="2">
<?= sprintf(gettext('The DNS servers entered in %sSystem: ' .
'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>'); ?>
</td>
</tr>
</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