diff options
| author | Michael Larson <slioch@eng-140.vyatta.com> | 2008-02-04 16:45:08 -0800 |
|---|---|---|
| committer | Michael Larson <slioch@eng-140.vyatta.com> | 2008-02-04 16:45:08 -0800 |
| commit | 6fc0de67999f8d8fee10ea7e95ac5601bcb5ff36 (patch) | |
| tree | 866acd3d869af8af46b4352ddb7714e7fbbbe1f6 | |
| parent | e357cbea7769efed1fe897dd800507bc55a15231 (diff) | |
| download | vyatta-wanloadbalance-6fc0de67999f8d8fee10ea7e95ac5601bcb5ff36.tar.gz vyatta-wanloadbalance-6fc0de67999f8d8fee10ea7e95ac5601bcb5ff36.zip | |
whole raft of cli related changes. Fixed bugs in display output--added error checking on some configuration combinations. added
additional error checking in the code.
| -rw-r--r-- | debian/vyatta-wanloadbalance/opt/vyatta/share/vyatta-cfg/templates/load-balancing/wan/rule/node.def | 3 | ||||
| -rw-r--r-- | scripts/vyatta-wanloadbalance.pl | 28 | ||||
| -rw-r--r-- | src/lbdata.cc | 6 | ||||
| -rw-r--r-- | src/lbdata.hh | 5 | ||||
| -rw-r--r-- | src/lbdatafactory.cc | 8 | ||||
| -rw-r--r-- | src/lbdecision.cc | 8 | ||||
| -rw-r--r-- | src/lboutput.cc | 43 | ||||
| -rw-r--r-- | templates/load-balancing/wan/rule/node.def | 4 | ||||
| -rw-r--r-- | templates/load-balancing/wan/rule/node.tag/protocol/node.def | 5 |
9 files changed, 77 insertions, 33 deletions
diff --git a/debian/vyatta-wanloadbalance/opt/vyatta/share/vyatta-cfg/templates/load-balancing/wan/rule/node.def b/debian/vyatta-wanloadbalance/opt/vyatta/share/vyatta-cfg/templates/load-balancing/wan/rule/node.def deleted file mode 100644 index 84b3ad3..0000000 --- a/debian/vyatta-wanloadbalance/opt/vyatta/share/vyatta-cfg/templates/load-balancing/wan/rule/node.def +++ /dev/null @@ -1,3 +0,0 @@ -tag: -type: txt -help: Rule number diff --git a/scripts/vyatta-wanloadbalance.pl b/scripts/vyatta-wanloadbalance.pl index 3d59607..b41bab2 100644 --- a/scripts/vyatta-wanloadbalance.pl +++ b/scripts/vyatta-wanloadbalance.pl @@ -85,7 +85,12 @@ sub write_rules { if (defined $option) { print FILE_LCK "\tprotocol " . $option . "\n" } - + + my $protocol = "all"; + if (defined $option) { + $protocol = $option; + } + #destination print FILE_LCK "\tdestination {\n"; $option = $config->returnValue("$rule destination address"); @@ -101,13 +106,22 @@ sub write_rules { $config->setLevel("load-balancing wan rule $rule destination port-number"); my @dport_nums = $config->listNodes(); foreach my $dport_num (@dport_nums) { + if ($protocol ne "tcp" && $protocol ne "udp") { + print "Please specify protocol tcp or udp when configuring ports\n"; + exit 2; + } + print FILE_LCK "\t\tport-number " . $dport_num . "\n"; } $config->setLevel("load-balancing wan rule $rule destination port-name"); my @dport_names = $config->listNodes(); foreach my $dport_name (@dport_names) { - print FILE_LCK "\t\tport-number " . $dport_name . "\n"; + if ($protocol ne "tcp" && $protocol ne "udp") { + print "Please specify protocol tcp or udp when configuring ports\n"; + exit 2; + } + print FILE_LCK "\t\tport-name " . $dport_name . "\n"; } print FILE_LCK "\t}\n"; @@ -126,13 +140,21 @@ sub write_rules { $config->setLevel("load-balancing wan rule $rule source port-number"); my @sport_nums = $config->listNodes(); foreach my $sport_num (@sport_nums) { + if ($protocol ne "tcp" && $protocol ne "udp") { + print "Please specify protocol tcp or udp when configuring ports\n"; + exit 2; + } print FILE_LCK "\t\tport-number " . $sport_num . "\n"; } $config->setLevel("load-balancing wan rule $rule source port-name"); my @sport_names = $config->listNodes(); foreach my $sport_name (@sport_names) { - print FILE_LCK "\t\tport-number " . $sport_name . "\n"; + if ($protocol ne "tcp" && $protocol ne "udp") { + print "Please specify protocol tcp or udp when configuring ports\n"; + exit 2; + } + print FILE_LCK "\t\tport-name " . $sport_name . "\n"; } print FILE_LCK "\t}\n"; diff --git a/src/lbdata.cc b/src/lbdata.cc index 14a04c0..57050d2 100644 --- a/src/lbdata.cc +++ b/src/lbdata.cc @@ -67,6 +67,7 @@ LBHealth::put(int rtt) LBHealthHistory::LBHealthHistory(int buffer_size) : _last_success(0), _last_failure(0), + _failure_count(0), _index(0) { _resp_data.resize(10); @@ -90,8 +91,10 @@ LBHealthHistory::push(int rtt) if (rtt == -1) { _last_failure = tv.tv_sec; + ++_failure_count; } else { + _failure_count = 0; _last_success = tv.tv_sec; } @@ -115,9 +118,10 @@ LBHealthHistory::push(int rtt) ++ct; } else { - return ct; + break; } } + return ct; } diff --git a/src/lbdata.hh b/src/lbdata.hh index 012d377..d05bf2d 100644 --- a/src/lbdata.hh +++ b/src/lbdata.hh @@ -75,6 +75,8 @@ public: unsigned long _last_success; unsigned long _last_failure; + unsigned long _failure_count; + static int _buffer_size; vector<int> _resp_data; int _index; @@ -102,6 +104,9 @@ class LBHealth { unsigned long last_failure() const {return _hresults._last_failure;} + unsigned long + failure_count() const {return _failure_ct;} + int _success_ct; int _failure_ct; string _ping_target; diff --git a/src/lbdatafactory.cc b/src/lbdatafactory.cc index ed96d72..d422c95 100644 --- a/src/lbdatafactory.cc +++ b/src/lbdatafactory.cc @@ -291,10 +291,10 @@ LBDataFactory::process_rule_source(const string &key, const string &value) _rule_iter->second._s_net = value; } else if (key == "port-name") { - _rule_iter->second._s_port_num = value; + _rule_iter->second._s_port_name = value; } else if (key == "port-number") { - _rule_iter->second._s_port_name = value; + _rule_iter->second._s_port_num = value; } } @@ -315,10 +315,10 @@ LBDataFactory::process_rule_destination(const string &key, const string &value) _rule_iter->second._d_net = value; } else if (key == "port-name") { - _rule_iter->second._d_port_num = value; + _rule_iter->second._d_port_name = value; } else if (key == "port-number") { - _rule_iter->second._d_port_name = value; + _rule_iter->second._d_port_num = value; } } diff --git a/src/lbdecision.cc b/src/lbdecision.cc index 0d256fb..23353ba 100644 --- a/src/lbdecision.cc +++ b/src/lbdecision.cc @@ -190,6 +190,7 @@ LBDecision::run(LBData &lb_data) sprintf(fbuf,"%f",w_iter->second); sprintf(dbuf,"%d",w_iter->first); execute(string("iptables -t mangle -A PREROUTING ") + app_cmd + " -m state --state NEW -m statistic --mode random --probability " + fbuf + " -j ISP_" + dbuf); + ++w_iter; } //last one is special case, the catch all rule @@ -318,6 +319,13 @@ LBDecision::get_application_cmd(LBRule &rule) else if (rule._s_port_num.empty() == false) { filter += "--source-port " + rule._s_port_num + " "; } + + if (rule._d_port_name.empty() == false) { + filter += "--destination-port " + rule._d_port_name + " "; + } + else if (rule._d_port_num.empty() == false) { + filter += "--destination-port " + rule._d_port_num + " "; + } } return filter; diff --git a/src/lboutput.cc b/src/lboutput.cc index 3ab2bdf..d682dc2 100644 --- a/src/lboutput.cc +++ b/src/lboutput.cc @@ -89,42 +89,43 @@ LBOutput::write(const LBData &lbdata) unsigned long days,hours,mins,secs; days = diff_t / (60*60*24); - diff_t -= days * (60*60*24); if (days > 0) { + diff_t -= days * (60*60*24); sprintf(btmp,"%ld",days); time_buf += string(btmp) + "d"; } hours = diff_t / (60*60); - diff_t -= hours * (60*60); if (hours > 0) { + diff_t -= hours * (60*60); sprintf(btmp,"%ld",hours); time_buf += string(btmp) + "h"; } mins = diff_t / (60); - diff_t -= mins * (60); if (mins > 0) { + diff_t -= mins * (60); sprintf(btmp,"%ld",mins); time_buf += string(btmp) + "m"; } secs = diff_t; - if (secs > 0) { - sprintf(btmp,"%ld",secs); - time_buf += string(btmp) + "s"; - } + sprintf(btmp,"%ld",secs); + time_buf += string(btmp) + "s"; - if (time_buf.empty() == true) { - line += string("0s") + string("\t\t"); + if (iter->second.last_success() == 0) { + line += string("n/a") + string("\t\t"); } else { line += time_buf + string("\t"); + if (time_buf.size() < 6) { + line += string("\t"); + } } time_buf = ""; - if (iter->second.last_success() > 0) { + if (iter->second.last_failure() > 0) { diff_t = cur_t.tv_sec - iter->second.last_failure(); } else { @@ -132,39 +133,43 @@ LBOutput::write(const LBData &lbdata) } days = diff_t / (60*60*24); - diff_t -= days * (60*60*24); if (days > 0) { + diff_t -= days * (60*60*24); sprintf(btmp,"%ld",days); time_buf += string(btmp) + "d"; } hours = diff_t / (60*60); - diff_t -= hours * (60*60); if (hours > 0) { + diff_t -= hours * (60*60); sprintf(btmp,"%ld",hours); time_buf += string(btmp) + "h"; } mins = diff_t / (60); - diff_t -= mins * (60); if (mins > 0) { + diff_t -= mins * (60); sprintf(btmp,"%ld",mins); time_buf += string(btmp) + "m"; } secs = diff_t; - if (secs > 0) { - sprintf(btmp,"%ld",secs); - time_buf += string(btmp) + "s"; - } + sprintf(btmp,"%ld",secs); + time_buf += string(btmp) + "s"; - if (time_buf.empty() == true) { - line += string("0s") + string("\t\t"); + if (iter->second.last_failure() == 0) { + line += string("n/a") + string("\t\t"); } else { line += time_buf + string("\t"); + if (time_buf.size() < 6) { + line += string("\t"); + } } + //now failure count + sprintf(btmp, "%ld", iter->second._hresults._failure_count); + line += string(btmp); line += "\n"; diff --git a/templates/load-balancing/wan/rule/node.def b/templates/load-balancing/wan/rule/node.def index 84b3ad3..b25fb93 100644 --- a/templates/load-balancing/wan/rule/node.def +++ b/templates/load-balancing/wan/rule/node.def @@ -1,3 +1,5 @@ tag: -type: txt +type: u32 help: Rule number + + diff --git a/templates/load-balancing/wan/rule/node.tag/protocol/node.def b/templates/load-balancing/wan/rule/node.tag/protocol/node.def index 1363bf1..1ce2754 100644 --- a/templates/load-balancing/wan/rule/node.tag/protocol/node.def +++ b/templates/load-balancing/wan/rule/node.tag/protocol/node.def @@ -1,3 +1,4 @@ +help: "protocol" type: txt -help: protocol - +default: "all" +syntax:expression: $VAR(@) in "all", "tcp", "udp", "icmp"; "must be (all, tcp, udp, icmp)"
\ No newline at end of file |
