dhcp: DHCRelay model migration #6983

It would be nice to have both IPv4 and IPv6 in here but it may be
less desirable in practice.  For now use a shared namespace and
only migrate IPv4 switching the binary and breaking everything
in the process.
This commit is contained in:
Franco Fichtner 2023-11-21 15:07:31 +01:00
parent f673d7f01b
commit 7d80f955de
7 changed files with 161 additions and 8 deletions

View File

@ -132,6 +132,7 @@ CORE_DEPENDS?= ca_root_nss \
choparp \
cpustats \
dhcp6c \
dhcrelay \
dnsmasq \
dpinger \
expiretable \
@ -141,7 +142,6 @@ CORE_DEPENDS?= ca_root_nss \
hostapd \
ifinfo \
iftop \
isc-dhcp44-relay \
isc-dhcp44-server \
kea \
lighttpd \

3
plist
View File

@ -593,6 +593,9 @@
/usr/local/opnsense/mvc/app/models/OPNsense/Cron/Migrations/M1_0_2.php
/usr/local/opnsense/mvc/app/models/OPNsense/Cron/Migrations/M1_0_3.php
/usr/local/opnsense/mvc/app/models/OPNsense/Cron/Migrations/M1_0_4.php
/usr/local/opnsense/mvc/app/models/OPNsense/DHCRelay/DHCRelay.php
/usr/local/opnsense/mvc/app/models/OPNsense/DHCRelay/DHCRelay.xml
/usr/local/opnsense/mvc/app/models/OPNsense/DHCRelay/Migrations/M1_0_0.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

View File

@ -400,7 +400,7 @@ function core_xmlrpc_sync()
);
$result[] = array(
'description' => gettext('DHCPv4: Relay'),
'section' => 'dhcrelay',
'section' => 'dhcrelay,OPNsense.DHCRelay',
'id' => 'dhcrelay',
'services' => ["dhcrelay"],
);

View File

@ -0,0 +1,35 @@
<?php
/*
* Copyright (C) 2023 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;
use OPNsense\Base\BaseModel;
class DHCRelay extends BaseModel
{
}

View File

@ -0,0 +1,40 @@
<model>
<mount>//OPNsense/DHCRelay</mount>
<version>1.0.0</version>
<description>DHCRelay configuration</description>
<items>
<relays type="ArrayField">
<enabled type="BooleanField">
<Required>Y</Required>
</enabled>
<interface type="InterfaceField">
<Required>Y</Required>
</interface>
<destination type="ModelRelationField">
<Model>
<template>
<source>OPNsense.DHCRelay.DHCRelay</source>
<items>destinations</items>
<display>description</display>
</template>
</Model>
<Required>Y</Required>
</destination>
<agent_info type="BooleanField">
<Required>Y</Required>
</agent_info>
</relays>
<destinations type="ArrayField">
<server type="NetworkField">
<Required>Y</Required>
<NetMaskAllowed>N</NetMaskAllowed>
<AddressFamily>ipv4</AddressFamily>
<AsList>Y</AsList>
<FieldSeparator>,</FieldSeparator>
</server>
<description type="TextField">
<Required>Y</Required>
</description>
</destinations>
</items>
</model>

View File

@ -0,0 +1,81 @@
<?php
/*
* Copyright (C) 2023 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_0 extends BaseModelMigration
{
/**
* Migrate older models into shared model
* @param $model
*/
public function run($model)
{
$config = Config::getInstance()->object();
$legacy = $config->dhcrelay;
if (empty($legacy->interface) || empty($legacy->server)) {
/* no value in partial migration so skip all */
return;
}
$node = $model->destinations->add();
$node->setNodes([
'server' => (string)$legacy->server,
'description' => 'Migrated server entry',
]);
$dest_uuid = $node->getAttribute('uuid');
foreach (explode(',', (string)$legacy->interface) as $interface) {
$node = $model->relays->add();
$node->setNodes([
'agent_info' => !empty($legacy->agentoption),
'enabled' => !empty($legacy->enable),
'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();
// XXX later
//unset($config->dhcrelay);
}
}

View File

@ -102,11 +102,6 @@ include("head.inc");
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php
if ($dhcpd_enabled) {
print_info_box(gettext('DHCP Server is currently enabled. Cannot enable the DHCP Relay service while the DHCP Server is enabled on any interface.'));
} else {
?>
<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
<?php if (isset($savemsg)) print_info_box($savemsg); ?>
<section class="col-xs-12">
@ -179,7 +174,6 @@ include("head.inc");
</form>
</div>
</section>
<?php } ?>
</div>
</div>
</section>