From 19d9146637b36dd8cb3d42e300c44d4a8ccfe6d2 Mon Sep 17 00:00:00 2001 From: Ermal Date: Wed, 6 Apr 2011 14:58:27 +0000 Subject: Another sweep at keeping the default route always present when the default setup route is marked as down. This now adds checks for configuration where a defaultgw is not specified by the user but deduced automatically. --- etc/inc/gwlb.inc | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'etc/inc') diff --git a/etc/inc/gwlb.inc b/etc/inc/gwlb.inc index 75dc775..50bd5c3 100644 --- a/etc/inc/gwlb.inc +++ b/etc/inc/gwlb.inc @@ -373,23 +373,33 @@ function return_gateway_groups_array() { */ $upgw = ""; $dfltgwdown = false; + $dfltgwfound = false; foreach ($gateways_arr as $gwname => $gwsttng) { - if ($gwsttng['defaultgw'] == true && stristr($gateways_status[$gwname]['status'], "down")) - $dfltgwdown = true; + if (isset($gwsttng['defaultgw'])) { + $dfltgwfound = true; + if (stristr($gateways_status[$gwname]['status'], "down")) + $dfltgwdown = true; + } /* Keep a record of the last up gateway */ if (empty($upgw) && !stristr($gateways_status[$gwname]['status'], "down")) $upgw = $gwname; - if ($dfltgwdown == true && !empty($upgw)) { - if ($gateways_arr[$upgw]['gateway'] == "dynamic") - $gateways_arr[$upgw]['gateway'] = get_interface_gateway($gateways_arr[$upgw]['friendlyiface']); - if (is_ipaddr($gateways_arr[$upgw]['gateway'])) { - log_error("Default gateway down setting {$upgw} as default!"); - mwexec("/sbin/route delete -inet default; /sbin/route add -inet default {$gateways_arr[$upgw]['gateway']}"); - } + if ($dfltgwdown == true && !empty($upgw)) break; + } + if ($dfltgwfound == false) { + $gwname = convert_friendly_interface_to_friendly_descr("wan"); + if (stristr($gateways_status[$gwname]['status'], "down")) + $dfltgwdown = true; + } + if ($dfltgwdown == true && !empty($upgw)) { + if ($gateways_arr[$upgw]['gateway'] == "dynamic") + $gateways_arr[$upgw]['gateway'] = get_interface_gateway($gateways_arr[$upgw]['friendlyiface']); + if (is_ipaddr($gateways_arr[$upgw]['gateway'])) { + log_error("Default gateway down setting {$upgw} as default!"); + mwexec("/sbin/route delete -inet default; /sbin/route add -inet default {$gateways_arr[$upgw]['gateway']}"); } } - unset($upgw, $dfltgwdown, $gwname, $gwsttng); + unset($upgw, $dfltgwfound, $dfltgwdown, $gwname, $gwsttng); if (is_array($config['gateways']['gateway_group'])) { foreach($config['gateways']['gateway_group'] as $group) { -- cgit v1.1