From ba0c82dd5441aa5e1871042efd28a48ce080a3d7 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Mon, 29 Apr 2019 07:49:26 +0200 Subject: [PATCH] dhcpd: naming convention, plugins_configure() use --- src/etc/inc/interfaces.inc | 6 +-- src/etc/inc/plugins.inc.d/dhcpd.inc | 31 ++++++++++--- src/etc/inc/xmlrpc/legacy.inc | 3 +- src/etc/rc.bootup | 8 ++-- src/etc/rc.newwanipv6 | 3 +- src/etc/rc.reload_all | 3 +- src/opnsense/scripts/shell/setaddr.php | 2 + src/opnsense/scripts/shell/setports.php | 3 +- src/www/diag_logs_dhcp.php | 2 +- src/www/diag_logs_settings.php | 3 +- src/www/interfaces_assign.php | 3 +- src/www/services_dhcp_relay.php | 56 ++++++++++++------------ src/www/services_dhcpv6_relay.php | 58 ++++++++++++------------- src/www/system_advanced_admin.php | 3 +- src/www/system_advanced_misc.php | 1 - src/www/system_general.php | 2 +- 16 files changed, 97 insertions(+), 90 deletions(-) diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc index 3dd8bcd80..15300beed 100644 --- a/src/etc/inc/interfaces.inc +++ b/src/etc/inc/interfaces.inc @@ -1082,8 +1082,7 @@ function interface_bring_down($interface = "wan", $ifacecfg = false) $track6 = link_interface_to_track6($interface); if (count($track6)) { /* bring down radvd and dhcp6 on these interfaces */ - require_once 'plugins.inc.d/dhcpd.inc'; /* XXX remove me */ - services_dhcpd_configure(false, 'inet6', $track6); + plugins_configure('dhcp', false, array('inet6', $track6)); } switch ($ifcfg['ipaddrv6']) { @@ -2572,9 +2571,8 @@ function interface_configure($verbose = false, $interface = 'wan', $reload = fal if ($reload) { system_routing_configure($verbose, $interface); plugins_configure('ipsec', $verbose, array($interface)); + plugins_configure('dhcp', $verbose); plugins_configure('dns', $verbose); - require_once 'plugins.inc.d/dhcpd.inc'; /* XXX remove me */ - services_dhcpd_configure($verbose); /* XXX move these up the call stack */ configdp_run('dyndns reload', array($interface)); configdp_run('rfc2136 reload', array($interface)); diff --git a/src/etc/inc/plugins.inc.d/dhcpd.inc b/src/etc/inc/plugins.inc.d/dhcpd.inc index 7e4444444..2ca4cc592 100644 --- a/src/etc/inc/plugins.inc.d/dhcpd.inc +++ b/src/etc/inc/plugins.inc.d/dhcpd.inc @@ -29,6 +29,14 @@ * POSSIBILITY OF SUCH DAMAGE. */ +function dhcpd_configure() +{ + return array( + 'dhcp' => array('services_dhcpd_configure:3'), + 'dhcrelay' => array('dhcpd_dhcrelay_configure:2'), + ); +} + function dhcpd_radvd_enabled() { global $config; @@ -104,8 +112,8 @@ function dhcpd_services() $pconfig = array(); $pconfig['name'] = "dhcrelay"; $pconfig['description'] = gettext("DHCPv4 Relay"); - $pconfig['php']['restart'] = array('services_dhcrelay_configure'); - $pconfig['php']['start'] = array('services_dhcrelay_configure'); + $pconfig['php']['restart'] = array('dhcpd_dhcrelay4_configure'); + $pconfig['php']['start'] = array('dhcpd_dhcrelay4_configure'); $pconfig['pidfile'] = '/var/run/dhcrelay.pid'; $services[] = $pconfig; } @@ -114,8 +122,8 @@ function dhcpd_services() $pconfig = array(); $pconfig['name'] = "dhcrelay6"; $pconfig['description'] = gettext("DHCPv6 Relay"); - $pconfig['php']['restart'] = array('services_dhcrelay6_configure'); - $pconfig['php']['start'] = array('services_dhcrelay6_configure'); + $pconfig['php']['restart'] = array('dhcpd_dhcrelay6_configure'); + $pconfig['php']['start'] = array('dhcpd_dhcrelay6_configure'); $pconfig['pidfile'] = '/var/run/dhcrelay6.pid'; $services[] = $pconfig; } @@ -1534,7 +1542,18 @@ EOD; } } -function services_dhcrelay_configure($verbose = false) +function dhcpd_dhcrelay_configure($verbose = false, $family = 'all') +{ + if ($family == 'all' || $family == 'inet') { + dhcpd_dhcrelay4_configure($verbose); + } + + if ($family == 'all' || $family == 'inet6') { + dhcpd_dhcrelay6_configure($verbose); + } +} + +function dhcpd_dhcrelay4_configure($verbose = false) { global $config; @@ -1654,7 +1673,7 @@ function services_dhcrelay_configure($verbose = false) } } -function services_dhcrelay6_configure($verbose = false) +function dhcpd_dhcrelay6_configure($verbose = false) { global $config; diff --git a/src/etc/inc/xmlrpc/legacy.inc b/src/etc/inc/xmlrpc/legacy.inc index 7b05e2bb2..b33abe356 100644 --- a/src/etc/inc/xmlrpc/legacy.inc +++ b/src/etc/inc/xmlrpc/legacy.inc @@ -120,15 +120,14 @@ function filter_configure_xmlrpc() require_once("system.inc"); require_once("util.inc"); require_once("interfaces.inc"); - require_once("plugins.inc.d/dhcpd.inc"); /* XXX */ system_routing_configure(); plugins_configure('monitor'); filter_configure(); system_hosts_generate(); local_sync_accounts(); + plugins_configure('dhcp'); plugins_configure('dns'); - services_dhcpd_configure(); plugins_configure('remote'); return true; diff --git a/src/etc/rc.bootup b/src/etc/rc.bootup index 4626a8a6c..2e583105e 100755 --- a/src/etc/rc.bootup +++ b/src/etc/rc.bootup @@ -102,12 +102,10 @@ plugins_configure('earlybootup', true); system_cron_configure(true, true); system_routing_configure(true); -plugins_configure('dns', true); -require_once 'plugins.inc.d/dhcpd.inc'; /* XXX */ -services_dhcpd_configure(true); system_hosts_generate(true); -services_dhcrelay_configure(true); -services_dhcrelay6_configure(true); +plugins_configure('dhcp', true); +plugins_configure('dhcrelay', true); +plugins_configure('dns', true); prefer_ipv4_or_ipv6(); plugins_configure('monitor', true); diff --git a/src/etc/rc.newwanipv6 b/src/etc/rc.newwanipv6 index 26079abe8..a7562d147 100755 --- a/src/etc/rc.newwanipv6 +++ b/src/etc/rc.newwanipv6 @@ -115,8 +115,7 @@ if (!empty($grouptmp)) { } if (count(link_interface_to_track6($interface, true))) { - require_once 'plugins.inc.d/dhcpd.inc'; /* XXX */ - services_dhcpd_configure(false, 'inet6'); + plugins_configure('dhcp', false, array('inet6')); } system_resolvconf_generate(); diff --git a/src/etc/rc.reload_all b/src/etc/rc.reload_all index 68c0d26bc..7e49b4add 100755 --- a/src/etc/rc.reload_all +++ b/src/etc/rc.reload_all @@ -35,7 +35,6 @@ require_once('rrd.inc'); require_once("util.inc"); require_once("system.inc"); require_once("interfaces.inc"); -require_once('plugins.inc.d/dhcpd.inc'); if (count($argv) > 1 && is_numeric($argv[1])) { // starting delayed. @@ -52,7 +51,7 @@ system_resolvconf_generate(true); interfaces_configure(true); system_routing_configure(true); filter_configure_sync(true); -services_dhcpd_configure(true); +plugins_configure('dhcp', true); plugins_configure('local', true); plugins_configure('vpn', true); rrd_configure(true); diff --git a/src/opnsense/scripts/shell/setaddr.php b/src/opnsense/scripts/shell/setaddr.php index 7d4b4de77..14a4bd2f6 100755 --- a/src/opnsense/scripts/shell/setaddr.php +++ b/src/opnsense/scripts/shell/setaddr.php @@ -562,10 +562,12 @@ plugins_configure('monitor', true); filter_configure_sync(true); if ($restart_dhcpd) { + /* XXX plugins_configure() */ services_dhcpd_configure(true); } if ($restart_webgui) { + /* XXX plugins_configure() */ webgui_configure_do(true); } diff --git a/src/opnsense/scripts/shell/setports.php b/src/opnsense/scripts/shell/setports.php index 0a7aef8f0..6aea7e772 100755 --- a/src/opnsense/scripts/shell/setports.php +++ b/src/opnsense/scripts/shell/setports.php @@ -34,7 +34,6 @@ require_once("util.inc"); require_once("rrd.inc"); require_once("system.inc"); require_once("interfaces.inc"); -require_once('plugins.inc.d/dhcpd.inc'); system_console_mute(); @@ -47,7 +46,7 @@ if (set_networking_interfaces_ports()) { interfaces_configure(true); system_routing_configure(true); filter_configure_sync(true); - services_dhcpd_configure(true); + plugins_configure('dhcp', true); plugins_configure('local', true); plugins_configure('vpn', true); rrd_configure(true); diff --git a/src/www/diag_logs_dhcp.php b/src/www/diag_logs_dhcp.php index 24166945f..95f44498c 100644 --- a/src/www/diag_logs_dhcp.php +++ b/src/www/diag_logs_dhcp.php @@ -6,7 +6,7 @@ $logclog = true; function clear_hook() { killbyname('dhcpd'); - services_dhcpd_configure(); + plugins_configure('dhcp'); } $service_hook = 'dhcpd'; diff --git a/src/www/diag_logs_settings.php b/src/www/diag_logs_settings.php index c74cbd6cf..165a72cda 100644 --- a/src/www/diag_logs_settings.php +++ b/src/www/diag_logs_settings.php @@ -33,7 +33,6 @@ require_once("guiconfig.inc"); require_once("interfaces.inc"); require_once("filter.inc"); require_once("system.inc"); -require_once("services.inc"); function clear_all_log_files() { @@ -80,7 +79,7 @@ function clear_all_log_files() system_syslogd_start(); killbyname('dhcpd'); - services_dhcpd_configure(); + plugins_configure('dhcp'); } function is_valid_syslog_server($target) { diff --git a/src/www/interfaces_assign.php b/src/www/interfaces_assign.php index 8a7fe99e9..a8515c5c3 100644 --- a/src/www/interfaces_assign.php +++ b/src/www/interfaces_assign.php @@ -176,9 +176,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { unset($config['interfaces'][$id]); /* delete the specified OPTn or LAN*/ + /* XXX what about DHCPv6? */ if (isset($config['dhcpd'][$id])) { unset($config['dhcpd'][$id]); - services_dhcpd_configure(); + plugins_configure('dhcp'); } if (isset($config['filter']['rule'])) { foreach ($config['filter']['rule'] as $x => $rule) { diff --git a/src/www/services_dhcp_relay.php b/src/www/services_dhcp_relay.php index 0617e4d1b..b2b6874b2 100644 --- a/src/www/services_dhcp_relay.php +++ b/src/www/services_dhcp_relay.php @@ -1,38 +1,37 @@ - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. -*/ + * Copyright (C) 2014-2016 Deciso B.V. + * Copyright (C) 2010 Ermal Luçi + * Copyright (C) 2003-2004 Justin Ellison + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ require_once("guiconfig.inc"); require_once("services.inc"); require_once("interfaces.inc"); - if ($_SERVER['REQUEST_METHOD'] === 'GET') { $pconfig['enable'] = isset($config['dhcrelay']['enable']); if (empty($config['dhcrelay']['interface'])) { @@ -71,8 +70,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $config['dhcrelay']['agentoption'] = !empty($pconfig['agentoption']); $config['dhcrelay']['server'] = $pconfig['server']; write_config(); - // reconfigure - services_dhcrelay_configure(); + plugins_configure('dhcrelay', false, array('inet')); header(url_safe('Location: /services_dhcp_relay.php')); exit; } diff --git a/src/www/services_dhcpv6_relay.php b/src/www/services_dhcpv6_relay.php index b57e405b6..04c65ba7a 100644 --- a/src/www/services_dhcpv6_relay.php +++ b/src/www/services_dhcpv6_relay.php @@ -1,39 +1,38 @@ - Copyright (C) 2010 Ermal Luçi - Copyright (C) 2010 Seth Mos - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. -*/ + * Copyright (C) 2014-2016 Deciso B.V. + * Copyright (C) 2003-2004 Justin Ellison + * Copyright (C) 2010 Ermal Luçi + * Copyright (C) 2010 Seth Mos + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ require_once("guiconfig.inc"); require_once("interfaces.inc"); require_once("services.inc"); - if ($_SERVER['REQUEST_METHOD'] === 'GET') { $pconfig['enable'] = isset($config['dhcrelay6']['enable']); if (empty($config['dhcrelay6']['interface'])) { @@ -72,8 +71,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $config['dhcrelay6']['agentoption'] = !empty($pconfig['agentoption']); $config['dhcrelay6']['server'] = $pconfig['server']; write_config(); - // reconfigure - services_dhcrelay6_configure(); + plugins_configure('dhcrelay', false, array('inet6')); header(url_safe('Location: /services_dhcpv6_relay.php')); exit; } diff --git a/src/www/system_advanced_admin.php b/src/www/system_advanced_admin.php index e56b8628c..b5d347c26 100644 --- a/src/www/system_advanced_admin.php +++ b/src/www/system_advanced_admin.php @@ -34,7 +34,6 @@ require_once("guiconfig.inc"); require_once("filter.inc"); require_once("system.inc"); -require_once("services.inc"); $a_group = &config_read_array('system', 'group'); $a_authmode = auth_get_authserver_list(); @@ -297,7 +296,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { system_login_configure(); system_hosts_generate(); plugins_configure('dns'); - services_dhcpd_configure(); + plugins_configure('dhcp'); configd_run('openssh restart', true); if ($restart_webgui) { diff --git a/src/www/system_advanced_misc.php b/src/www/system_advanced_misc.php index b13626df0..34dfaea99 100644 --- a/src/www/system_advanced_misc.php +++ b/src/www/system_advanced_misc.php @@ -32,7 +32,6 @@ require_once("guiconfig.inc"); require_once("filter.inc"); -require_once("services.inc"); require_once("system.inc"); require_once("interfaces.inc"); diff --git a/src/www/system_general.php b/src/www/system_general.php index b45b10899..bd18dceaf 100644 --- a/src/www/system_general.php +++ b/src/www/system_general.php @@ -223,7 +223,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { system_hosts_generate(); system_resolvconf_generate(); plugins_configure('dns'); - services_dhcpd_configure(); + plugins_configure('dhcp'); filter_configure(); header(url_safe('Location: /system_general.php?savemsg=%s', array('The changes have been applied successfully.')));