Skip to content

Commit

Permalink
system: repair system default route handling; closes #2164
Browse files Browse the repository at this point in the history
  • Loading branch information
fichtner committed Feb 27, 2018
1 parent 60df387 commit 4f955e4
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/etc/inc/system.inc
Original file line number Diff line number Diff line change
Expand Up @@ -465,18 +465,14 @@ function system_routing_configure($interface = '', $verbose = false)

/* tack on all the hard defined gateways as well */
if (isset($config['gateways']['gateway_item'])) {
/* XXX eventually this file-based workaround must be removed */
foreach (glob('/tmp/*_defaultgw{,v6}', GLOB_BRACE) as $to_delete) {
log_error("ROUTING: removing {$to_delete}");
@unlink($to_delete);
}

foreach ($config['gateways']['gateway_item'] as $gateway) {
if (isset($gateway['defaultgw'])) {
if ($gateway['ipprotocol'] != "inet6" && (is_ipaddrv4($gateway['gateway']) || $gateway['gateway'] == "dynamic")) {
if (strstr($gateway['gateway'], ":")) {
continue;
}
if ($foundgw == false && $gateway['ipprotocol'] != "inet6" && (is_ipaddrv4($gateway['gateway']) || $gateway['gateway'] == "dynamic")) {
if ($gateway['gateway'] == "dynamic") {
$gateway['gateway'] = get_interface_gateway($gateway['interface']);
}
Expand All @@ -491,7 +487,7 @@ function system_routing_configure($interface = '', $verbose = false)
}
}
$foundgw = true;
} elseif ($gateway['ipprotocol'] == "inet6" && (is_ipaddrv6($gateway['gateway']) || $gateway['gateway'] == "dynamic")) {
} elseif ($foundgwv6 == false && $gateway['ipprotocol'] == "inet6" && (is_ipaddrv6($gateway['gateway']) || $gateway['gateway'] == "dynamic")) {
if ($gateway['gateway'] == "dynamic") {
$gateway['gateway'] = get_interface_gateway_v6($gateway['interface']);
}
Expand All @@ -510,19 +506,27 @@ function system_routing_configure($interface = '', $verbose = false)
}
}

/*
* From the looks of the code below we cannot cope with
* multi-WAN without setting explicit gateways. This is
* probably where the default gateway switching comes into
* play because this facility is allowed to use dynamically
* created gateways while the former code does not.
*/

if (!$foundgw) {
$defaultif = get_real_interface("wan");
$interfacegw = "wan";
$gatewayip = get_interface_gateway("wan");
@touch("/tmp/{$defaultif}_defaultgw");
@file_put_contents("/tmp/{$defaultif}_defaultgw", $gatewayip);
log_error("ROUTING: no IPv4 default gateway set, trying ${interfacegw} on '{$defaultif}' ({$gatewayip})");
}

if (!$foundgwv6) {
$defaultifv6 = get_real_interface("wan");
$interfacegwv6 = "wan";
$gatewayipv6 = get_interface_gateway_v6("wan");
@touch("/tmp/{$defaultif}_defaultgwv6");
@file_put_contents("/tmp/{$defaultifv6}_defaultgwv6", $gatewayipv6);
log_error("ROUTING: no IPv6 default gateway set, trying ${interfacegwv6} on '{$defaultifv6}' ({$gatewayipv6})");
}

Expand Down

0 comments on commit 4f955e4

Please sign in to comment.