summaryrefslogtreecommitdiffstats
path: root/src/etc/inc/system.inc
diff options
context:
space:
mode:
authorRenato Botelho <renato@netgate.com>2017-01-11 12:23:53 -0200
committerRenato Botelho <renato@netgate.com>2017-01-11 14:36:28 -0200
commit2da0fc7735d5e17f7bedc8f2f48962534b4ba301 (patch)
tree5f4938e1563445bec9b532725a2dda237654ae13 /src/etc/inc/system.inc
parent8cf97db3528a3d11cf780757214365a3bbe18d5e (diff)
downloadpfsense-2da0fc7735d5e17f7bedc8f2f48962534b4ba301.zip
pfsense-2da0fc7735d5e17f7bedc8f2f48962534b4ba301.tar.gz
Ticket #6712: Create system_hosts_local_entries()
This function will return an array with 127.0.0.1, ::1 and LAN (or first interface with no gateway when LAN is not there) items to be added to /etc/hosts
Diffstat (limited to 'src/etc/inc/system.inc')
-rw-r--r--src/etc/inc/system.inc98
1 files changed, 62 insertions, 36 deletions
diff --git a/src/etc/inc/system.inc b/src/etc/inc/system.inc
index 708b64e..24536a1 100644
--- a/src/etc/inc/system.inc
+++ b/src/etc/inc/system.inc
@@ -289,6 +289,60 @@ function get_nameservers() {
return $master_list;
}
+/* Create localhost + local interfaces entries for /etc/hosts */
+function system_hosts_local_entries() {
+ global $config;
+
+ $syscfg = $config['system'];
+
+ $hosts = array();
+ $hosts[] = array(
+ 'ipaddr' => '127.0.0.1',
+ 'fqdn' => 'localhost',
+ 'name' => 'localhost.' . $syscfg['domain']
+ );
+ $hosts[] = array(
+ 'ipaddr' => '::1',
+ 'fqdn' => 'localhost',
+ 'name' => 'localhost.' . $syscfg['domain']
+ );
+
+ if ($config['interfaces']['lan']) {
+ $sysiflist = array('lan' => "lan");
+ } else {
+ $sysiflist = get_configured_interface_list();
+ }
+
+ $hosts_if_found = false;
+ $local_fqdn = "{$syscfg['hostname']}.{$syscfg['domain']}";
+ foreach ($sysiflist as $sysif) {
+ if ($sysif != 'lan' && interface_has_gateway($sysif)) {
+ continue;
+ }
+ $cfgip = get_interface_ip($sysif);
+ if (is_ipaddrv4($cfgip)) {
+ $hosts[] = array(
+ 'ipaddr' => $cfgip,
+ 'fqdn' => $local_fqdn
+ );
+ $hosts_if_found = true;
+ }
+ $cfgipv6 = get_interface_ipv6($sysif);
+ if (is_ipaddrv6($cfgipv6)) {
+ $hosts[] = array(
+ 'ipaddr' => $cfgipv6,
+ 'fqdn' => $local_fqdn
+ );
+ $hosts_if_found = true;
+ }
+ if ($hosts_if_found == true) {
+ break;
+ }
+ }
+
+ return $hosts;
+}
+
function system_hosts_generate() {
global $config, $g;
if (isset($config['system']['developerspew'])) {
@@ -296,7 +350,6 @@ function system_hosts_generate() {
echo "system_hosts_generate() being called $mt\n";
}
- $syscfg = $config['system'];
// prefer dnsmasq for hosts generation where it's enabled. It relies
// on hosts for name resolution of its overrides, unbound does not.
if (isset($config['dnsmasq']) && isset($config['dnsmasq']['enable'])) {
@@ -305,45 +358,18 @@ function system_hosts_generate() {
$dnsmasqcfg = $config['unbound'];
}
- $hosts = "127.0.0.1 localhost localhost.{$syscfg['domain']}\n";
- $hosts .= "::1 localhost localhost.{$syscfg['domain']}\n";
+ $syscfg = $config['system'];
+ $hosts = "";
$lhosts = "";
$dhosts = "";
- if ($config['interfaces']['lan']) {
- $cfgip = get_interface_ip("lan");
- if (is_ipaddrv4($cfgip)) {
- $hosts .= "{$cfgip} {$syscfg['hostname']}." .
- "{$syscfg['domain']}\n";
- }
- $cfgipv6 = get_interface_ipv6("lan");
- if (is_ipaddrv6($cfgipv6)) {
- $hosts .= "{$cfgipv6} {$syscfg['hostname']}." .
- "{$syscfg['domain']}\n";
- }
- } else {
- $sysiflist = get_configured_interface_list();
- $hosts_if_found = false;
- foreach ($sysiflist as $sysif) {
- if (interface_has_gateway($sysif)) {
- continue;
- }
- $cfgip = get_interface_ip($sysif);
- if (is_ipaddrv4($cfgip)) {
- $hosts .= "{$cfgip} {$syscfg['hostname']}" .
- ".{$syscfg['domain']}\n";
- $hosts_if_found = true;
- }
- $cfgipv6 = get_interface_ipv6($sysif);
- if (is_ipaddrv6($cfgipv6)) {
- $hosts .= "{$cfgipv6} {$syscfg['hostname']}" .
- ".{$syscfg['domain']}\n";
- $hosts_if_found = true;
- }
- if ($hosts_if_found == true) {
- break;
- }
+ $hosts_array = system_hosts_local_entries();
+ foreach ($hosts_array as $host) {
+ $hosts .= "{$host['ipaddr']}\t{$host['fqdn']}";
+ if (!empty($host['name'])) {
+ $hosts .= " {$host['name']}";
}
+ $hosts .= "\n";
}
if (isset($dnsmasqcfg['enable'])) {
OpenPOWER on IntegriCloud