diff options
author | Ermal <eri@pfsense.org> | 2011-07-22 21:03:31 +0000 |
---|---|---|
committer | Ermal <eri@pfsense.org> | 2011-07-22 21:03:31 +0000 |
commit | e75be7fc01f7448d9f5158294481e475d9ff1954 (patch) | |
tree | dbbe58bb9b811714437be3f891be27ddb56c16fc /etc | |
parent | 73481ad33b6b455e12a61b9632e6736fb5ba6ff8 (diff) | |
download | pfsense-e75be7fc01f7448d9f5158294481e475d9ff1954.zip pfsense-e75be7fc01f7448d9f5158294481e475d9ff1954.tar.gz |
Switch back to the default gateway configured when possible when gateway switching is active
Diffstat (limited to 'etc')
-rw-r--r-- | etc/inc/gwlb.inc | 64 |
1 files changed, 35 insertions, 29 deletions
diff --git a/etc/inc/gwlb.inc b/etc/inc/gwlb.inc index 27e8020..0caa840 100644 --- a/etc/inc/gwlb.inc +++ b/etc/inc/gwlb.inc @@ -373,39 +373,45 @@ function return_gateway_groups_array() { $gateway_groups_array = array(); if (isset($config['system']['gw_switch_default'])) { - /* - * NOTE: The code below is meant to replace the default gateway when it goes down. - * This facilitates services running on pfSense itself and are not handled by a PBR to continue working. - */ - $upgw = ""; - $dfltgwdown = false; - $dfltgwfound = false; - foreach ($gateways_arr as $gwname => $gwsttng) { - if (isset($gwsttng['defaultgw'])) { - $dfltgwfound = true; + /* + * NOTE: The code below is meant to replace the default gateway when it goes down. + * This facilitates services running on pfSense itself and are not handled by a PBR to continue working. + */ + $upgw = ""; + $dfltgwdown = false; + $dfltgwfound = false; + foreach ($gateways_arr as $gwname => $gwsttng) { + if (isset($gwsttng['defaultgw'])) { + $dfltgwfound = true; + $dfltgwname = $gwname; + 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)) + break; + } + if ($dfltgwfound == false) { + $gwname = convert_friendly_interface_to_friendly_descr("wan"); 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)) - 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']}"); + 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']}"); + } + } else { + $defaultgw = trim(`/sbin/route -n get -inet default | /usr/bin/grep gateway | /usr/bin/sed 's/gateway://g'`, " \n"); + if ($defaultgw != $gateways_arr[$dfltgwname]['gateway']) + mwexec("/sbin/route delete -inet default; /sbin/route add -inet default {$gateways_arr[$dfltgwname]['gateway']}"); } - } - unset($upgw, $dfltgwfound, $dfltgwdown, $gwname, $gwsttng); + + unset($upgw, $dfltgwfound, $dfltgwdown, $gwname, $gwsttng); } if (is_array($config['gateways']['gateway_group'])) { |