From 99c9dc3da585f1c70716a53fac2305e26b549fee Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Tue, 18 Jan 2022 18:37:37 +0100 Subject: [PATCH] Firewall: Shaper - add kernel constraint for kernel bandwidth limitation, closes https://github.com/opnsense/core/issues/5224 --- .../OPNsense/TrafficShaper/TrafficShaper.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/opnsense/mvc/app/models/OPNsense/TrafficShaper/TrafficShaper.php b/src/opnsense/mvc/app/models/OPNsense/TrafficShaper/TrafficShaper.php index 29e0b64f7..9a5b19df5 100644 --- a/src/opnsense/mvc/app/models/OPNsense/TrafficShaper/TrafficShaper.php +++ b/src/opnsense/mvc/app/models/OPNsense/TrafficShaper/TrafficShaper.php @@ -28,6 +28,7 @@ namespace OPNsense\TrafficShaper; +use Phalcon\Messages\Message; use OPNsense\Base\BaseModel; /** @@ -36,6 +37,42 @@ use OPNsense\Base\BaseModel; */ class TrafficShaper extends BaseModel { + + /** + * {@inheritdoc} + */ + public function performValidation($validateFullModel = false) + { + // standard model validations + $max_bandwith = 4294967295; // bps + $messages = parent::performValidation($validateFullModel); + $all_nodes = $this->getFlatNodes(); + foreach ($all_nodes as $key => $node) { + if ($validateFullModel || $node->isFieldChanged()) { + $parentNode = $node->getParentNode(); + if (in_array($node->getInternalXMLTagName(), ['bandwidth', 'bandwidthMetric'])) { + $currentval = (int)(string)$parentNode->bandwidth; + if ($parentNode->bandwidthMetric == "Kbit") { + $currentval *= 1000; + } elseif ($parentNode->bandwidthMetric == "Mbit") { + $currentval *= 1000000; + } + if ($currentval > $max_bandwith) { + $messages->appendMessage(new Message( + gettext(sprintf( + "%d bit/s exceeds the maximum bandwith of %d bit/s.", $currentval, $max_bandwith + )), + $key + )); + + } + } + } + } + return $messages; + } + + /** * generate new Id by filling a gap or add 1 to the last * @param int $startAt start search at number