From 5d128840c36073a04b8bdac1a59856e2ecf5a10f Mon Sep 17 00:00:00 2001 From: Ermal Date: Fri, 4 Jan 2013 08:51:06 +0000 Subject: GC cmd_chain.inc it never found uses since pfSense module got used more. Also fix the problem with pfsync on bootup waiting 30 seconds since cmd chain was executed after and pfsync was never brought up to compleete the sync. --- etc/inc/cmd_chain.inc | 132 ------------------------------------------------- etc/inc/interfaces.inc | 68 ++++++++----------------- 2 files changed, 21 insertions(+), 179 deletions(-) delete mode 100644 etc/inc/cmd_chain.inc (limited to 'etc') diff --git a/etc/inc/cmd_chain.inc b/etc/inc/cmd_chain.inc deleted file mode 100644 index eb81954..0000000 --- a/etc/inc/cmd_chain.inc +++ /dev/null @@ -1,132 +0,0 @@ -cmd_chain_array = array(); - } - - /* enables log_error() of each command we run */ - function setdebug() { - $this->is_debugging = true; - } - - /* no halt execution of CmdCHAIN if there is a failure */ - function nohaltonerror() { - $this->halt_on_errors = false; - } - - /* halts execution of CmdCHAIN if there is a failure */ - function sethaltonerror() { - $this->halt_on_errors = true; - } - - /* adds a command to the CmdCHAIN */ - function add($cmd_title = "", $command = "", $ignore_return_text = false) { - if(!$cmd_title) - return; - if(!$command) - return; - $temp = array(); - $temp['cmd_title'] = $cmd_title; - $temp['command'] = $command; - if($ignore_return_text) - $temp['ignore_return_text'] = true; - else - $temp['ignore_return_text'] = false; - $this->cmd_chain_array[] = $temp; // add array to class - return array(); - } - - /* executes the CmdCHAIN one command at a time */ - function execute() { - foreach($this->cmd_chain_array as $cmd) { - $cmd_title = $cmd['cmd_title']; - $command = $cmd['command']; - $ignore_return_text = $cmd['ignore_return_text']; - // Should we perform verbose debugging? - if($this->is_debugging == true) { - log_error("CmdCHAIN is executing -> {$cmd_title} - {$command}"); - usleep(100); // give network stack time to deliver network syslog message - } - // Execute command - $status = exec($command); - if($this->ignore_return_text == true) - continue; - if(intval($status) <> 0) { - log_error("{$cmd_title} failed with return code -> {$status}. The command was {$command}"); - if($this->halt_on_errors == true) - return("{$cmd_title} failed with return code -> {$status}. The command was {$command}"); - } - } - return; - } -} - -/* - * example usage: - * - -$cmdchain = new CmdCHAIN(); -$cmdchain->add("grab freebsd version", "uname -a", false); -$cmdchain->setdebug(); // optional for verbose logging -$cmdchain->nohaltonerror(); // tells cmdchain to keep processing commands if any of them fail -$cmdchain->execute(); - -$cmdchain->clear(); // clears the previous added entries - -*/ - -?> \ No newline at end of file diff --git a/etc/inc/interfaces.inc b/etc/inc/interfaces.inc index 5edb85a..d02258b 100644 --- a/etc/inc/interfaces.inc +++ b/etc/inc/interfaces.inc @@ -1625,17 +1625,11 @@ EOD; function interfaces_carp_setup() { global $g, $config; - $balanacing = ""; - $pfsyncinterface = ""; - $pfsyncenabled = ""; if(isset($config['system']['developerspew'])) { $mt = microtime(); echo "interfaces_carp_setup() being called $mt\n"; } - // Prepare CmdCHAIN that will be used to execute commands. - $cmdchain = new CmdCHAIN(); - if ($g['booting']) { echo "Configuring CARP settings..."; mute_kernel_msgs(); @@ -1658,61 +1652,41 @@ function interfaces_carp_setup() { } if($balanacing) { - $cmdchain->add("Enable CARP ARP-balancing", "/sbin/sysctl net.inet.carp.arpbalance=1", true); - $cmdchain->add("Disallow CARP preemption", "/sbin/sysctl net.inet.carp.preempt=0", true); + mwexec("/sbin/sysctl net.inet.carp.arpbalance=1", true); + mwexec("/sbin/sysctl net.inet.carp.preempt=0", true); } else - $cmdchain->add("Enable CARP preemption", "/sbin/sysctl net.inet.carp.preempt=1", true); + mwexec("/sbin/sysctl net.inet.carp.preempt=1", true); - $cmdchain->add("Enable CARP logging", "/sbin/sysctl net.inet.carp.log=1", true); + mwexec("sbin/sysctl net.inet.carp.log=1", true); if (!empty($pfsyncinterface)) $carp_sync_int = get_real_interface($pfsyncinterface); - - if($g['booting']) { - /* install rules to alllow pfsync to sync up during boot - * carp interfaces will remain down until the bootup sequence finishes - */ - $fd = fopen("{$g['tmp_path']}/rules.boot", "w"); - if ($fd) { - fwrite($fd, "block quick proto carp \n"); - fwrite($fd, "block quick proto pfsync \n"); - fwrite($fd, "pass out quick from any to any keep state\n"); - fclose($fd); - mwexec("/sbin/pfctl -f {$g['tmp_path']}/rules.boot"); - } else - log_error("Could not create rules.boot file!"); - } + else + unset($carp_sync_int); /* setup pfsync interface */ - if($carp_sync_int and $pfsyncenabled) { + if ($carp_sync_int and $pfsyncenabled) { if (is_ipaddr($pfsyncpeerip)) - $cmdchain->add("Bring up pfsync0 syncpeer", "/sbin/ifconfig pfsync0 syncdev {$carp_sync_int} syncpeer {$pfsyncpeerip} up", false); + mwexec("/sbin/ifconfig pfsync0 syncdev {$carp_sync_int} syncpeer {$pfsyncpeerip} up", false); else - $cmdchain->add("Bring up pfsync0 syncdev", "/sbin/ifconfig pfsync0 syncdev {$carp_sync_int} up", false); - } else - $cmdchain->add("Bring up pfsync0", "/sbin/ifconfig pfsync0 syncdev lo0 up", false); - - sleep(1); + mwexec("/sbin/ifconfig pfsync0 syncdev {$carp_sync_int} up", false); - /* XXX: Handle an issue with pfsync(4) and carp(4). In a cluster carp will come up before pfsync(4) has updated and so will cause issuese - * for exiting sessions. - */ - $i = 0; - while (intval(trim(`/sbin/ifconfig pfsync0 | /usr/bin/grep 'syncok: 0' | /usr/bin/grep -v grep | /usr/bin/wc -l`)) == 0 && $i < 30) { - $i++; sleep(1); + + /* XXX: Handle an issue with pfsync(4) and carp(4). In a cluster carp will come up before pfsync(4) has updated and so will cause issuese + * for exiting sessions. + */ + $i = 0; + while (intval(trim(`/sbin/ifconfig pfsync0 | /usr/bin/grep 'syncok: 0' | /usr/bin/grep -v grep | /usr/bin/wc -l`)) == 0 && $i < 30) { + $i++; + sleep(1); + } } - if($config['virtualip']['vip']) - $cmdchain->add("Allow CARP.", "/sbin/sysctl net.inet.carp.allow=1", true); + if ($config['virtualip']['vip']) + mwexec("/sbin/sysctl net.inet.carp.allow=1", true); else - $cmdchain->add("Disallow CARP.", "/sbin/sysctl net.inet.carp.allow=0", true); + mwexec("/sbin/sysctl net.inet.carp.allow=0", true); - if($g['debug']) - $cmdchain->setdebug(); // optional for verbose logging - - $cmdchain->execute(); - $cmdchain->clear(); - if ($g['booting']) { unmute_kernel_msgs(); echo "done.\n"; -- cgit v1.1