summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorslioch <slioch@eng-140.vyatta.com>2009-07-08 11:14:08 -0700
committerslioch <slioch@eng-140.vyatta.com>2009-07-08 11:20:51 -0700
commite04a3602d2be984a8ec71bf8b69d9b56665d1333 (patch)
treefd7ec7847f8ec754dd9a72ce268eb74bd7a61625 /src
parent8fd0204c883ca175c754d96b83433f084a7cc2ee (diff)
downloadvyatta-wanloadbalance-e04a3602d2be984a8ec71bf8b69d9b56665d1333.tar.gz
vyatta-wanloadbalance-e04a3602d2be984a8ec71bf8b69d9b56665d1333.zip
fix for bug 4699. Note that dhcp nexthop detection was also broken due to changes in the location of the dhcp client information. this was also
fixed.
Diffstat (limited to 'src')
-rw-r--r--src/lbdata.cc40
-rw-r--r--src/lbdata.hh4
-rw-r--r--src/lbdecision.cc29
-rw-r--r--src/lboutput.cc7
-rw-r--r--src/lbpathtest.cc11
-rw-r--r--src/loadbalance.cc3
6 files changed, 69 insertions, 25 deletions
diff --git a/src/lbdata.cc b/src/lbdata.cc
index 0a1f33a..da92d3c 100644
--- a/src/lbdata.cc
+++ b/src/lbdata.cc
@@ -10,6 +10,7 @@
#include <syslog.h>
#include <iostream>
+#include "rl_str_proc.hh"
#include "lbdata.hh"
int LBHealthHistory::_buffer_size = 10;
@@ -200,3 +201,42 @@ LBData::reset_state_changed()
++h_iter;
}
}
+
+/**
+ *
+ *
+ **/
+void
+LBData::update_dhcp_nexthop()
+{
+ /**
+ * currently only reads the nexthop as maintained by the dhcp client
+ **/
+ LBData::InterfaceHealthIter h_iter = _iface_health_coll.begin();
+ while (h_iter != _iface_health_coll.end()) {
+ if (h_iter->second._nexthop == "dhcp") {
+ string file("/var/lib/dhcp3/dhclient_"+h_iter->first+"_lease");
+ FILE *fp = fopen(file.c_str(),"r");
+ if (fp) {
+ char str[1025];
+ while (fgets(str, 1024, fp)) {
+ StrProc tokens(str, "=");
+ if (tokens.get(0) == "new_routers") {
+ string tmp = tokens.get(1);
+
+ //need to watch out for the case where there are mult routers...
+ StrProc tokens2(tmp," ");
+ tmp = tokens2.get(0);
+
+ long len = tmp.length()-2;
+
+ h_iter->second._dhcp_nexthop = tmp.substr(1,len);
+ break;
+ }
+ }
+ fclose(fp);
+ }
+ }
+ ++h_iter;
+ }
+}
diff --git a/src/lbdata.hh b/src/lbdata.hh
index dd0ac8e..e85adbf 100644
--- a/src/lbdata.hh
+++ b/src/lbdata.hh
@@ -100,6 +100,7 @@ class LBHealth {
string _ping_target;
int _ping_resp_time;
string _nexthop;
+ string _dhcp_nexthop;
LBHealthHistory _hresults;
bool _is_active;
bool _state_changed;
@@ -133,6 +134,9 @@ class LBData {
reset_state_changed();
void
+ update_dhcp_nexthop();
+
+ void
dump();
public:
diff --git a/src/lbdecision.cc b/src/lbdecision.cc
index 10fa12c..1c320ce 100644
--- a/src/lbdecision.cc
+++ b/src/lbdecision.cc
@@ -153,8 +153,9 @@ if so then this stuff goes here!
// 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") {
- string nexthop = fetch_iface_nexthop(iface);
- execute(string("ip route replace table ") + buf + " default dev " + iface + " via " + nexthop, stdout);
+ if (iter->second._dhcp_nexthop.empty() == false) {
+ execute(string("ip route replace table ") + buf + " default dev " + iface + " via " + iter->second._dhcp_nexthop, stdout);
+ }
}
else {
execute(string("ip route replace table ") + buf + " default dev " + iface + " via " + iter->second._nexthop, stdout);
@@ -196,8 +197,9 @@ LBDecision::update_paths(LBData &lbdata)
//now let's update the nexthop here in the route table
if (iter->second._nexthop == "dhcp") {
- string nexthop = fetch_iface_nexthop(iface);
- insert_default(string("ip route replace table ") + buf + " default dev " + iface + " via " + nexthop, iter->second._interface_index);
+ 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);
+ }
}
else {
insert_default(string("ip route replace table ") + buf + " default dev " + iface + " via " + iter->second._nexthop, iter->second._interface_index);
@@ -589,25 +591,6 @@ LBDecision::insert_default(string cmd, int table)
}
/**
- * currently only reads the nexthop as maintained by the dhcp client
- **/
-string
-LBDecision::fetch_iface_nexthop(const string &iface)
-{
- string file("/var/run/vyatta/dhclient/dhclient-script-router-"+iface);
- FILE *fp = fopen(file.c_str(),"r");
- if (fp) {
- char str[1025];
- int ct = 0;
- if ((ct = fread(str, 1, 1024, fp)) > 0) {
- return string(str);
- }
- fclose(fp);
- }
- return string("");
-}
-
-/**
* Fetch interface configuration
**/
string
diff --git a/src/lboutput.cc b/src/lboutput.cc
index e673ee0..35118d3 100644
--- a/src/lboutput.cc
+++ b/src/lboutput.cc
@@ -69,7 +69,12 @@ LBOutput::write(const LBData &lbdata)
string target = iter->second._ping_target;
if (target.empty()) {
- target = iter->second._nexthop;
+ if (iter->second._nexthop == "dhcp") {
+ target = iter->second._dhcp_nexthop;
+ }
+ else {
+ target = iter->second._nexthop;
+ }
}
line += space + string("Target: Ping ") + target + "\n";
diff --git a/src/lbpathtest.cc b/src/lbpathtest.cc
index ebe55cd..d7ed6cd 100644
--- a/src/lbpathtest.cc
+++ b/src/lbpathtest.cc
@@ -103,9 +103,18 @@ LBPathTest::start(LBData &lb_data)
while (iter != lb_data._iface_health_coll.end()) {
string target = iter->second._ping_target;
if (target.empty()) {
- target = iter->second._nexthop;
+ if (iter->second._nexthop == "dhcp") {
+ target = iter->second._dhcp_nexthop;
+ }
+ else {
+ target = iter->second._nexthop;
+ }
}
+ //don't have target yet...
+ if (target.empty()) {
+ return;
+ }
if (_debug) {
cout << "LBPathTest::start(): sending ping test for: " << iter->first << " for " << target << endl;
}
diff --git a/src/loadbalance.cc b/src/loadbalance.cc
index 9b2c8a5..4f42388 100644
--- a/src/loadbalance.cc
+++ b/src/loadbalance.cc
@@ -64,6 +64,9 @@ bool
LoadBalance::start_cycle()
{
_lbdata.reset_state_changed();
+
+ _lbdata.update_dhcp_nexthop();
+
return true;
}