From a6340f80321cabceb500d9d740e1617d06c7f0d2 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Fri, 12 Apr 2019 14:53:03 +0200 Subject: [PATCH] Routing, gateways. add getAddress() method to return a gateways address. for https://github.com/opnsense/core/issues/2279 --- .../app/library/OPNsense/Routing/Gateways.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/opnsense/mvc/app/library/OPNsense/Routing/Gateways.php b/src/opnsense/mvc/app/library/OPNsense/Routing/Gateways.php index 1cb6a4661..e5481a500 100644 --- a/src/opnsense/mvc/app/library/OPNsense/Routing/Gateways.php +++ b/src/opnsense/mvc/app/library/OPNsense/Routing/Gateways.php @@ -310,4 +310,23 @@ class Gateways return false; } + /** + * @param string $name gateway name + * @return string|null gateway address + */ + public function getAddress($name) + { + foreach ($this->getGateways() as $gateway) { + if ($gateway['name'] == $name && !empty($gateway['gateway'])){ + $result = $gateway['gateway']; + if (strtolower(substr($gateway['gateway'], 0, 5)) == "fe80:") { + // link local, suffix interface + $result .= "%{$gw['if']}"; + } + return $result; + } + } + return null; + } + }