mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-15 00:54:41 +00:00
Routing, gateways. kill fixup_default_gateway() and replace with new logic from Gateways() class, remove gw_switch_group[4|6] while at it. for https://github.com/opnsense/core/issues/2279
This commit is contained in:
parent
b64af8fe49
commit
65facfb695
@ -298,8 +298,18 @@ function filter_configure_sync($verbose = false, $flush_states = false, $load_al
|
||||
}
|
||||
|
||||
if (isset($config['system']['gw_switch_default'])) {
|
||||
/* XXX gw_switch_group4 and gw_switch_group6 to pass down: */
|
||||
fixup_default_gateway();
|
||||
// When gateway switching is enabled, we might consider a different default gateway.
|
||||
// although this isn't really the right spot for the feature (it's a monitoring/routing decision),
|
||||
// we keep it here for now (historical reasons).
|
||||
$down_gateways = return_down_gateways();
|
||||
foreach (array("inet", "inet6") as $ipprotocol) {
|
||||
$default_gw = $fw->getGateways()->getDefaultGW($down_gateways, $ipprotocol);
|
||||
if ($default_gw !== null) {
|
||||
system_default_route(
|
||||
$default_gw['gateway'], $ipprotocol, $default_gw['if'], isset($default_gw['fargw'])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$aliases = filter_generate_aliases();
|
||||
|
||||
@ -624,66 +624,6 @@ function return_down_gateways()
|
||||
return $result ;
|
||||
}
|
||||
|
||||
function fixup_default_gateway()
|
||||
{
|
||||
$gateways_status = return_gateways_status();
|
||||
$gateways_arr = return_gateways_array();
|
||||
|
||||
foreach (array("inet", "inet6") as $ipprotocol) {
|
||||
$dfltgwname = null;
|
||||
$dfltgwip = null;
|
||||
$count = 0;
|
||||
|
||||
foreach ($gateways_arr as $gwname => $gwsttng) {
|
||||
if (isset($gwsttng['disabled'])) {
|
||||
/* does not apply */
|
||||
continue;
|
||||
}
|
||||
if ($gwsttng['ipprotocol'] !== $ipprotocol) {
|
||||
/* wrong address family */
|
||||
continue;
|
||||
}
|
||||
if (strpos($gateways_status[$gwname]['status'], 'down') !== false) {
|
||||
/* cannot use down gateway */
|
||||
continue;
|
||||
}
|
||||
|
||||
$gwip = '';
|
||||
|
||||
if ($gateways_arr[$gwname]['gateway'] == "dynamic") {
|
||||
if ($ipprotocol == 'inet') {
|
||||
$gwip = get_interface_gateway($gateways_arr[$gwname]['friendlyiface']);
|
||||
} else {
|
||||
$gwip = get_interface_gateway_v6($gateways_arr[$gwname]['friendlyiface']);
|
||||
}
|
||||
} else {
|
||||
$gwip = $gateways_arr[$gwname]['gateway'];
|
||||
}
|
||||
|
||||
if (!is_ipaddr($gwip)) {
|
||||
log_error("Cannot switch gateway $gwname with undefined address");
|
||||
continue;
|
||||
}
|
||||
|
||||
/* can use this gateway */
|
||||
$dfltgwname = $gwname;
|
||||
$dfltgwip = $gwip;
|
||||
$count += 1;
|
||||
|
||||
if (isset($gwsttng['defaultgw'])) {
|
||||
/* if we found the default to be working use it right away */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($dfltgwname)) {
|
||||
log_error("Cannot switch while $count $ipprotocol gateways are up");
|
||||
continue;
|
||||
}
|
||||
|
||||
system_default_route($dfltgwip, $ipprotocol, $gateways_arr[$dfltgwname]['friendlyiface'], isset($gateways_arr[$dfltgwname]['fargw']));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Return an array with all gateway groups with name as key
|
||||
|
||||
@ -52,8 +52,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
$pconfig['timezone'] = empty($config['system']['timezone']) ? 'Etc/UTC' : $config['system']['timezone'];
|
||||
|
||||
$pconfig['gw_switch_default'] = isset($config['system']['gw_switch_default']);
|
||||
$pconfig['gw_switch_group4'] = isset($config['system']['gw_switch_group4']) ? $config['system']['gw_switch_group4'] : null;
|
||||
$pconfig['gw_switch_group6'] = isset($config['system']['gw_switch_group6']) ? $config['system']['gw_switch_group6'] : null;
|
||||
|
||||
for ($dnscounter = 1; $dnscounter < 9; $dnscounter++) {
|
||||
$dnsname = "dns{$dnscounter}";
|
||||
@ -160,18 +158,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
unset($config['system']['gw_switch_default']);
|
||||
}
|
||||
|
||||
if (!empty($pconfig['gw_switch_group4'])) {
|
||||
$config['system']['gw_switch_group4'] = $pconfig['gw_switch_group4'];
|
||||
} elseif (isset($config['system']['gw_switch_group4'])) {
|
||||
unset($config['system']['gw_switch_group4']);
|
||||
}
|
||||
|
||||
if (!empty($pconfig['gw_switch_group6'])) {
|
||||
$config['system']['gw_switch_group6'] = $pconfig['gw_switch_group6'];
|
||||
} elseif (isset($config['system']['gw_switch_group6'])) {
|
||||
unset($config['system']['gw_switch_group6']);
|
||||
}
|
||||
|
||||
$olddnsservers = $config['system']['dnsserver'];
|
||||
$config['system']['dnsserver'] = array();
|
||||
|
||||
@ -453,28 +439,6 @@ include("head.inc");
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext('IPv4 gateway group') ?></td>
|
||||
<td>
|
||||
<select name="gw_switch_group4" class="selectpicker">
|
||||
<option value="" <?= empty($pconfig['gw_switch_group4']) ? 'selected="selected"' : '' ?>><?= gettext('Any available gateway') ?></option>
|
||||
<?php foreach (config_read_array('gateways', 'gateway_group') as $gwgroup): ?>
|
||||
<option value="<?= html_safe($gwgroup['name']) ?>" <?= $pconfig['gw_switch_group4'] == $gwgroup['name'] ? 'selected="selected"' : '' ?>><?= $gwgroup['name'] ?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext('IPv6 gateway group') ?></td>
|
||||
<td>
|
||||
<select name="gw_switch_group6" class="selectpicker">
|
||||
<option value="" <?= empty($pconfig['gw_switch_group6']) ? 'selected="selected"' : '' ?>><?= gettext('Any available gateway') ?></option>
|
||||
<?php foreach (config_read_array('gateways', 'gateway_group') as $gwgroup): ?>
|
||||
<option value="<?= html_safe($gwgroup['name']) ?>" <?= $pconfig['gw_switch_group6'] == $gwgroup['name'] ? 'selected="selected"' : '' ?>><?= $gwgroup['name'] ?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="content-box tab-content">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user