mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-15 09:04:39 +00:00
Firewall / Alias - remove global $aliastable reference and use our shared \OPNsense\Firewall\Util::isAlias() instead. closes https://github.com/opnsense/core/issues/5423
Although a direct table lookup will be faster than using a lookup in isAlias(), it's likely not problematic to have a slightly slower lookup using is_alias(), but if performance is of the essence at some point we can easily cache results in isAlias() to reach the same target.
This commit is contained in:
parent
e4d5478662
commit
c281f1e573
@ -63,23 +63,11 @@ function load_config_from_file($filename)
|
||||
******/
|
||||
function parse_config()
|
||||
{
|
||||
global $aliastable;
|
||||
|
||||
$cnf = OPNsense\Core\Config::getInstance();
|
||||
|
||||
// return config data as array, use old "listags" construction to mark certain elements as array (even if they're not recurring)
|
||||
$config = $cnf->toArray(listtags());
|
||||
|
||||
$aliastable = array();
|
||||
|
||||
foreach ((new \OPNsense\Firewall\Alias())->aliasIterator() as $alias) {
|
||||
if (strncmp($alias['type'], 'url', 3) !== 0) {
|
||||
$aliastable[$alias['name']] = implode(" ", explode("\n", $alias['content']));
|
||||
} else {
|
||||
$aliastable[$alias['name']] = "";
|
||||
}
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
@ -543,7 +543,7 @@ function system_routing_configure($verbose = false, $interface = '')
|
||||
|
||||
function system_staticroutes_configure($interface = '')
|
||||
{
|
||||
$static_routes = get_staticroutes(false, true);
|
||||
$static_routes = get_staticroutes(false);
|
||||
if (count($static_routes)) {
|
||||
$ifdetails = legacy_interfaces_details();
|
||||
$gateways_arr = (new \OPNsense\Routing\Gateways($ifdetails))->gatewaysIndexedByName(false, true);
|
||||
|
||||
@ -1027,8 +1027,7 @@ function mwexecf_bg($format, $args = array(), $mute = false)
|
||||
/* check if an alias exists */
|
||||
function is_alias($name)
|
||||
{
|
||||
global $aliastable;
|
||||
return array_key_exists($name, $aliastable);
|
||||
return \OPNsense\Firewall\Util::isAlias($name);
|
||||
}
|
||||
|
||||
function subnet_size($subnet)
|
||||
@ -1241,36 +1240,14 @@ function is_URL($url)
|
||||
return false;
|
||||
}
|
||||
|
||||
function get_staticroutes($returnsubnetsonly = false, $returnhostnames = false)
|
||||
function get_staticroutes($returnsubnetsonly=false)
|
||||
{
|
||||
global $aliastable;
|
||||
|
||||
$allstaticroutes = array();
|
||||
$allsubnets = array();
|
||||
|
||||
/* Loop through routes and expand aliases as we find them. */
|
||||
$allstaticroutes = [];
|
||||
$allsubnets = [];
|
||||
foreach (config_read_array('staticroutes', 'route') as $route) {
|
||||
if (is_alias($route['network'])) {
|
||||
if (!isset($aliastable[$route['network']])) {
|
||||
continue;
|
||||
}
|
||||
$subnets = preg_split('/\s+/', $aliastable[$route['network']]);
|
||||
foreach ($subnets as $net) {
|
||||
if (!is_subnet($net)) {
|
||||
if (is_ipaddrv4($net)) {
|
||||
$net .= "/32";
|
||||
} elseif (is_ipaddrv6($net)) {
|
||||
$net .= "/128";
|
||||
} elseif ($returnhostnames === false || !is_fqdn($net)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$temproute = $route;
|
||||
$temproute['network'] = $net;
|
||||
$allstaticroutes[] = $temproute;
|
||||
$allsubnets[] = $net;
|
||||
}
|
||||
} elseif (is_subnet($route['network'])) {
|
||||
if (is_subnet($route['network'])) {
|
||||
$allstaticroutes[] = $route;
|
||||
$allsubnets[] = $route['network'];
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user