From 1d60ed9bb4901c5b85813d0dab32630e8a135d41 Mon Sep 17 00:00:00 2001 From: Ermal Date: Mon, 4 Apr 2011 11:09:06 +0000 Subject: Try to always keep pfSense with a default gateway to avoid errors for service running from pfSense itself. Previously PBR should be configured for such services. While PBR is a better fix this at least keeps users from complaining in simple setups. Reported by many. --- etc/inc/gwlb.inc | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'etc') diff --git a/etc/inc/gwlb.inc b/etc/inc/gwlb.inc index a192bd3..75dc775 100644 --- a/etc/inc/gwlb.inc +++ b/etc/inc/gwlb.inc @@ -367,6 +367,30 @@ function return_gateway_groups_array() { $gateways_arr = return_gateways_array(); $gateway_groups_array = array(); + /* + * 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; + foreach ($gateways_arr as $gwname => $gwsttng) { + if ($gwsttng['defaultgw'] == true && 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']}"); + } + break; + } + } + unset($upgw, $dfltgwdown, $gwname, $gwsttng); + if (is_array($config['gateways']['gateway_group'])) { foreach($config['gateways']['gateway_group'] as $group) { /* create array with group gateways members seperated by tier */ @@ -532,4 +556,4 @@ function get_interface_gateway($interface, &$dynamic = false) { return ($gw); } -?> \ No newline at end of file +?> -- cgit v1.1