summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorslioch <slioch@eng-140.vyatta.com>2009-07-27 13:49:05 -0700
committerslioch <slioch@eng-140.vyatta.com>2009-07-27 13:49:05 -0700
commit96641370e0e1bccbe9197ea486db30c3019b2c3a (patch)
tree31c35509920422cc898e88c7d97c45c6761965f5 /src
parentfbd1493208cad8ec72aa2bde8f28dd7f13dbaa80 (diff)
downloadvyatta-wanloadbalance-96641370e0e1bccbe9197ea486db30c3019b2c3a.tar.gz
vyatta-wanloadbalance-96641370e0e1bccbe9197ea486db30c3019b2c3a.zip
fix for mixed test type configuration where ttl would fail. now works.
Diffstat (limited to 'src')
-rw-r--r--src/lbdata.cc8
-rw-r--r--src/lbtest_icmp.cc32
-rw-r--r--src/lbtest_ttl.cc36
3 files changed, 45 insertions, 31 deletions
diff --git a/src/lbdata.cc b/src/lbdata.cc
index a2666e7..24447b7 100644
--- a/src/lbdata.cc
+++ b/src/lbdata.cc
@@ -346,6 +346,10 @@ LBTest::init()
}
_initialized = true;
+ if (_debug) {
+ cout << "LBTest::init()" << endl;
+ }
+
struct protoent *ppe = getprotobyname("icmp");
_send_icmp_sock = socket(PF_INET, SOCK_RAW, ppe->p_proto);
if (_send_icmp_sock < 0){
@@ -399,6 +403,10 @@ LBTest::init()
}
}
+/**
+ *
+ *
+ **/
LBTest::~LBTest()
{
if (_recv_icmp_sock != 0) {
diff --git a/src/lbtest_icmp.cc b/src/lbtest_icmp.cc
index 278b927..9d72a9a 100644
--- a/src/lbtest_icmp.cc
+++ b/src/lbtest_icmp.cc
@@ -40,12 +40,12 @@ using namespace std;
void
ICMPEngine::init()
{
- if (_debug) {
- cout << "LBTestICMP::init(): initializing test system" << endl;
- }
if (_initialized == false) {
_results.erase(_results.begin(),_results.end());
}
+ if (_debug) {
+ cout << "ICMPEngine::init(): initializing test system" << endl;
+ }
_initialized = true;
_received = false;
}
@@ -74,7 +74,7 @@ ICMPEngine::process(LBHealth &health,LBTestICMP *data)
}
_packet_id = ++_packet_id % 32767;
if (_debug) {
- cout << "LBTestICMP::start(): sending ping test for: " << health._interface << " for " << target << " id: " << _packet_id << endl;
+ cout << "ICMPEngine::start(): sending ping test for: " << health._interface << " for " << target << " id: " << _packet_id << endl;
}
send(data->_send_icmp_sock, health._interface, target, _packet_id);
_results.insert(pair<int,PktData>(_packet_id,PktData(health._interface,-1)));
@@ -105,7 +105,7 @@ ICMPEngine::recv(LBHealth &health,LBTestICMP *data)
while (cur_time < timeout && pending_result_ct != 0) {
int id = receive(data->_recv_icmp_sock);
if (_debug) {
- cout << "LBTestICMP::recv(): " << id << endl;
+ cout << "ICMPEngine::recv(): " << id << endl;
}
//update current time for comparison
@@ -131,7 +131,7 @@ ICMPEngine::recv(LBHealth &health,LBTestICMP *data)
}
}
if (_debug) {
- cout << "LBTestICMP::recv(): finished heath test" << endl;
+ cout << "ICMPEngine::recv(): finished heath test" << endl;
}
_received = true;
}
@@ -145,7 +145,7 @@ ICMPEngine::recv(LBHealth &health,LBTestICMP *data)
if (r_iter->second._rtt < data->_resp_time) {
data->_state = LBTest::K_SUCCESS;
if (_debug) {
- cout << "LBTestICMP::recv(): success for " << r_iter->second._iface << " : " << r_iter->second._rtt << endl;
+ cout << "ICMPEngine::recv(): success for " << r_iter->second._iface << " : " << r_iter->second._rtt << endl;
}
int rtt = r_iter->second._rtt;
_results.erase(r_iter);
@@ -153,7 +153,7 @@ ICMPEngine::recv(LBHealth &health,LBTestICMP *data)
}
else {
if (_debug) {
- cout << "LBTestICMP::recv(): failure for " << r_iter->second._iface << " : " << r_iter->second._rtt << endl;
+ cout << "ICMPEngine::recv(): failure for " << r_iter->second._iface << " : " << r_iter->second._rtt << endl;
}
_results.erase(r_iter);
return -1;
@@ -163,7 +163,7 @@ ICMPEngine::recv(LBHealth &health,LBTestICMP *data)
}
if (_debug) {
- cout << "LBTestICMP::recv(): failure for " << health._interface << " : unable to find interface" << endl;
+ cout << "ICMPEngine::recv(): failure for " << health._interface << " : unable to find interface" << endl;
}
return -1;
}
@@ -190,7 +190,7 @@ ICMPEngine::send(int send_sock, const string &iface, const string &target_addr,
struct hostent *h = gethostbyname(target_addr.c_str());
if (h == NULL) {
if (_debug) {
- cerr << "LBTestICMP::send() Error in resolving hostname" << endl;
+ cerr << "ICMPEngine::send() Error in resolving hostname" << endl;
}
syslog(LOG_ERR, "wan_lb: error in resolving configured hostname: %s", target_addr.c_str());
return;
@@ -238,7 +238,7 @@ ICMPEngine::send(int send_sock, const string &iface, const string &target_addr,
//need to direct this packet out a specific interface!!!!!!!!!!!!!
err = sendto(send_sock, buffer, icmp_pktsize, 0, (struct sockaddr*)&taddr, sizeof(taddr));
if (_debug) {
- cout << "LBTestICMP::send(): sendto: " << err << ", packet id: " << packet_id << endl;
+ cout << "ICMPEngine::send(): sendto: " << err << ", packet id: " << packet_id << endl;
}
if(err < 0) {
if (_debug) {
@@ -294,17 +294,15 @@ ICMPEngine::receive(int recv_sock)
wait_time.tv_sec = 3; //3 second timeout
if (_debug) {
- cout << "LBTestICMP::receive(): start" << endl;
+ cout << "ICMPEngine::receive(): start" << endl;
}
- while (select(recv_sock+1, &readfs, NULL, NULL, &wait_time) != 0)
- {
+ while (select(recv_sock+1, &readfs, NULL, NULL, &wait_time) != 0) {
ret = ::recv(recv_sock, &resp_buf, icmp_pktsize, 0);
if (ret != -1) {
if (_debug) {
- cout << "LBTestICMP::receive(): recv: " << ret << endl;
+ cout << "ICMPEngine::receive(): recv: " << ret << endl;
}
-
icmp_hdr = (struct icmphdr *)(resp_buf + sizeof(iphdr));
if (icmp_hdr->type == ICMP_ECHOREPLY) {
//process packet data
@@ -313,7 +311,7 @@ ICMPEngine::receive(int recv_sock)
data = (char*)(&resp_buf) + 36;
memcpy(&id, data, sizeof(unsigned short));
if (_debug) {
- cout << "LBTestICMP::receive(): " << id << endl;
+ cout << "ICMPEngine::receive(): " << id << endl;
}
return id;
}
diff --git a/src/lbtest_ttl.cc b/src/lbtest_ttl.cc
index d6b067b..6ba6466 100644
--- a/src/lbtest_ttl.cc
+++ b/src/lbtest_ttl.cc
@@ -41,12 +41,12 @@ using namespace std;
void
TTLEngine::init()
{
- if (_debug) {
- cout << "LBTestICMP::init(): initializing test system" << endl;
- }
if (_initialized == false) {
_results.erase(_results.begin(),_results.end());
}
+ if (_debug) {
+ cout << "TTLEngine::init(): initializing test system" << endl;
+ }
_initialized = true;
_received = false;
}
@@ -107,7 +107,7 @@ TTLEngine::recv(LBHealth &health,LBTestTTL *data)
unsigned long cur_time = si.uptime;
int pending_result_ct = _results.size();
- while (cur_time < timeout) {
+ while (cur_time < timeout && pending_result_ct != 0) {
int id = receive(data->_recv_icmp_sock);
if (_debug) {
cout << "TTLEngine::recv(): " << id << endl;
@@ -306,9 +306,9 @@ int
TTLEngine::receive(int recv_sock)
{
timeval wait_time;
- int ret;
int icmp_pktsize = 40;
char resp_buf[icmp_pktsize];
+ icmphdr *icmp_hdr;
struct sockaddr_in dest_addr;
unsigned int addr_len;
fd_set readfs;
@@ -327,16 +327,24 @@ TTLEngine::receive(int recv_sock)
//NEW-OLD STUFF HERE
while (select(recv_sock+1, &readfs, NULL, NULL, &wait_time) != 0) {
- int bytes_recv = recvfrom(recv_sock, &resp_buf, 56, 0, (struct sockaddr*)&dest_addr, &addr_len);
- if (_debug) {
- cout << "TTLEngine::receive() received: " << bytes_recv << endl;
- }
+ int bytes_recv = ::recv(recv_sock, &resp_buf, 56, 0);
if (bytes_recv != -1) {
- //process packet data
- char* datap;
- datap = (char*)(&resp_buf) + 49;
- memcpy(&packet_id, datap, sizeof(unsigned short));
- return packet_id;
+ if (_debug) {
+ cout << "TTLEngine::receive() received: " << bytes_recv << endl;
+ }
+ icmp_hdr = (struct icmphdr *)(resp_buf + sizeof(iphdr));
+
+ // if (icmp_hdr->type == ICMP_ECHOREPLY) {
+ //process packet data
+ char* data;
+ int id = 0;
+ data = (char*)(&resp_buf) + 49;
+ memcpy(&id, data, sizeof(unsigned short));
+ if (_debug) {
+ cout << "TTLEngine::receive(): " << id << endl;
+ }
+ return id;
+ // }
}
else {
cerr << "TTLEngine::receive(): error from recvfrom" << endl;