From 10655b3c779e3d2c9278ed3a983ca3587ad03a20 Mon Sep 17 00:00:00 2001 From: Scott Ullrich Date: Tue, 31 May 2005 22:40:13 +0000 Subject: Speedup get_carp_interface_status() by caching the full ifconfig file and then using it for each seqsequent request during the php session --- etc/inc/pfsense-utils.inc | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'etc') diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc index 31a9c59..2f3b7f7 100644 --- a/etc/inc/pfsense-utils.inc +++ b/etc/inc/pfsense-utils.inc @@ -369,9 +369,21 @@ function filter_translate_type_to_real_interface($interface) { * get_carp_interface_status($carpinterface): returns the status of a carp ip */ function get_carp_interface_status($carpinterface) { - $result = does_interface_exist($carpinterface); - if($result <> true) return false; - $status = exec_command("/sbin/ifconfig {$carpinterface} | /usr/bin/grep \"carp:\" | /usr/bin/cut -d\" \" -f2"); + /* basically cache the contents of ifconfig statement + to speed up this routine */ + global $carp_query; + if($carp_query == "") + $carp_query = split("\n", `/sbin/ifconfig | /usr/bin/grep carp`); + $found_interface = 0; + foreach($carp_query as $int) { + if($found_interface == 1) { + if(stristr($int, "MASTER") == true) return "MASTER"; + if(stristr($int, "BACKUP") == true) return "BACKUP"; + if(stristr($int, "INIT") == true) return "INIT"; + return false; + } + if(stristr($int, $carpinterface) == true) $found_interface=1; + } return $status; } -- cgit v1.1