summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorslioch <slioch@eng-140.vyatta.com>2009-07-27 17:01:08 -0700
committerslioch <slioch@eng-140.vyatta.com>2009-07-27 17:01:08 -0700
commitb80e518d20d05646404a28c2a5cbfc86d0221600 (patch)
tree7d9f5fc32c677819adcb9a679a75b2d73d76cfa4 /src
parent6047ad1d172c1f825ff98468e2ffdb33002c718f (diff)
downloadvyatta-wanloadbalance-b80e518d20d05646404a28c2a5cbfc86d0221600.tar.gz
vyatta-wanloadbalance-b80e518d20d05646404a28c2a5cbfc86d0221600.zip
clean up all of mangle table on exit, including new entries. fixed bug in target iteration where some targets never completed test cycle
Diffstat (limited to 'src')
-rw-r--r--src/lbdata.cc39
-rw-r--r--src/lbdata.hh12
-rw-r--r--src/lbdecision.cc17
-rw-r--r--src/lboutput.cc2
-rw-r--r--src/lbpathtest.cc2
-rw-r--r--src/lbtest_icmp.cc4
-rw-r--r--src/lbtest_ttl.cc92
7 files changed, 96 insertions, 72 deletions
diff --git a/src/lbdata.cc b/src/lbdata.cc
index 24447b7..9aa155e 100644
--- a/src/lbdata.cc
+++ b/src/lbdata.cc
@@ -84,29 +84,44 @@ LBHealth::send_test()
}
_test_iter->second->init();
_test_iter->second->send(*this);
+
+ struct sysinfo si;
+ sysinfo(&si);
+ _time_start = si.uptime;
}
/**
*
*
**/
-bool
+int
LBHealth::recv_test()
{
- if (_test_success == true || _test_iter == _test_coll.end()) {
- return false;
+ if (_test_success == true) {
+ //shouldn't call this again....
+ return 0; //means stop iteration
}
+
int rtt = _test_iter->second->recv(*this);
- if (rtt != -1) {
- put(rtt); //push test result
+ if (rtt > -1) {
_test_success = true;
- return true; //means we have successfully completed the test
+ put(rtt);
+ return rtt; //means stop iterator
}
- if (++_test_iter == _test_coll.end()) {
+
+ struct sysinfo si;
+ sysinfo(&si);
+ unsigned long cur_time = si.uptime;
+ if (cur_time > _time_start + _timeout) {
+ //move to next test
+ ++_test_iter;
+ }
+
+ if (_test_iter == _test_coll.end()) {
put(-1);
- return true; //end of tests
+ return 0; //means stop iteration
}
- return false;
+ return -1; //means keep going
}
/**
@@ -354,7 +369,7 @@ LBTest::init()
_send_icmp_sock = socket(PF_INET, SOCK_RAW, ppe->p_proto);
if (_send_icmp_sock < 0){
if (_debug) {
- cerr << "LBTestICMP::LBTestICMP(): no send sock: " << _send_icmp_sock << endl;
+ cerr << "LBTest::init(): no send sock: " << _send_icmp_sock << endl;
}
syslog(LOG_ERR, "wan_lb: failed to acquired socket");
_send_icmp_sock = 0;
@@ -369,7 +384,7 @@ LBTest::init()
_send_raw_sock = socket(PF_INET, SOCK_RAW, IPPROTO_RAW);
if (_send_raw_sock < 0){
if (_debug) {
- cerr << "LBTestICMP::LBTestICMP(): no send sock: " << _send_raw_sock << endl;
+ cerr << "LBTest::init(): no send sock: " << _send_raw_sock << endl;
}
syslog(LOG_ERR, "wan_lb: failed to acquired socket");
_send_raw_sock = 0;
@@ -389,7 +404,7 @@ LBTest::init()
_recv_icmp_sock = socket(PF_INET, SOCK_RAW, ppe->p_proto);
if (_recv_icmp_sock < 0) {
if (_debug) {
- cerr << "LBTestICMP::LBTestICMP(): no recv sock: " << _recv_icmp_sock << endl;
+ cerr << "LBTest::init(): no recv sock: " << _recv_icmp_sock << endl;
}
syslog(LOG_ERR, "wan_lb: failed to acquired socket");
_recv_icmp_sock = 0;
diff --git a/src/lbdata.hh b/src/lbdata.hh
index a901653..2e9cf63 100644
--- a/src/lbdata.hh
+++ b/src/lbdata.hh
@@ -146,7 +146,9 @@ public:
_is_active(true),
_state_changed(true),
_last_time_state_changed(0),
- _interface_index(0)
+ _interface_index(0),
+ _timeout(5),
+ _time_start(0)
{}
LBHealth(int interface_index, string &interface) :
@@ -157,7 +159,9 @@ public:
_state_changed(true),
_last_time_state_changed(0),
_interface(interface),
- _interface_index(interface_index)
+ _interface_index(interface_index),
+ _timeout(5),
+ _time_start(0)
{}
void put(int rtt);
@@ -181,7 +185,7 @@ public:
void
send_test();
- bool
+ int
recv_test();
public: //variables
@@ -201,6 +205,8 @@ public: //variables
private: //variables
TestIter _test_iter;
bool _test_success;
+ unsigned long _timeout;
+ unsigned long _time_start;
};
/**
diff --git a/src/lbdecision.cc b/src/lbdecision.cc
index cf77331..5534452 100644
--- a/src/lbdecision.cc
+++ b/src/lbdecision.cc
@@ -391,23 +391,26 @@ LBDecision::shutdown(LBData &data)
string stdout;
//then if we do, flush all
- execute("iptables -t mangle -F WANLOADBALANCE_PRE", stdout);
- execute("iptables -t mangle -F WANLOADBALANCE_OUT", stdout);
execute("iptables -t mangle -D PREROUTING -j WANLOADBALANCE_PRE", stdout);
execute("iptables -t mangle -D OUTPUT -j WANLOADBALANCE_OUT", stdout);
+ execute("iptables -t mangle -F WANLOADBALANCE_PRE", stdout);
+ execute("iptables -t mangle -F WANLOADBALANCE_OUT", stdout);
+ execute("iptables -t mangle -X WANLOADBALANCE_PRE", stdout);
+ execute("iptables -t mangle -X WANLOADBALANCE_OUT", stdout);
LBData::LBRuleIter iter = data._lb_rule_coll.begin();
while (iter != data._lb_rule_coll.end()) {
if (iter->second._limit) {
char rule_str[20];
sprintf(rule_str,"%d",iter->first);
- execute(string("iptables -t mangle -D PREROUTING -j WANLOADBALANCE_PRE_LIMIT_") + rule_str,stdout);
- execute(string("iptables -t mangle -D PREROUTING -j WANLOADBALANCE_OUT_LIMIT_") + rule_str,stdout);
+ execute(string("iptables -t mangle -F WANLOADBALANCE_PRE_LIMIT_") + rule_str,stdout);
+ execute(string("iptables -t mangle -F WANLOADBALANCE_OUT_LIMIT_") + rule_str,stdout);
+ execute(string("iptables -t mangle -X WANLOADBALANCE_PRE_LIMIT_") + rule_str,stdout);
+ execute(string("iptables -t mangle -X WANLOADBALANCE_OUT_LIMIT_") + rule_str,stdout);
}
++iter;
}
-
//clear out nat as well
execute("iptables -t nat -F WANLOADBALANCE", stdout);
execute("iptables -t nat -D VYATTA_PRE_SNAT_HOOK -j WANLOADBALANCE", stdout);
@@ -428,6 +431,10 @@ LBDecision::shutdown(LBData &data)
//need to delete ip rule here as well!
+ //clean up mangle final entries here
+ execute(string("iptables -t mangle -F ISP_") + h_iter->first,stdout);
+ execute(string("iptables -t mangle -X ISP_") + h_iter->first,stdout);
+
++h_iter;
}
}
diff --git a/src/lboutput.cc b/src/lboutput.cc
index 10283d6..5977f92 100644
--- a/src/lboutput.cc
+++ b/src/lboutput.cc
@@ -97,7 +97,7 @@ LBOutput::write(const LBData &lbdata)
unsigned long diff_t;
//the last condition is to handle a system time change...
- if (iter->second.last_success() > 0 && (cur_t.tv_sec > iter->second.last_success())) {
+ if (iter->second.last_success() > 0 && ((unsigned)cur_t.tv_sec > iter->second.last_success())) {
diff_t = cur_t.tv_sec - iter->second.last_success();
}
else {
diff --git a/src/lbpathtest.cc b/src/lbpathtest.cc
index d9ec242..d865639 100644
--- a/src/lbpathtest.cc
+++ b/src/lbpathtest.cc
@@ -88,7 +88,7 @@ LBPathTest::start(LBData &lb_data)
//wait on responses
i = coll.begin();
while (i != coll.end()) {
- if ((*i)->recv_test()) {
+ if ((*i)->recv_test() != -1) {
coll.erase(i++);
}
else {
diff --git a/src/lbtest_icmp.cc b/src/lbtest_icmp.cc
index 7447b21..d6f9e3b 100644
--- a/src/lbtest_icmp.cc
+++ b/src/lbtest_icmp.cc
@@ -1,5 +1,5 @@
/*
- * Module: lbpathtest.cc
+ * Module: lbtest_icmp.cc
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
@@ -78,6 +78,7 @@ ICMPEngine::process(LBHealth &health,LBTestICMP *data)
}
send(data->_send_icmp_sock, health._interface, target, _packet_id);
_results.insert(pair<int,PktData>(_packet_id,PktData(health._interface,-1)));
+ return 0;
}
/**
@@ -140,7 +141,6 @@ ICMPEngine::recv(LBHealth &health,LBTestICMP *data)
map<int,PktData>::iterator r_iter = _results.begin();
data->_state = LBTest::K_FAILURE;
while (r_iter != _results.end()) {
-
if (r_iter->second._iface == health._interface) {
if (r_iter->second._rtt < data->_resp_time) {
data->_state = LBTest::K_SUCCESS;
diff --git a/src/lbtest_ttl.cc b/src/lbtest_ttl.cc
index 4b10223..47d1f4d 100644
--- a/src/lbtest_ttl.cc
+++ b/src/lbtest_ttl.cc
@@ -1,5 +1,5 @@
/*
- * Module: lbpathtest.cc
+ * Module: lbtest_ttl.cc
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
@@ -83,6 +83,7 @@ TTLEngine::process(LBHealth &health,LBTestTTL *data)
send(data->_send_raw_sock, health._interface,target,_packet_id,health._address,data->get_ttl(),data->get_port());
_results.insert(pair<int,PktData>(_packet_id,PktData(health._interface,-1)));
+ return 0;
}
/**
@@ -94,7 +95,6 @@ TTLEngine::recv(LBHealth &health,LBTestTTL *data)
{
_initialized = false;
if (_received == false) {
-
//use gettimeofday to calculate time to millisecond
//then iterate over recv socket and receive and record
//use sysinfo to make sure we don't get stuck in a loop with timechange
@@ -115,9 +115,9 @@ TTLEngine::recv(LBHealth &health,LBTestTTL *data)
//update current time for comparison
struct sysinfo si;
sysinfo(&si);
+ cur_time = si.uptime;
timeval recv_time;
gettimeofday(&recv_time,NULL);
- cur_time = si.uptime;
map<int,PktData>::iterator r_iter = _results.find(id);
if (r_iter != _results.end()) {
//calculate time in milliseconds
@@ -133,6 +133,9 @@ TTLEngine::recv(LBHealth &health,LBTestTTL *data)
r_iter->second._rtt = abs(msecs) / 1000 + 1000 * secs;
--pending_result_ct;
}
+ else {
+ return -1;
+ }
}
if (_debug) {
cout << "TTLEngine::recv(): finished heath test" << endl;
@@ -143,7 +146,6 @@ TTLEngine::recv(LBHealth &health,LBTestTTL *data)
map<int,PktData>::iterator r_iter = _results.begin();
data->_state = LBTest::K_FAILURE;
while (r_iter != _results.end()) {
-
if (r_iter->second._iface == health._interface) {
if (r_iter->second._rtt < data->_resp_time) {
data->_state = LBTest::K_SUCCESS;
@@ -200,7 +202,6 @@ TTLEngine::send(int send_sock, const string &iface, const string &target_addr, u
int err;
sockaddr_in taddr;
- timeval send_time;
char buffer[42];
struct iphdr *ip;
struct udphdr *udp;
@@ -309,10 +310,7 @@ TTLEngine::receive(int recv_sock)
int icmp_pktsize = 40;
char resp_buf[icmp_pktsize];
icmphdr *icmp_hdr;
- struct sockaddr_in dest_addr;
- unsigned int addr_len;
fd_set readfs;
- unsigned short packet_id = 0;
FD_ZERO(&readfs);
FD_SET(recv_sock, &readfs);
@@ -364,27 +362,27 @@ TTLEngine::receive(int recv_sock)
*
**/
unsigned short
-TTLEngine::in_checksum(unsigned short *pAddr, int iLen)
+TTLEngine::in_checksum(unsigned short *addr, int len)
{
- int iSum = 0;
- unsigned short usAnswer = 0;
- unsigned short *pW = pAddr;
- int iRemain = iLen;
+ int sum = 0;
+ unsigned short answer = 0;
+ unsigned short *w = addr;
+ int remain = len;
- while(iRemain > 1)
+ while(remain > 1)
{
- iSum += *pW++;
- iRemain -= sizeof(unsigned short);
+ sum += *w++;
+ remain -= sizeof(unsigned short);
}
- if(iRemain==1)
+ if(remain==1)
{
- *(u_char *)(&usAnswer)=*(u_char*)pW;
- iSum += usAnswer;
+ *(u_char *)(&answer)=*(u_char*)w;
+ sum += answer;
}
- iSum = (iSum>>16) + (iSum&0xffff);
- iSum += (iSum>>16);
- usAnswer = ~iSum;
- return(usAnswer);
+ sum = (sum>>16) + (sum&0xffff);
+ sum += (sum>>16);
+ answer = ~sum;
+ return(answer);
}
@@ -394,42 +392,40 @@ TTLEngine::in_checksum(unsigned short *pAddr, int iLen)
*
**/
unsigned short
-TTLEngine::udp_checksum(unsigned char ucProto, char *pPacket, int iLength, unsigned long ulSourceAddress, unsigned long ulDestAddress)
+TTLEngine::udp_checksum(unsigned char proto, char *packet, int length, unsigned long source_address, unsigned long dest_address)
{
- struct PsuedoHdr
+ struct PseudoHdr
{
- struct in_addr sourceAddr;
- struct in_addr destAddr;
- unsigned char ucPlaceHolder;
- unsigned char ucProtocol;
- unsigned short usLength;
- } PsuedoHdr;
+ struct in_addr source_addr;
+ struct in_addr dest_addr;
+ unsigned char place_holder;
+ unsigned char protocol;
+ unsigned short length;
+ } PseudoHdr;
- struct PsuedoHdr psuedoHdr;
- char *pTempPacket;
- unsigned short usAnswer;
- psuedoHdr.ucProtocol = ucProto;
- psuedoHdr.usLength = htons(iLength);
- psuedoHdr.ucPlaceHolder = 0;
- psuedoHdr.sourceAddr.s_addr = ulSourceAddress;
- psuedoHdr.destAddr.s_addr = ulDestAddress;
+ struct PseudoHdr pseudoHdr;
+ char *temp_packet;
+ unsigned short answer;
+ pseudoHdr.protocol = proto;
+ pseudoHdr.length = htons(length);
+ pseudoHdr.place_holder = 0;
+ pseudoHdr.source_addr.s_addr = source_address;
+ pseudoHdr.dest_addr.s_addr = dest_address;
- if((pTempPacket = (char*)malloc(sizeof(PsuedoHdr) + iLength)) == NULL)
+ if((temp_packet = (char*)malloc(sizeof(PseudoHdr) + length)) == NULL)
{
cerr << "ActionDropConn::UDPChecksum(), error in malloc" << endl;
//throw an exception
return 0;
}
- memcpy(pTempPacket, &psuedoHdr, sizeof(PsuedoHdr));
- memcpy((pTempPacket + sizeof(PsuedoHdr)), pPacket, iLength);
-
- usAnswer = (unsigned short)in_checksum((unsigned short*)pTempPacket,
- (iLength + sizeof(PsuedoHdr)));
-
- free(pTempPacket);
+ memcpy(temp_packet, &pseudoHdr, sizeof(PseudoHdr));
+ memcpy((temp_packet + sizeof(PseudoHdr)), packet, length);
- return usAnswer;
+ answer = (unsigned short)in_checksum((unsigned short*)temp_packet,
+ (length + sizeof(PseudoHdr)));
+ free(temp_packet);
+ return answer;
}
/**