summaryrefslogtreecommitdiff
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:14:08 -0700
commite3ce5a918771a5293affd73dd4168d941b43edae (patch)
tree1f52335cc01b1c6de53d96328155ff12a96da20d
parentbca36f8f9b10ec225f622a8de5ce3e399fab9a85 (diff)
downloadvyatta-wanloadbalance-e3ce5a918771a5293affd73dd4168d941b43edae.tar.gz
vyatta-wanloadbalance-e3ce5a918771a5293affd73dd4168d941b43edae.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.
-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 4764266..60522ff 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;
@@ -199,3 +200,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 3f90b1e..1537c20 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 e87070d..683045d 100644
--- a/src/lbdecision.cc
+++ b/src/lbdecision.cc
@@ -141,8 +141,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);
@@ -184,8 +185,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);
@@ -553,25 +555,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 ff915ec..94c29b3 100644
--- a/src/lboutput.cc
+++ b/src/lboutput.cc
@@ -62,7 +62,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 0324c08..7ec79b0 100644
--- a/src/loadbalance.cc
+++ b/src/loadbalance.cc
@@ -63,6 +63,9 @@ bool
LoadBalance::start_cycle()
{
_lbdata.reset_state_changed();
+
+ _lbdata.update_dhcp_nexthop();
+
return true;
}