Commit f5c2ddb4 authored by Franco Fichtner's avatar Franco Fichtner

gateways: change the approach for gateway generation

Instead of injecting dynamic gateways after reading the config, we will
inject them before instead.  This gives us the opportinuity to check
for matches and remove disabled gateways, finally addressing #933 in a
sane way.

(cherry picked from commit 125808e2)
parent c3a711c0
...@@ -491,92 +491,6 @@ function return_gateways_array($disabled = false, $localhost = false, $inactive ...@@ -491,92 +491,6 @@ function return_gateways_array($disabled = false, $localhost = false, $inactive
$interfaces_v4 = array(); $interfaces_v4 = array();
$interfaces_v6 = array(); $interfaces_v6 = array();
$i = -1;
/* Process/add all the configured gateways. */
if (isset($config['gateways']['gateway_item'])) {
foreach ($config['gateways']['gateway_item'] as $gateway) {
/* Increment it here to do not skip items */
$i++;
if (empty($config['interfaces'][$gateway['interface']])) {
if ($inactive === false) {
continue;
} else {
$gateway['inactive'] = true;
}
}
$wancfg = $config['interfaces'][$gateway['interface']];
/* skip disabled interfaces */
if ($disabled === false && (!isset($wancfg['enable']) || isset($gateway['disabled']))) {
continue;
}
/* if the gateway is dynamic and we can find the IPv4, Great! */
if (empty($gateway['gateway']) || $gateway['gateway'] == "dynamic") {
if ($gateway['ipprotocol'] == "inet") {
/* we know which interfaces is dynamic, this should be made a function */
$gateway['gateway'] = get_interface_gateway($gateway['interface']);
/* no IP address found, set to dynamic */
if (!is_ipaddrv4($gateway['gateway'])) {
$gateway['gateway'] = "dynamic";
}
$gateway['dynamic'] = true;
} elseif ($gateway['ipprotocol'] == "inet6") {
/* if the gateway is dynamic and we can find the IPv6, Great! */
/* we know which interfaces is dynamic, this should be made a function, and for v6 too */
$gateway['gateway'] = get_interface_gateway_v6($gateway['interface']);
/* no IPv6 address found, set to dynamic */
if (!is_ipaddrv6($gateway['gateway'])) {
$gateway['gateway'] = "dynamic";
}
$gateway['dynamic'] = true;
}
} else {
/* getting this detection right is hard at this point because we still don't
* store the address family in the gateway item */
if (is_ipaddrv4($gateway['gateway'])) {
$gateway['ipprotocol'] = "inet";
} elseif (is_ipaddrv6($gateway['gateway'])) {
$gateway['ipprotocol'] = "inet6";
}
}
if (isset($gateway['monitor_disable'])) {
$gateway['monitor_disable'] = true;
} elseif (empty($gateway['monitor'])) {
$gateway['monitor'] = $gateway['gateway'];
}
$gateway['friendlyiface'] = $gateway['interface'];
/* special treatment for tunnel interfaces */
if ($gateway['ipprotocol'] == "inet6") {
$gateway['interface'] = get_real_interface($gateway['interface'], "inet6", false, false);
$interfaces_v6[$gateway['friendlyiface']] = $gateway['friendlyiface'];
} else {
$gateway['interface'] = get_real_interface($gateway['interface'], "all", false, false);
$interfaces_v4[$gateway['friendlyiface']] = $gateway['friendlyiface'];
}
/* entry has a default flag, use it */
if (isset($gateway['defaultgw'])) {
if ($gateway['ipprotocol'] == "inet") {
$gateway['defaultgw'] = true;
$found_defaultv4 = 1;
} else if ($gateway['ipprotocol'] == "inet6") {
$gateway['defaultgw'] = true;
$found_defaultv6 = 1;
}
}
/* include the gateway index as the attribute */
$gateway['attribute'] = $i;
$gateways_arr[$gateway['name']] = $gateway;
}
}
unset($gateway);
/* Loop through all interfaces with a gateway and add it to a array */ /* Loop through all interfaces with a gateway and add it to a array */
if ($disabled == false) { if ($disabled == false) {
$iflist = get_configured_interface_with_descr(); $iflist = get_configured_interface_with_descr();
...@@ -585,8 +499,8 @@ function return_gateways_array($disabled = false, $localhost = false, $inactive ...@@ -585,8 +499,8 @@ function return_gateways_array($disabled = false, $localhost = false, $inactive
} }
/* Process/add dynamic v4 gateways. */ /* Process/add dynamic v4 gateways. */
foreach($iflist as $ifname => $friendly ) { foreach ($iflist as $ifname => $friendly) {
if (! interface_has_gateway($ifname)) { if (!interface_has_gateway($ifname)) {
continue; continue;
} }
...@@ -653,7 +567,7 @@ function return_gateways_array($disabled = false, $localhost = false, $inactive ...@@ -653,7 +567,7 @@ function return_gateways_array($disabled = false, $localhost = false, $inactive
} }
/* automatically skip known static and dynamic gateways we have a array entry for */ /* automatically skip known static and dynamic gateways we have a array entry for */
foreach($gateways_arr as $gateway_item) { foreach ($gateways_arr as $gateway_item) {
if ((($ifname == $gateway_item['friendlyiface'] && $friendly == $gateway_item['name'])&& ($gateway['ipprotocol'] == $gateway_item['ipprotocol'])) || if ((($ifname == $gateway_item['friendlyiface'] && $friendly == $gateway_item['name'])&& ($gateway['ipprotocol'] == $gateway_item['ipprotocol'])) ||
($ifname == $gateway_item['friendlyiface'] && $gateway_item['dynamic'] == true) && ($gateway['ipprotocol'] == $gateway_item['ipprotocol'])) { ($ifname == $gateway_item['friendlyiface'] && $gateway_item['dynamic'] == true) && ($gateway['ipprotocol'] == $gateway_item['ipprotocol'])) {
continue 2; continue 2;
...@@ -671,7 +585,7 @@ function return_gateways_array($disabled = false, $localhost = false, $inactive ...@@ -671,7 +585,7 @@ function return_gateways_array($disabled = false, $localhost = false, $inactive
unset($gateway); unset($gateway);
/* Process/add dynamic v6 gateways. */ /* Process/add dynamic v6 gateways. */
foreach($iflist as $ifname => $friendly ) { foreach ($iflist as $ifname => $friendly) {
/* If the user has disabled IPv6, they probably don't want any IPv6 gateways. */ /* If the user has disabled IPv6, they probably don't want any IPv6 gateways. */
if (!isset($config['system']['ipv6allow'])) { if (!isset($config['system']['ipv6allow'])) {
break; break;
...@@ -771,6 +685,95 @@ function return_gateways_array($disabled = false, $localhost = false, $inactive ...@@ -771,6 +685,95 @@ function return_gateways_array($disabled = false, $localhost = false, $inactive
} }
unset($gateway); unset($gateway);
$i = -1;
/* Process/add all the configured gateways. */
if (isset($config['gateways']['gateway_item'])) {
foreach ($config['gateways']['gateway_item'] as $gateway) {
/* Increment it here to do not skip items */
$i++;
if (empty($config['interfaces'][$gateway['interface']])) {
if ($inactive === false) {
continue;
} else {
$gateway['inactive'] = true;
}
}
$wancfg = $config['interfaces'][$gateway['interface']];
/* skip disabled interfaces */
if ($disabled === false && (!isset($wancfg['enable']) || isset($gateway['disabled']))) {
if (isset($gateways_arr[$gateway['name']])) {
unset($gateways_arr[$gateway['name']]);
}
continue;
}
/* if the gateway is dynamic and we can find the IPv4, Great! */
if (empty($gateway['gateway']) || $gateway['gateway'] == "dynamic") {
if ($gateway['ipprotocol'] == "inet") {
/* we know which interfaces is dynamic, this should be made a function */
$gateway['gateway'] = get_interface_gateway($gateway['interface']);
/* no IP address found, set to dynamic */
if (!is_ipaddrv4($gateway['gateway'])) {
$gateway['gateway'] = "dynamic";
}
$gateway['dynamic'] = true;
} elseif ($gateway['ipprotocol'] == "inet6") {
/* if the gateway is dynamic and we can find the IPv6, Great! */
/* we know which interfaces is dynamic, this should be made a function, and for v6 too */
$gateway['gateway'] = get_interface_gateway_v6($gateway['interface']);
/* no IPv6 address found, set to dynamic */
if (!is_ipaddrv6($gateway['gateway'])) {
$gateway['gateway'] = "dynamic";
}
$gateway['dynamic'] = true;
}
} else {
/* getting this detection right is hard at this point because we still don't
* store the address family in the gateway item */
if (is_ipaddrv4($gateway['gateway'])) {
$gateway['ipprotocol'] = "inet";
} elseif (is_ipaddrv6($gateway['gateway'])) {
$gateway['ipprotocol'] = "inet6";
}
}
if (isset($gateway['monitor_disable'])) {
$gateway['monitor_disable'] = true;
} elseif (empty($gateway['monitor'])) {
$gateway['monitor'] = $gateway['gateway'];
}
$gateway['friendlyiface'] = $gateway['interface'];
/* special treatment for tunnel interfaces */
if ($gateway['ipprotocol'] == "inet6") {
$gateway['interface'] = get_real_interface($gateway['interface'], "inet6", false, false);
$interfaces_v6[$gateway['friendlyiface']] = $gateway['friendlyiface'];
} else {
$gateway['interface'] = get_real_interface($gateway['interface'], "all", false, false);
$interfaces_v4[$gateway['friendlyiface']] = $gateway['friendlyiface'];
}
/* entry has a default flag, use it */
if (isset($gateway['defaultgw'])) {
if ($gateway['ipprotocol'] == "inet") {
$gateway['defaultgw'] = true;
$found_defaultv4 = 1;
} else if ($gateway['ipprotocol'] == "inet6") {
$gateway['defaultgw'] = true;
$found_defaultv6 = 1;
}
}
/* include the gateway index as the attribute */
$gateway['attribute'] = $i;
$gateways_arr[$gateway['name']] = $gateway;
}
}
unset($gateway);
/* FIXME: Should this be enabled. /* FIXME: Should this be enabled.
* Some interface like wan might be default but have no info recorded * Some interface like wan might be default but have no info recorded
* the config. */ * the config. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment