From 21d3ff051fae292804f578583724b410a3318292 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Wed, 12 Sep 2018 08:59:06 +0200 Subject: [PATCH] system: iterate over gateways without $config access Positive side-effect is we don't have to sanity-check access anymore. --- src/etc/inc/system.inc | 48 +++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/src/etc/inc/system.inc b/src/etc/inc/system.inc index 68f8855f0..087b9f816 100644 --- a/src/etc/inc/system.inc +++ b/src/etc/inc/system.inc @@ -464,8 +464,6 @@ function system_default_route($gateway, $family, $interface, $far = false) function system_routing_configure($verbose = false, $interface = '') { - global $config; - if ($verbose) { echo 'Setting up routes...'; flush(); @@ -486,31 +484,29 @@ function system_routing_configure($verbose = false, $interface = '') log_error("ROUTING: entering configure using defaults"); } - if (isset($config['gateways']['gateway_item'])) { - foreach ($config['gateways']['gateway_item'] as $gateway) { - if (isset($gateway['defaultgw'])) { - if ($foundgw == false && $gateway['ipprotocol'] != 'inet6') { - if ($gateway['gateway'] == 'dynamic') { - $gateway['gateway'] = get_interface_gateway($gateway['interface']); - } - - $interfacegw = $gateway['interface']; - $fargw = isset($gateway['fargw']); - $gatewayip = $gateway['gateway']; - $foundgw = true; - - log_error("ROUTING: IPv4 default gateway set to {$interfacegw}"); - } elseif ($foundgwv6 == false && $gateway['ipprotocol'] == 'inet6') { - if ($gateway['gateway'] == 'dynamic') { - $gateway['gateway'] = get_interface_gateway_v6($gateway['interface']); - } - - $interfacegwv6 = $gateway['interface']; - $gatewayipv6 = $gateway['gateway']; - $foundgwv6 = true; - - log_error("ROUTING: IPv6 default gateway set to {$interfacegwv6}"); + foreach (config_read_array('gateways', 'gateway_item') as $gateway) { + if (isset($gateway['defaultgw'])) { + if ($foundgw == false && $gateway['ipprotocol'] != 'inet6') { + if ($gateway['gateway'] == 'dynamic') { + $gateway['gateway'] = get_interface_gateway($gateway['interface']); } + + $interfacegw = $gateway['interface']; + $fargw = isset($gateway['fargw']); + $gatewayip = $gateway['gateway']; + $foundgw = true; + + log_error("ROUTING: IPv4 default gateway set to {$interfacegw}"); + } elseif ($foundgwv6 == false && $gateway['ipprotocol'] == 'inet6') { + if ($gateway['gateway'] == 'dynamic') { + $gateway['gateway'] = get_interface_gateway_v6($gateway['interface']); + } + + $interfacegwv6 = $gateway['interface']; + $gatewayipv6 = $gateway['gateway']; + $foundgwv6 = true; + + log_error("ROUTING: IPv6 default gateway set to {$interfacegwv6}"); } } }