summaryrefslogtreecommitdiffstats
path: root/etc
diff options
context:
space:
mode:
authorErmal <eri@pfsense.org>2011-07-22 21:03:31 +0000
committerErmal <eri@pfsense.org>2011-07-22 21:03:45 +0000
commit860a83e4517c2ce6b060c191bff19c7fd1fdb7f7 (patch)
tree16d229f651bf1ade58f5b40985d74fd47bc20df1 /etc
parent503830368e44dd78eb14ee822ec47751e5cde03b (diff)
downloadpfsense-860a83e4517c2ce6b060c191bff19c7fd1fdb7f7.zip
pfsense-860a83e4517c2ce6b060c191bff19c7fd1fdb7f7.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.inc64
1 files changed, 35 insertions, 29 deletions
diff --git a/etc/inc/gwlb.inc b/etc/inc/gwlb.inc
index 66a0af3..10a4172 100644
--- a/etc/inc/gwlb.inc
+++ b/etc/inc/gwlb.inc
@@ -368,39 +368,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'])) {
OpenPOWER on IntegriCloud