Skip to content

Commit

Permalink
dnsmasq: remove unused/refactor #6402
Browse files Browse the repository at this point in the history
(cherry picked from commit 11b6708)
(cherry picked from commit 481db99)
  • Loading branch information
fichtner committed Mar 14, 2023
1 parent 40cabd0 commit 0a744f9
Showing 1 changed file with 26 additions and 54 deletions.
80 changes: 26 additions & 54 deletions src/etc/inc/plugins.inc.d/dnsmasq.inc
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,26 @@ function dnsmasq_enabled()

function dnsmasq_configure()
{
return array(
'dns' => array('dnsmasq_configure_do'),
'hosts' => array('dnsmasq_hosts_generate:0'),
'local' => array('dnsmasq_configure_do'),
'newwanip' => array('dnsmasq_configure_do'),
);
return [
'dns' => ['dnsmasq_configure_do'],
'local' => ['dnsmasq_configure_do'],
'newwanip' => ['dnsmasq_configure_do'],
];
}

function dnsmasq_services()
{
$services = array();
$services = [];

if (!dnsmasq_enabled()) {
return $services;
}

$pconfig = array();
$pconfig = [];
$pconfig['name'] = 'dnsmasq';
$pconfig['description'] = gettext('Dnsmasq DNS');
$pconfig['php']['restart'] = array('dnsmasq_configure_do');
$pconfig['php']['start'] = array('dnsmasq_configure_do');
$pconfig['php']['restart'] = ['dnsmasq_configure_do'];
$pconfig['php']['start'] = ['dnsmasq_configure_do'];
$pconfig['pidfile'] = '/var/run/dnsmasq.pid';
$services[] = $pconfig;

Expand All @@ -67,23 +66,23 @@ function dnsmasq_services()

function dnsmasq_syslog()
{
$logfacilities = array();
$logfacilities = [];

$logfacilities['dnsmasq'] = array('facility' => array('dnsmasq'));
$logfacilities['dnsmasq'] = ['facility' => ['dnsmasq']];

return $logfacilities;
}

function dnsmasq_xmlrpc_sync()
{
$result = array();
$result = [];

$result[] = array(
$result[] = [
'description' => gettext('Dnsmasq DNS'),
'section' => 'dnsmasq',
'id' => 'dnsforwarder',
'services' => ["dnsmasq"],
);
'services' => ['dnsmasq'],
];

return $result;
}
Expand All @@ -92,9 +91,8 @@ function dnsmasq_configure_do($verbose = false)
{
global $config;

_dnsmasq_dhcpleases_stop();

killbypid('/var/run/dnsmasq.pid', 'TERM', true);
killbypid('/var/run/dnsmasq_dhcpd.pid');
killbypid('/var/run/dnsmasq.pid');

if (!dnsmasq_enabled()) {
return;
Expand All @@ -118,7 +116,7 @@ function dnsmasq_configure_do($verbose = false)
if (!empty($config['dnsmasq']['interface'])) {
$interfaces = explode(',', $config['dnsmasq']['interface']);
$interfaces[] = 'lo0';
$addresses = array();
$addresses = [];

foreach (interfaces_addresses($interfaces) as $tmpaddr => $info) {
if ($info['name'] == 'lo0' && $info['family'] == 'inet' && $tmpaddr != '127.0.0.1') {
Expand Down Expand Up @@ -210,7 +208,13 @@ function dnsmasq_configure_do($verbose = false)

mwexec("/usr/local/sbin/dnsmasq {$args}");

_dnsmasq_dhcpleases_start();
if (isset($config['dnsmasq']['regdhcp'])) {
$domain = $config['system']['domain'];
if (isset($config['dnsmasq']['regdhcpdomain'])) {
$domain = $config['dnsmasq']['regdhcpdomain'];
}
mwexecf('/usr/local/opnsense/scripts/dhcp/dnsmasq_watcher.py --domain %s', $domain);
}

service_log("done.\n", $verbose);
}
Expand All @@ -224,7 +228,7 @@ function _dnsmasq_add_host_entries()
$dhosts = '';

if (!isset($dnsmasqcfg['hosts']) || !is_array($dnsmasqcfg['hosts'])) {
$dnsmasqcfg['hosts'] = array();
$dnsmasqcfg['hosts'] = [];
}

foreach ($dnsmasqcfg['hosts'] as $host) {
Expand Down Expand Up @@ -283,35 +287,3 @@ function _dnsmasq_add_host_entries()
touch('/var/etc/dnsmasq-leases');
chmod('/var/etc/dnsmasq-leases', 0644);
}

function _dnsmasq_dhcpleases_start()
{
global $config;

if (isset($config['dnsmasq']['regdhcp'])) {
$domain = $config['system']['domain'];
if (isset($config['dnsmasq']['regdhcpdomain'])) {
$domain = $config['dnsmasq']['regdhcpdomain'];
}
mwexecf('/usr/local/opnsense/scripts/dhcp/dnsmasq_watcher.py --domain %s', $domain);
}
}

function _dnsmasq_dhcpleases_stop()
{
killbypid('/var/run/dnsmasq_dhcpd.pid', 'TERM', true);
}

function dnsmasq_hosts_generate()
{
_dnsmasq_dhcpleases_stop();

if (!dnsmasq_enabled()) {
return;
}

_dnsmasq_add_host_entries();
_dnsmasq_dhcpleases_start();

killbypid('/var/run/dnsmasq.pid', 'HUP');
}

0 comments on commit 0a744f9

Please sign in to comment.