Skip to content

Commit

Permalink
dhcrelay: migrate IPv6 data, consolidation cleanups opnsense#6983
Browse files Browse the repository at this point in the history
Menu, ACL and XMLRPC wer consolidated into the IPv4 flag.  IPv6 is
no longer functional and operates from the shared reimplementation
now.  Syslog doesn't work on OpenBSD dhcrelay especially since we
start it with -d so it tries to spam to stderr which is ignored by
daemon -f to background it properly with a pid file (it's a long
story, don't ask).
  • Loading branch information
fichtner committed Mar 13, 2024
1 parent 53a95b0 commit ad5fed3
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 234 deletions.
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Copyright (c) 2009-2012 Jim Pingle <[email protected]>
Copyright (c) 2012 Jonas von Andrian
Copyright (c) 2004-2005 Jonathan Watt <[email protected]>
Copyright (c) 2015 Jos Schellevis <[email protected]>
Copyright (c) 2003-2004 Justin Ellison <[email protected]>
Copyright (c) 2021 Kyle Evans <[email protected]>
Copyright (c) 2015 Manuel Faux <[email protected]>
Copyright (c) 2003-2006 Manuel Kasper <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion plist
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@
/usr/local/opnsense/mvc/app/models/OPNsense/DHCRelay/DHCRelay.xml
/usr/local/opnsense/mvc/app/models/OPNsense/DHCRelay/Menu/Menu.xml
/usr/local/opnsense/mvc/app/models/OPNsense/DHCRelay/Migrations/M1_0_0.php
/usr/local/opnsense/mvc/app/models/OPNsense/DHCRelay/Migrations/M1_0_1.php
/usr/local/opnsense/mvc/app/models/OPNsense/Diagnostics/ACL/ACL.xml
/usr/local/opnsense/mvc/app/models/OPNsense/Diagnostics/DnsDiagnostics.php
/usr/local/opnsense/mvc/app/models/OPNsense/Diagnostics/DnsDiagnostics.xml
Expand Down Expand Up @@ -2080,7 +2081,6 @@
/usr/local/www/services_dhcp_edit.php
/usr/local/www/services_dhcpv6.php
/usr/local/www/services_dhcpv6_edit.php
/usr/local/www/services_dhcpv6_relay.php
/usr/local/www/services_dnsmasq.php
/usr/local/www/services_dnsmasq_domainoverride_edit.php
/usr/local/www/services_dnsmasq_edit.php
Expand Down
6 changes: 0 additions & 6 deletions src/etc/inc/plugins.inc.d/core.inc
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,6 @@ function core_xmlrpc_sync()
'id' => 'dhcpdv6',
'services' => ["dhcpdv6", "radvd"],
);
$result[] = array(
'description' => gettext('DHCPv6: Relay'),
'section' => 'dhcrelay6',
'id' => 'dhcrelay6',
'services' => ["dhcrelay6"],
);
$result[] = array(
'description' => gettext('Virtual IPs'),
'help' => gettext('Synchronize the CARP Virtual IPs to the other HA host.'),
Expand Down
17 changes: 0 additions & 17 deletions src/etc/inc/plugins.inc.d/dhcpd.inc
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,6 @@ function dhcpd_services()
$services[] = $pconfig;
}

if (isset($config['dhcrelay6']['enable'])) {
$pconfig = array();
$pconfig['name'] = "dhcrelay6";
$pconfig['description'] = gettext("DHCPv6 Relay");
$pconfig['php']['restart'] = array('dhcpd_dhcrelay6_configure');
$pconfig['php']['start'] = array('dhcpd_dhcrelay6_configure');
$pconfig['pidfile'] = '/var/run/dhcrelay6.pid';
$services[] = $pconfig;
}

if (dhcpd_dhcpv4_enabled()) {
$pconfig = array();
$pconfig['name'] = 'dhcpd';
Expand Down Expand Up @@ -1599,13 +1589,6 @@ EOD;
service_log("done.\n", $verbose);
}

function dhcpd_dhcrelay_configure($verbose = false, $family = null, $id = null)
{
if ($family == null || $family == 'inet6') {
dhcpd_dhcrelay6_configure($verbose);
}
}

