summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Larson <slioch@slioch.vyatta.com>2010-04-06 11:40:25 -0700
committerMichael Larson <slioch@slioch.vyatta.com>2010-04-19 11:40:31 -0700
commit046372fbec27151be5c0e5e516d9dd87433b858f (patch)
tree5fc3f044bb3055fcb5b5fb60c7ea3b3c3fe34720
parentb73008d6451e1d6db5b542c68d3862728679ede5 (diff)
downloadvyatta-wanloadbalance-046372fbec27151be5c0e5e516d9dd87433b858f.tar.gz
vyatta-wanloadbalance-046372fbec27151be5c0e5e516d9dd87433b858f.zip
fix for bug 5520.
When checking policy route compare nexthop and interface rather then just checking for an entry. This allows for incorrect entries to be replaced. This would be a problem if different nexthop is readvertised via dhcp to the interface.
-rw-r--r--src/lbdecision.cc25
-rw-r--r--src/lbdecision.hh2
2 files changed, 18 insertions, 9 deletions
diff --git a/src/lbdecision.cc b/src/lbdecision.cc
index a5cc7e2..c1731fe 100644
--- a/src/lbdecision.cc
+++ b/src/lbdecision.cc
@@ -152,7 +152,6 @@ if so then this stuff goes here!
//NOTE, WILL NEED A WAY TO CLEAN UP THIS RULE ON RESTART...
execute(string("iptables -t mangle -A ISP_") + iface + " -j ACCEPT", stdout);
- // insert_default(string("ip route replace table ") + buf + " default dev " + iface + " via " + iter->second._nexthop, ct);
//need to force the entry on restart as the configuration may have changed.
if (iter->second._nexthop == "dhcp") {
if (iter->second._dhcp_nexthop.empty() == false) {
@@ -203,11 +202,11 @@ LBDecision::update_paths(LBData &lbdata)
//now let's update the nexthop here in the route table
if (iter->second._nexthop == "dhcp") {
if (iter->second._dhcp_nexthop.empty() == false) {
- insert_default(string("ip route replace table ") + buf + " default dev " + iface + " via " + iter->second._dhcp_nexthop, iter->second._interface_index);
+ insert_default(iter->second, iter->second._dhcp_nexthop);
}
}
else {
- insert_default(string("ip route replace table ") + buf + " default dev " + iface + " via " + iter->second._nexthop, iter->second._interface_index);
+ insert_default(iter->second, iter->second._nexthop);
}
if (lbdata._disable_source_nat == false) {
@@ -686,17 +685,27 @@ LBDecision::get_application_cmd(LBRule &rule, bool local, bool exclude)
* should be replaced by netlink in the next release.
**/
void
-LBDecision::insert_default(string cmd, int table)
+LBDecision::insert_default(LBHealth &h, string &nexthop)
{
+ //if found will return something of the form:
+ // "default via 10.3.0.1 dev eth0"
+
+ //retrieve route entry
string stdout;
char buf[40];
+ sprintf(buf,"%d",h._interface_index);
+ string default_route = string("ip route replace table ") + buf + " default dev " + h._interface + " via " + nexthop;
string showcmd("ip route show table ");
- sprintf(buf,"%d",table);
showcmd += string(buf);
execute(showcmd,stdout,true);
-
- if (stdout.empty() == true) {
- execute(cmd,stdout);
+ if (stdout.empty() == false) {
+ //compare string:
+ if (stdout.find(nexthop) == string::npos || stdout.find(h._interface) == string::npos) { //compare expected string
+ execute(default_route,stdout); //apply entry because this doesn't match
+ }
+ }
+ else {
+ execute(default_route,stdout); //apply entry because this doesn't match
}
}
diff --git a/src/lbdecision.hh b/src/lbdecision.hh
index 7ef9308..e4b5378 100644
--- a/src/lbdecision.hh
+++ b/src/lbdecision.hh
@@ -37,7 +37,7 @@ private:
execute(string cmd, string &stdout, bool read = false);
void
- insert_default(string cmd, int table);
+ insert_default(LBHealth &h, string &nexthop);
map<string,float>
get_new_weights(LBData &data, LBRule &rule);