summaryrefslogtreecommitdiffstats
path: root/etc/inc/unbound.inc
diff options
context:
space:
mode:
authorRenato Botelho <garga@FreeBSD.org>2014-11-17 14:08:11 -0200
committerRenato Botelho <garga@FreeBSD.org>2014-11-17 14:08:11 -0200
commitb39774932aad89c7e1ab1b89f909dee3591294c1 (patch)
tree5eec267d10ea2ac9eb8cba7aa1e92c27afde447f /etc/inc/unbound.inc
parent21713b25f3454a7fe167615e546797c1f2909555 (diff)
downloadpfsense-b39774932aad89c7e1ab1b89f909dee3591294c1.zip
pfsense-b39774932aad89c7e1ab1b89f909dee3591294c1.tar.gz
Unbound improvements and fixes, ticket #4011:
- Create dhcpleases_entries.conf, feed by dhcpleases - Do not read lines created by dhcpleases from /etc/hosts to populate host_entries.conf - Simplify logic for host_entries.conf creation
Diffstat (limited to 'etc/inc/unbound.inc')
-rw-r--r--etc/inc/unbound.inc131
1 files changed, 29 insertions, 102 deletions
diff --git a/etc/inc/unbound.inc b/etc/inc/unbound.inc
index d4991fd..f6808a0 100644
--- a/etc/inc/unbound.inc
+++ b/etc/inc/unbound.inc
@@ -303,6 +303,9 @@ include: {$g['unbound_chroot_path']}/access_lists.conf
# Static host entries
include: {$g['unbound_chroot_path']}/host_entries.conf
+# dhcp lease entries
+include: {$g['unbound_chroot_path']}/dhcpleases_entries.conf
+
# Domain overrides
include: {$g['unbound_chroot_path']}/domainoverrides.conf
{$forward_conf}
@@ -345,7 +348,6 @@ EOF;
}
}
-
// Read /etc/hosts
function read_hosts() {
@@ -354,19 +356,19 @@ function read_hosts() {
*/
$etc_hosts = array();
foreach (file('/etc/hosts') as $line) {
- $d = preg_split('/\s/', $line, -1, PREG_SPLIT_NO_EMPTY);
+ if (strpos($line, "dhcpleases automatically entered"))
+ break;
+ $d = preg_split('/\s+/', $line, -1, PREG_SPLIT_NO_EMPTY);
if (empty($d) || substr(reset($d), 0, 1) == "#")
continue;
- if ($d[3] == "#") {
- $ip = array_shift($d);
- $fqdn = array_shift($d);
- $name = array_shift($d);
- if ($fqdn != "empty") {
- if ($name != "empty")
- array_push($etc_hosts, array(ipaddr => "$ip", fqdn => "$fqdn", name => "$name"));
- else
- array_push($etc_hosts, array(ipaddr => "$ip", fqdn => "$fqdn"));
- }
+ $ip = array_shift($d);
+ $fqdn = array_shift($d);
+ $name = array_shift($d);
+ if (!empty($fqdn) && $fqdn != "empty") {
+ if (!empty($name) && $name != "empty")
+ array_push($etc_hosts, array(ipaddr => "$ip", fqdn => "$fqdn", name => "$name"));
+ else
+ array_push($etc_hosts, array(ipaddr => "$ip", fqdn => "$fqdn"));
}
}
return $etc_hosts;
@@ -472,102 +474,27 @@ function unbound_add_host_entries() {
global $config, $g;
$unbound_entries = "local-zone: \"{$config['system']['domain']}\" transparent\n";
- // IPv4 entries
- $unbound_entries .= "local-data-ptr: \"127.0.0.1 localhost\"\n";
- $unbound_entries .= "local-data: \"localhost A 127.0.0.1\"\n";
- $unbound_entries .= "local-data: \"localhost.{$config['system']['domain']} A 127.0.0.1\"\n";
- // IPv6 entries
- $unbound_entries .= "local-data-ptr: \"::1 localhost\"\n";
- $unbound_entries .= "local-data: \"localhost AAAA ::1\"\n";
- $unbound_entries .= "local-data: \"localhost.{$config['system']['domain']} AAAA ::1\"\n";
-
- $listen_addresses = "";
- if (isset($config['unbound']['interface'])) {
- $interfaces = explode(",", $config['unbound']['interface']);
- foreach ($interfaces as $interface) {
- if (is_ipaddrv4($interface)) {
- $unbound_entries .= "local-data-ptr: \"{$interface} {$config['system']['hostname']}.{$config['system']['domain']}\"\n";
- $unbound_entries .= "local-data: \"{$config['system']['hostname']}.{$config['system']['domain']} A {$interface}\"\n";
- $unbound_entries .= "local-data: \"{$config['system']['hostname']} A {$interface}\"\n";
- } else if (is_ipaddrv6($interface)) {
- $unbound_entries .= "local-data: \"{$config['system']['hostname']}.{$config['system']['domain']} AAAA {$interface}\"\n";
- $unbound_entries .= "local-data: \"{$config['system']['hostname']} AAAA {$interface}\"\n";
- } else {
- $if = get_real_interface($interface);
- if (does_interface_exist($if)) {
- $laddr = find_interface_ip($if);
- if (is_ipaddrv4($laddr)) {
- $unbound_entries .= "local-data-ptr: \"{$laddr} {$config['system']['hostname']}.{$config['system']['domain']}\"\n";
- $unbound_entries .= "local-data: \"{$config['system']['hostname']}.{$config['system']['domain']} A {$laddr}\"\n";
- $unbound_entries .= "local-data: \"{$config['system']['hostname']} A {$laddr}\"\n";
- }
- $laddr6 = find_interface_ipv6($if);
- if (is_ipaddrv6($laddr6) && !isset($config['dnsmasq']['strictbind'])) {
- $unbound_entries .= "local-data-ptr: \"{$laddr6} {$config['system']['hostname']}.{$config['system']['domain']}\"\n";
- $unbound_entries .= "local-data: \"{$config['system']['hostname']}.{$config['system']['domain']} AAAA {$laddr}\"\n";
- $unbound_entries .= "local-data: \"{$config['system']['hostname']} AAAA {$laddr}\"\n";
- }
- }
- }
- }
- }
- // Static Host entries
- if (isset($config['unbound']['hosts'])) {
- $host_entries = "";
- $added_item = array();
- foreach($config['unbound']['hosts'] as $host) {
- $current_host = $host['host'];
- if ($host['host'] != "")
- $host['host'] = $host['host'].".";
- if (!$added_item[$current_host]) {
- $host_entries .= "local-data-ptr: \"{$host['ip']} {$host['host']}{$host['domain']}\"\n";
- if (is_ipaddrv6($host['ip']))
- $host_entries .= "local-data: \"{$host['host']}{$host['domain']} IN AAAA {$host['ip']}\"\n";
- else
- $host_entries .= "local-data: \"{$host['host']}{$host['domain']} IN A {$host['ip']}\"\n";
- if (!empty($host['descr']) && isset($config['unbound']['txtsupport']))
- $host_entries .= "local-data: '{$host['host']}{$host['domain']} TXT \"".addslashes($host['descr'])."\"'\n";
-
- // Do not add duplicate entries
- $added_item[$current_host] = true;
- }
- }
- $unbound_entries .= $host_entries;
- }
-
- // Static DHCP entries
- $host_entries = "";
- if (isset($config['unbound']['regdhcpstatic']) && is_array($config['dhcpd'])) {
- foreach ($config['dhcpd'] as $dhcpif => $dhcpifconf)
- if (is_array($dhcpifconf['staticmap']) && isset($dhcpifconf['enable']))
- foreach ($dhcpifconf['staticmap'] as $host)
- if ($host['ipaddr'] && $host['hostname']) {
- $host_entries .= "local-data-ptr: \"{$host['ipaddr']} {$host['hostname']}.{$config['system']['domain']}\"\n";
- $host_entries .= "local-data: \"{$host['hostname']}.{$config['system']['domain']} IN A {$host['ipaddr']}\"\n";
- if (!empty($host['descr']) && $unboundcfg['txtsupport'] == 'on')
- $host_entries .= "local-data: '{$host['hostname']}.{$config['system']['domain']} TXT \"".addslashes($host['descr'])."\"'\n";
- }
- $unbound_entries .= $host_entries;
- }
+ $hosts = read_hosts();
+ foreach ($hosts as $host) {
+ if (is_ipaddrv4($host['ipaddr']))
+ $type = 'A';
+ else if (is_ipaddrv6($host['ipaddr']))
+ $type = 'AAAA';
+ else
+ continue;
- // Handle DHCPLeases added host entries
- $dhcplcfg = read_hosts();
- $host_entries = "";
- if (is_array($dhcplcfg)) {
- foreach($dhcplcfg as $key=>$host) {
- $host_entries .= "local-data-ptr: \"{$host['ipaddr']} {$host['fqdn']}\"\n";
- $host_entries .= "local-data: \"{$host['fqdn']} IN A {$host['ipaddr']}\"\n";
- if (!empty($host['name'])) {
- $host_entries .= "local-data-ptr: \"{$host['ipaddr']} {$host['name']}\"\n";
- $host_entries .= "local-data: \"{$host['name']} IN A {$host['ipaddr']}\"\n";
- }
- }
- $unbound_entries .= $host_entries;
+ $unbound_entries .= "local-data-ptr: \"{$host['ipaddr']} {$host['fqdn']}\"\n";
+ $unbound_entries .= "local-data: \"{$host['fqdn']} {$type} {$host['ipaddr']}\"\n";
+ if (isset($host['name']))
+ $unbound_entries .= "local-data: \"{$host['name']} {$type} {$host['ipaddr']}\"\n";
}
// Write out entries
file_put_contents("{$g['unbound_chroot_path']}/host_entries.conf", $unbound_entries);
+
+ /* dhcpleases will write to this config file, make sure it exists */
+ @touch("{$g['unbound_chroot_path']}/dhcpleases_entries.conf");
}
function unbound_control($action) {
OpenPOWER on IntegriCloud