diff options
| author | slioch <slioch@eng-140.vyatta.com> | 2009-07-07 14:33:15 -0700 |
|---|---|---|
| committer | slioch <slioch@eng-140.vyatta.com> | 2009-07-07 14:33:15 -0700 |
| commit | 4000b742f9eb731d40d22d6e73daef466a0e34ee (patch) | |
| tree | 53a57bbb91b1f2b9b5b33f0acf2b8a35a240cb9f | |
| parent | 45760b0cc60d9f1f307fa3db5d420876f833a38d (diff) | |
| download | vyatta-wanloadbalance-4000b742f9eb731d40d22d6e73daef466a0e34ee.tar.gz vyatta-wanloadbalance-4000b742f9eb731d40d22d6e73daef466a0e34ee.zip | |
added configuration hook to execute script on interface state change. configurable via conf mode. environment variables identify interface and new state.
| -rw-r--r-- | scripts/vyatta-wanloadbalance.pl | 10 | ||||
| -rw-r--r-- | src/lbdata.cc | 9 | ||||
| -rw-r--r-- | src/lbdata.hh | 5 | ||||
| -rw-r--r-- | src/lbdatafactory.cc | 11 | ||||
| -rw-r--r-- | src/lbdatafactory.hh | 9 | ||||
| -rw-r--r-- | src/lbdecision.cc | 24 | ||||
| -rw-r--r-- | templates/load-balancing/wan/hook/node.def | 2 |
7 files changed, 57 insertions, 13 deletions
diff --git a/scripts/vyatta-wanloadbalance.pl b/scripts/vyatta-wanloadbalance.pl index 6016f33..f541ea3 100644 --- a/scripts/vyatta-wanloadbalance.pl +++ b/scripts/vyatta-wanloadbalance.pl @@ -33,11 +33,15 @@ sub write_health { print FILE_LCK "flush-conntrack\n"; } - $config->setLevel("load-balancing wan interface-health"); - my @eths = $config->listNodes(); - print FILE_LCK "health {\n"; + my $hook = $config->returnValue("load-balancing wan hook"); + if (defined $hook) { + print FILE_LCK "\thook \"" . $hook . "\"\n"; + } + + $config->setLevel("load-balancing wan interface-health"); + my @eths = $config->listNodes(); foreach my $ethNode (@eths) { print FILE_LCK "\tinterface " . $ethNode . " {\n"; diff --git a/src/lbdata.cc b/src/lbdata.cc index 4764266..0a1f33a 100644 --- a/src/lbdata.cc +++ b/src/lbdata.cc @@ -165,10 +165,10 @@ LBData::dump() * * **/ -bool +map<string,string> LBData::state_changed() { - bool overall_state = false; + map<string,string> coll; LBData::InterfaceHealthIter h_iter = _iface_health_coll.begin(); while (h_iter != _iface_health_coll.end()) { if (h_iter->second.state_changed()) { @@ -179,11 +179,12 @@ LBData::state_changed() h_iter->second._last_time_state_changed = (unsigned long)tv.tv_sec; syslog(LOG_WARNING, "Interface %s has changed state to %s",h_iter->first.c_str(),tmp.c_str()); - overall_state = true; + + coll.insert(pair<string,string>(h_iter->first,tmp)); } ++h_iter; } - return overall_state; + return coll; } /** diff --git a/src/lbdata.hh b/src/lbdata.hh index 3f90b1e..dd0ac8e 100644 --- a/src/lbdata.hh +++ b/src/lbdata.hh @@ -83,7 +83,7 @@ class LBHealth { void put(int rtt); - bool + bool state_changed() const {return _state_changed;} unsigned long @@ -126,7 +126,7 @@ class LBData { bool is_active(const string &iface); - bool + map<string,string> state_changed(); void @@ -143,6 +143,7 @@ class LBData { bool _disable_source_nat; bool _flush_conntrack; + string _hook; }; #endif //__LBDATA_HH__ diff --git a/src/lbdatafactory.cc b/src/lbdatafactory.cc index a6c117c..c1b77ed 100644 --- a/src/lbdatafactory.cc +++ b/src/lbdatafactory.cc @@ -130,6 +130,9 @@ LBDataFactory::process(const vector<string> &path, int depth, const string &key, if (l_key == "interface") { process_health(l_key,l_value); } + else if (l_key == "hook") { + process_health_hook(l_key,l_value); + } else { process_health_interface(l_key,l_value); } @@ -190,6 +193,14 @@ LBDataFactory::process_health(const string &key, const string &value) } } +void +LBDataFactory::process_health_hook(const string &key, const string &value) +{ + if (value.empty() == false) { + _lb_data._hook = value; + } +} + void LBDataFactory::process_health_interface(const string &key, const string &value) diff --git a/src/lbdatafactory.hh b/src/lbdatafactory.hh index d11446a..12648e8 100644 --- a/src/lbdatafactory.hh +++ b/src/lbdatafactory.hh @@ -5,8 +5,8 @@ * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation. */ -#ifndef __LBCONFLOADER_HH__ -#define __LBCONFLOADER_HH__ +#ifndef __LBDATALOADER_HH__ +#define __LBDATALOADER_HH__ #include <string> #include <vector> @@ -50,6 +50,9 @@ private: process_health(const string &key, const string &value); void + process_health_hook(const string &key, const string &value); + + void process_health_interface(const string &key, const string &value); void @@ -91,4 +94,4 @@ private: LBRule::InterfaceDistIter _rule_iface_iter; }; -#endif //__LBCONFLOADER_HH__ +#endif //__LBDATALOADER_HH__ diff --git a/src/lbdecision.cc b/src/lbdecision.cc index a26476b..c6107d5 100644 --- a/src/lbdecision.cc +++ b/src/lbdecision.cc @@ -229,9 +229,31 @@ LBDecision::run(LBData &lb_data) update_paths(lb_data); //first determine if we need to alter the rule set - if (!lb_data.state_changed()) { + map<string,string> state_changed_coll; + state_changed_coll = lb_data.state_changed(); + if (state_changed_coll.empty() == true) { return; } + else { + //state has changed execute script now + + map<string,string>::iterator iter = state_changed_coll.begin(); + while (iter != state_changed_coll.end()) { + //set state + //set interface + setenv("WLB_INTERFACE_NAME",iter->first.c_str(),1); + setenv("WLB_INTERFACE_STATE",iter->second.c_str(),1); + + syslog(LOG_WARNING, "executing script: %s",lb_data._hook.c_str()); + + execute(lb_data._hook, stdout); + //unset state + //unset interface + unsetenv("WLB_INTERFACE_NAME"); + unsetenv("WLB_INTERFACE_STATE"); + ++iter; + } + } //then if we do, flush all execute("iptables -t mangle -F PREROUTING", stdout); diff --git a/templates/load-balancing/wan/hook/node.def b/templates/load-balancing/wan/hook/node.def new file mode 100644 index 0000000..94ad019 --- /dev/null +++ b/templates/load-balancing/wan/hook/node.def @@ -0,0 +1,2 @@ +type: txt +help: Set script to be executed on interface status change |
