mirror of
https://github.com/opnsense/core.git
synced 2026-10-12 02:20:36 +00:00
interfaces: offload $legacybools and $legacyempties to NetworkInterface model; closes #10918
So we can fix the mocked $config apply in apply_pending_if_changes.php. Ideally, toLegacy() should already do this and we just replace the whole interface section in the script.
This commit is contained in:
@@ -32,6 +32,7 @@ use OPNsense\Base\ApiMutableModelControllerBase;
|
||||
use OPNsense\Base\UserException;
|
||||
use OPNsense\Core\Backend;
|
||||
use OPNsense\Core\Config;
|
||||
use OPNsense\Interfaces\NetworkInterface;
|
||||
|
||||
class AssignmentController extends ApiMutableModelControllerBase
|
||||
{
|
||||
@@ -139,30 +140,6 @@ class AssignmentController extends ApiMutableModelControllerBase
|
||||
|
||||
public function reconfigureAction()
|
||||
{
|
||||
$legacybools = [
|
||||
'blockbogons',
|
||||
'blockpriv',
|
||||
'dhcp6-ia-pd-send-hint',
|
||||
'dhcp6-information-only',
|
||||
'dhcp6_norequest_dns',
|
||||
'dhcp6_rapid_commit',
|
||||
'dhcp6prefixonly',
|
||||
'dhcpd6track6allowoverride',
|
||||
'dhcphonourmtu',
|
||||
'disablechecksumoffloading',
|
||||
'disablelargereceiveoffloading',
|
||||
'disablesegmentationoffloading',
|
||||
'disablevlanhwfilter',
|
||||
'enable',
|
||||
'gateway_interface',
|
||||
'hw_settings_overwrite',
|
||||
'lock',
|
||||
'promisc',
|
||||
];
|
||||
$legacyempties = [
|
||||
'descr',
|
||||
'spoofmac',
|
||||
];
|
||||
if ($this->request->isPost()) {
|
||||
$this->throwReadOnly();
|
||||
$backend = new Backend();
|
||||
@@ -189,12 +166,13 @@ class AssignmentController extends ApiMutableModelControllerBase
|
||||
unset(Config::getInstance()->object()->interfaces->$key->$akey);
|
||||
}
|
||||
}
|
||||
foreach ($legacybools as $legacybool) {
|
||||
/* XXX should be in toLegacy() */
|
||||
foreach (NetworkInterface::$legacybools as $legacybool) {
|
||||
if (empty($pending[$legacybool])) {
|
||||
unset(Config::getInstance()->object()->interfaces->$key->$legacybool);
|
||||
}
|
||||
}
|
||||
foreach ($legacyempties as $legacyempty) {
|
||||
foreach (NetworkInterface::$legacyempties as $legacyempty) {
|
||||
if (!strlen($pending[$legacyempty] ?? '')) {
|
||||
Config::getInstance()->object()->interfaces->$key->$legacyempty = '';
|
||||
}
|
||||
|
||||
@@ -38,6 +38,31 @@ use OPNsense\Routing\Gateways;
|
||||
|
||||
class NetworkInterface extends BaseModel
|
||||
{
|
||||
public static $legacybools = [
|
||||
'blockbogons',
|
||||
'blockpriv',
|
||||
'dhcp6-ia-pd-send-hint',
|
||||
'dhcp6-information-only',
|
||||
'dhcp6_norequest_dns',
|
||||
'dhcp6_rapid_commit',
|
||||
'dhcp6prefixonly',
|
||||
'dhcpd6track6allowoverride',
|
||||
'dhcphonourmtu',
|
||||
'disablechecksumoffloading',
|
||||
'disablelargereceiveoffloading',
|
||||
'disablesegmentationoffloading',
|
||||
'disablevlanhwfilter',
|
||||
'enable',
|
||||
'gateway_interface',
|
||||
'hw_settings_overwrite',
|
||||
'lock',
|
||||
'promisc',
|
||||
];
|
||||
public static $legacyempties = [
|
||||
'descr',
|
||||
'spoofmac',
|
||||
];
|
||||
|
||||
var $todo_file = '/tmp/.interfaces.todo';
|
||||
|
||||
/**
|
||||
@@ -130,6 +155,7 @@ class NetworkInterface extends BaseModel
|
||||
$intf->descr = $interfaces[$key]['descr'];
|
||||
/* flush actions that need to be applied, for which we need history (config reflects running config) */
|
||||
$todo = [
|
||||
/* XXX toLegacy() unfortunately isn't legacy yet, which matters in apply_pending_if_changes.php */
|
||||
'pending' => $this->interface->$key->toLegacy(),
|
||||
'pending_action' => 'update',
|
||||
];
|
||||
|
||||
@@ -32,6 +32,8 @@ require_once("system.inc");
|
||||
require_once("config.inc");
|
||||
require_once("util.inc");
|
||||
|
||||
use OPNsense\Interfaces\NetworkInterface;
|
||||
|
||||
if (is_array($config['interfaces'])) {
|
||||
if (is_file('/tmp/.interfaces.todo')) {
|
||||
$todos = (new \OPNsense\Core\FileObject('/tmp/.interfaces.todo', 'r'))->readJson() ?? [];
|
||||
@@ -71,11 +73,17 @@ if (is_array($config['interfaces'])) {
|
||||
unset($config['interfaces'][$ifname][$key]);
|
||||
}
|
||||
}
|
||||
foreach (['enable', 'lock'] as $legacybool) {
|
||||
/* XXX should be toLegacy() */
|
||||
foreach (NetworkInterface::$legacybools as $legacybool) {
|
||||
if (empty($pending[$legacybool])) {
|
||||
unset($config['interfaces'][$ifname][$legacybool]);
|
||||
}
|
||||
}
|
||||
foreach (NetworkInterface::$legacyempties as $legacyempty) {
|
||||
if (!strlen($pending[$legacyempty] ?? '')) {
|
||||
$config['interfaces'][$ifname][$legacybool][$legacyempty] = '';
|
||||
}
|
||||
}
|
||||
/* Reload all for the interface. */
|
||||
interface_configure(false, $ifname, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user