summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2021-11-30 16:29:23 +0700
committerGitHub <noreply@github.com>2021-11-30 16:29:23 +0700
commitac518f1494fd1f014c90d3354eabbb7e33a22f30 (patch)
treefa9f2f1b669050f03d9baf01e8c344c5bfec7b42
parente796b6a9dbf8eaa66b746a75c3211d9ea7ac458b (diff)
parent69a6a8a153b8c53de66bfb9c72a113bd42afa989 (diff)
downloadvyatta-wanloadbalance-lithium.tar.gz
vyatta-wanloadbalance-lithium.zip
Merge pull request #6 from EwaldvanGeffen/lithiumlithium
Bug 590 & 363
-rw-r--r--scripts/vyatta-wanloadbalance.pl5
-rw-r--r--src/lbdata.hh1
-rw-r--r--src/lbdatafactory.cc11
-rw-r--r--src/lbdatafactory.hh3
-rw-r--r--src/lbdecision.cc19
-rw-r--r--templates/load-balancing/wan/interface-health/node.tag/failure-count/node.def4
-rw-r--r--templates/load-balancing/wan/interface-health/node.tag/success-count/node.def4
-rw-r--r--templates/load-balancing/wan/post-hook/node.def4
8 files changed, 47 insertions, 4 deletions
diff --git a/scripts/vyatta-wanloadbalance.pl b/scripts/vyatta-wanloadbalance.pl
index 9603c48..58f1cf3 100644
--- a/scripts/vyatta-wanloadbalance.pl
+++ b/scripts/vyatta-wanloadbalance.pl
@@ -49,6 +49,11 @@ sub write_health {
print FILE_LCK "health {\n";
+ my $post_hook = $config->returnValue("load-balancing wan post-hook");
+ if (defined $post_hook) {
+ print FILE_LCK "post-hook \"" . $post_hook . "\"\n";
+ }
+
$config->setLevel("load-balancing wan interface-health");
my @eths = $config->listNodes();
foreach my $ethNode (@eths) {
diff --git a/src/lbdata.hh b/src/lbdata.hh
index 0b4175c..aaaa896 100644
--- a/src/lbdata.hh
+++ b/src/lbdata.hh
@@ -227,6 +227,7 @@ class LBData {
bool _flush_conntrack;
bool _sticky_inbound_connections;
string _hook;
+ string _post_hook;
};
#endif //__LBDATA_HH__
diff --git a/src/lbdatafactory.cc b/src/lbdatafactory.cc
index 9729e62..682b0b4 100644
--- a/src/lbdatafactory.cc
+++ b/src/lbdatafactory.cc
@@ -157,6 +157,9 @@ LBDataFactory::process(const vector<string> &path, int depth, const string &key,
else if (path[0] == "hook") {
process_hook(l_key,l_value);
}
+ else if (path[0] == "post-hook") {
+ process_post_hook(l_key,l_value);
+ }
else if (path[0] == "health") {
if (depth == 2 && key == "interface") {
process_health(l_key,l_value);
@@ -250,6 +253,14 @@ LBDataFactory::process_hook(const string &key, const string &value)
}
void
+LBDataFactory::process_post_hook(const string &key, const string &value)
+{
+ if (value.empty() == false) {
+ _lb_data._post_hook = value;
+ }
+}
+
+void
LBDataFactory::process_health(const string &key, const string &value)
{
if (value.empty() == false) {
diff --git a/src/lbdatafactory.hh b/src/lbdatafactory.hh
index 9178e00..f213993 100644
--- a/src/lbdatafactory.hh
+++ b/src/lbdatafactory.hh
@@ -59,6 +59,9 @@ private:
process_hook(const string &key, const string &value);
void
+ process_post_hook(const string &key, const string &value);
+
+ void
process_health_interface(const string &key, const string &value);
void
diff --git a/src/lbdecision.cc b/src/lbdecision.cc
index 665b2a2..fd5fd62 100644
--- a/src/lbdecision.cc
+++ b/src/lbdecision.cc
@@ -434,6 +434,25 @@ LBDecision::run(LBData &lb_data)
}
++iter;
}
+
+ map<string,string>::iterator post_iter = state_changed_coll.begin();
+ while (post_iter != state_changed_coll.end()) {
+ //set state
+ //set interface
+ if (lb_data._post_hook.empty() == false) {
+ setenv("WLB_INTERFACE_NAME",post_iter->first.c_str(),1);
+ setenv("WLB_INTERFACE_STATE",post_iter->second.c_str(),1);
+
+ syslog(LOG_WARNING, "executing script: %s",lb_data._post_hook.c_str());
+
+ execute(lb_data._post_hook, stdout);
+ //unset state
+ //unset interface
+ unsetenv("WLB_INTERFACE_NAME");
+ unsetenv("WLB_INTERFACE_STATE");
+ }
+ ++post_iter;
+ }
}
/**
diff --git a/templates/load-balancing/wan/interface-health/node.tag/failure-count/node.def b/templates/load-balancing/wan/interface-health/node.tag/failure-count/node.def
index 89ca474..1dd24f7 100644
--- a/templates/load-balancing/wan/interface-health/node.tag/failure-count/node.def
+++ b/templates/load-balancing/wan/interface-health/node.tag/failure-count/node.def
@@ -1,5 +1,5 @@
type: u32
default: 1
-syntax:expression: $VAR(@) >= 0 && $VAR(@) <= 10; "failure count must be between 1-10"
+syntax:expression: $VAR(@) >= 0 && $VAR(@) <= 10000; "failure count must be between 1-10000"
help: Failure count
-val_help: u32:1-10; Failure count
+val_help: u32:1-10000; Failure count
diff --git a/templates/load-balancing/wan/interface-health/node.tag/success-count/node.def b/templates/load-balancing/wan/interface-health/node.tag/success-count/node.def
index 8d8a6b7..6047b27 100644
--- a/templates/load-balancing/wan/interface-health/node.tag/success-count/node.def
+++ b/templates/load-balancing/wan/interface-health/node.tag/success-count/node.def
@@ -1,6 +1,6 @@
type: u32
default: 1
-syntax:expression: $VAR(@) >= 0 && $VAR(@) <= 10; "success count must be between 1 and 10"
+syntax:expression: $VAR(@) >= 0 && $VAR(@) <= 10000; "success count must be between 1 and 10000"
help: Success count
-val_help: u32:1-10; Success count
+val_help: u32:1-10000; Success count
diff --git a/templates/load-balancing/wan/post-hook/node.def b/templates/load-balancing/wan/post-hook/node.def
new file mode 100644
index 0000000..2666930
--- /dev/null
+++ b/templates/load-balancing/wan/post-hook/node.def
@@ -0,0 +1,4 @@
+type: txt
+help: Script to be executed on interface status change after the firewall rules have been activated.
+syntax:expression: exec "/opt/vyatta/sbin/check_file_in_config_dir $VAR(@) '/config/scripts'"
+val_help: Script in /config/scripts \ No newline at end of file