diff options
author | Ermal Luçi <eri@pfsense.org> | 2009-04-26 13:47:33 +0000 |
---|---|---|
committer | Ermal Luçi <eri@pfsense.org> | 2009-04-26 13:47:33 +0000 |
commit | 6dc3a5c2e428a6f8c0d11d904f12ab8ab86a8718 (patch) | |
tree | f528b84d1cd3ee104d92a2320a9eabf77bc8c9eb /etc/inc/gwlb.inc | |
parent | 52947718175a67512a7b79c5d401f2ba7d536489 (diff) | |
download | pfsense-6dc3a5c2e428a6f8c0d11d904f12ab8ab86a8718.zip pfsense-6dc3a5c2e428a6f8c0d11d904f12ab8ab86a8718.tar.gz |
* Move other functions around to where it makes sense.
* Reduce somewhat require_once() overhead by removing the includes from gwlb.inc they are not needed.
Some more analysis is needed on the include path
Diffstat (limited to 'etc/inc/gwlb.inc')
-rw-r--r-- | etc/inc/gwlb.inc | 90 |
1 files changed, 83 insertions, 7 deletions
diff --git a/etc/inc/gwlb.inc b/etc/inc/gwlb.inc index af040d4..e6fb8b1 100644 --- a/etc/inc/gwlb.inc +++ b/etc/inc/gwlb.inc @@ -27,12 +27,6 @@ */ -/* include all configuration functions */ -require_once("functions.inc"); -require_once("pkg-utils.inc"); -require_once("notices.inc"); -require_once("globals.inc"); - /* add static routes for monitor IP addresse * creates monitoring configuration file */ @@ -397,4 +391,86 @@ function dhclient_update_gateway_groups_defaultroute($interface = "wan") { write_config("Updating gateway group gateway for $interface - new gateway is $current_gw"); } -?>
\ No newline at end of file +function lookup_gateway_ip_by_name($name) { + global $config; + if(is_array($config['gateways'])) { + foreach($config['gateways']['gateway_item'] as $gateway) { + if($gateway['name'] == $name) { + $gatewayip = $gateway['gateway']; + //$interfacegw = $gateway['interface']; + return($gatewayip); + } + } + } else { + return(false); + } +} + +function lookup_gateway_monitor_ip_by_name($name) { + global $config; + $gateways_arr = return_gateways_array(); + + foreach($gateways_arr as $gateway) { + if($gateway['name'] == "$name") { + $monitorip = $gateway['monitor']; + if($monitorip == "") + $monitorip = $gateway['gateway']; + + return($monitorip); + } + } + return(false); +} + +function lookup_gateway_interface_by_name($name) { + global $config; + $gateways_arr = return_gateways_array(); + + foreach($gateways_arr as $gateway) { + if($gateway['name'] == "$name") { + $gatewayip = $gateway['gateway']; + $interfacegw = $gateway['interface']; + return($interfacegw); + } + } + return(false); +} + +function get_interface_gateway($interface) { + global $config, $g; + + $iflist = get_configured_interface_with_descr(); + /* + * XXX: BUG: This is silly at first, but we may be called with the interface + * descr for no apparent reason!!! + * Probably one of those silly strtoupper() legacy stuff! + */ + foreach ($iflist as $ifent => $ifdesc) { + if ($ifent == $interface || $ifdesc == $interface) { + $interface = $ifent; + break; + } + } + + $gw = NULL; + + $gwcfg = $config['interfaces'][$interface]; + if (is_ipaddr($gwcfg['gateway'])) + $gw = $gwcfg['gateway']; + else if (!empty($gwcfg['gateway'])) + $gw = lookup_gateway_ip_by_name($gwcfg['gateway']); + + // for dynamic interfaces we handle them through the $interface_router file. + if (!is_ipaddr($gw)) { + $realif = get_real_interface($interface); + if (file_exists("{$g['tmp_path']}/{$realif}_router")) { + $gw = file_get_contents("{$g['tmp_path']}/{$realif}_router"); + $gw = rtrim($gw); + } + } + + /* return gateway */ + return $gw; +} + +?> |