diff --git a/src/etc/inc/plugins.inc.d/dpinger.inc b/src/etc/inc/plugins.inc.d/dpinger.inc index 01f0276fa..534f4df42 100644 --- a/src/etc/inc/plugins.inc.d/dpinger.inc +++ b/src/etc/inc/plugins.inc.d/dpinger.inc @@ -121,6 +121,13 @@ function dpinger_instances($extended = false) } } + foreach (\OPNsense\Routing\Gateways::getDpingerDefaults() as $key => $value) { + /* make sure callers can reliably query the dpinger settings */ + if (empty($gateway[$key])) { + $gateway[$key] = $value; + } + } + $instances[$name] = $gateway; } diff --git a/src/opnsense/mvc/app/models/OPNsense/Routing/Gateways.php b/src/opnsense/mvc/app/models/OPNsense/Routing/Gateways.php index ac5b0e907..552c97529 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Routing/Gateways.php +++ b/src/opnsense/mvc/app/models/OPNsense/Routing/Gateways.php @@ -72,9 +72,13 @@ class Gateways extends BaseModel $tagName = $node->getInternalXMLTagName(); if (array_key_exists($tagName, $defaults)) { if (empty((string)$node)) { - // Since dpinger values are not required in the model, - // we set them to the defaults here if they're empty. + /* + * Since dpinger values are not required in the model, + * we set them to the defaults here if they're empty, but keep them virtual so + * they're not persisted. The validations below might depend on the values being set. + */ $node->setValue($defaults[$tagName]); + $node->setInternalIsVirtual(true); } } } @@ -272,7 +276,8 @@ class Gateways extends BaseModel foreach ($this->getDpingerDefaults() as $key => $value) { if (empty($record[$key])) { - $record[$key] = $value; + // make sure node exists without value set + $record[$key] = ''; } } $record['uuid'] = ''; diff --git a/src/opnsense/mvc/app/models/OPNsense/Routing/Migrations/M1_0_0.php b/src/opnsense/mvc/app/models/OPNsense/Routing/Migrations/M1_0_0.php index 3b4c4b240..52aed0777 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Routing/Migrations/M1_0_0.php +++ b/src/opnsense/mvc/app/models/OPNsense/Routing/Migrations/M1_0_0.php @@ -74,13 +74,6 @@ class M1_0_0 extends BaseModelMigration $node->$key = (string)$value; } - // apply dpinger defaults if old model didn't have them set - foreach (Gateways::getDpingerDefaults() as $key => $value) { - if (empty((string)$node->$key)) { - $node->$key = $value; - } - } - // increase time period if old model had it set too low $min_time_period = 2 * (intval((string)$node->interval) + intval((string)$node->loss_interval)); if ((string)$node->time_period < $min_time_period) {