function dhcpd_dhcrelay6_configure($verbose = false)
{
global $config;
Expand Down
4 changes: 2 additions & 2 deletions src/etc/inc/plugins.inc.d/dhcrelay.inc
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ function dhcrelay_xmlrpc_sync()
$result = [];

$result[] = [
'description' => gettext('DHCPv4: Relay'),
'section' => 'dhcrelay,OPNsense.DHCRelay',
'description' => gettext('DHCRelay'),
'section' => 'dhcrelay,dhcrelay6,OPNsense.DHCRelay',
'services' => ['dhcrelay'],
'id' => 'dhcrelay',
];
Expand Down
6 changes: 0 additions & 6 deletions src/opnsense/mvc/app/models/OPNsense/Core/ACL/ACL.xml
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,6 @@
<pattern>services_dhcp.php*</pattern>
</patterns>
</page-services-dhcpserver>
<page-services-dhcpv6relay>
<name>Services: DHCPv6 Relay</name>
<patterns>
<pattern>services_dhcpv6_relay.php*</pattern>
</patterns>
</page-services-dhcpv6relay>
<page-services-dhcpserverv6-editstaticmapping>
<name>Services: DHCPv6 Server: Edit static mapping</name>
<patterns>
Expand Down
1 change: 0 additions & 1 deletion src/opnsense/mvc/app/models/OPNsense/Core/Menu/Menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@
<LogFile VisibleName="Log File" order="400" url="/ui/diagnostics/log/core/dhcpd"/>
</ISC_DHCPv4>
<ISC_DHCPv6 VisibleName="ISC DHCPv6" cssClass="fa fa-bullseye fa-fw">
<Relay order="300" url="/services_dhcpv6_relay.php"/>
<Leases order="400" url="/ui/dhcpv6/leases"/>
</ISC_DHCPv6>
<OpenDNS VisibleName="OpenDNS" url="/services_opendns.php" cssClass="fa fa-tags fa-fw"/>
Expand Down
2 changes: 1 addition & 1 deletion src/opnsense/mvc/app/models/OPNsense/DHCRelay/DHCRelay.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<model>
<mount>//OPNsense/DHCRelay</mount>
<version>1.0.0</version>
<version>1.0.1</version>
<description>DHCRelay configuration</description>
<items>
<relays type="ArrayField">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public function run($model)
foreach (explode(',', (string)$legacy->interface) as $interface) {
$node = $model->relays->add();
$node->setNodes([
'agent_info' => !empty($legacy->agentoption),
'enabled' => !empty($legacy->enable),
'agent_info' => !empty($legacy->agentoption) ? '1' : '0',
'enabled' => !empty($legacy->enable) ? '1' : '0',
'interface' => (string)$interface,
'destination' => $dest_uuid,
]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

/*
* Copyright (C) 2024 Deciso B.V.
* 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.
*/

namespace OPNsense\DHCRelay\Migrations;

use OPNsense\Base\BaseModelMigration;
use OPNsense\Base\FieldTypes\BooleanField;
use OPNsense\Base\FieldTypes\NetworkField;
use OPNsense\Base\FieldTypes\PortField;
use OPNsense\Core\Config;

class M1_0_1 extends BaseModelMigration
{
/**
* Migrate older models into shared model
* @param $model
*/
public function run($model)
{
$config = Config::getInstance()->object();

$legacy = $config->dhcrelay6;
if (empty($legacy->interface) || empty($legacy->server)) {
/* no value in partial migration so skip all */
return;
}

$node = $model->destinations->add();
$node->setNodes([
'name' => 'Migrated IPv6 server entry',
'server' => (string)$legacy->server,
]);
$dest_uuid = $node->getAttribute('uuid');

foreach (explode(',', (string)$legacy->interface) as $interface) {
$node = $model->relays->add();
$node->setNodes([
'agent_info' => !empty($legacy->agentoption) ? '1' : '0',
'enabled' => !empty($legacy->enable) ? '1' : '0',
'interface' => (string)$interface,
'destination' => $dest_uuid,
]);
$node->interface->normalizeValue();
if (empty((string)$node->interface)) {
$model->relays->del($node->getAttribute('uuid'));
}
}
}

public function post($model)
{
$config = Config::getInstance()->object();
unset($config->dhcrelay6);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# Local syslog-ng configuration filter definition [dhcpd].
###################################################################
filter f_local_dhcpd {
facility(local7) or program("dhcpd") or program("dhcrelay");
facility(local7) or program("dhcpd");
};
10 changes: 0 additions & 10 deletions src/www/services_dhcpv6.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,6 @@ function reconfigure_dhcpd()
}
}
}

/* make sure that the DHCP Relay isn't enabled on this interface */
if (isset($config['dhcrelay'][$if]['enable'])) {
$input_errors[] = sprintf(gettext("You must disable the DHCP relay on the %s interface before enabling the DHCP server."),
!empty($config['interfaces'][$if]['descr']) ? htmlspecialchars($config['interfaces'][$if]['descr']) : strtoupper($if));
}
}

if (count($input_errors) == 0) {
Expand Down Expand Up @@ -424,9 +418,6 @@ function show_netboot_config() {
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php if (!empty($config['dhcrelay6']['enabled'])): ?>
<?php print_info_box(gettext('DHCP Relay is currently enabled. Cannot enable the DHCP Server service while the DHCP Relay is enabled on any interface.')); ?>
<?php else: ?>
<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
<?php if (isset($savemsg)) print_info_box($savemsg); ?>
<?php if (is_subsystem_dirty('staticmaps')): ?><p>
Expand Down Expand Up @@ -798,7 +789,6 @@ function show_netboot_config() {
</table>
</div>
</div>
<?php endif; ?>
</section>
</div>
</div>
Expand Down
Loading

0 comments on commit ad5fed3

Please sign in to comment.