summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorslioch <slioch@eng-140.vyatta.com>2009-04-02 09:33:15 -0700
committerslioch <slioch@eng-140.vyatta.com>2009-04-02 09:33:15 -0700
commit3c28df532e783cb42d0f003da402783767308e6d (patch)
treea63b623e6d128db891b29ac873d6781f3232c371
parentc9229987f30ddc568568ac743c037d1a2f62c7d0 (diff)
downloadvyatta-wanloadbalance-3c28df532e783cb42d0f003da402783767308e6d.tar.gz
vyatta-wanloadbalance-3c28df532e783cb42d0f003da402783767308e6d.zip
added source based routing feature.
-rw-r--r--scripts/vyatta-wanloadbalance.pl4
-rw-r--r--src/lbdata.hh3
-rw-r--r--src/lbdatafactory.cc10
-rw-r--r--src/lbdatafactory.hh3
-rw-r--r--src/lbdecision.cc14
5 files changed, 31 insertions, 3 deletions
diff --git a/scripts/vyatta-wanloadbalance.pl b/scripts/vyatta-wanloadbalance.pl
index c287ddd..c0c4a8d 100644
--- a/scripts/vyatta-wanloadbalance.pl
+++ b/scripts/vyatta-wanloadbalance.pl
@@ -29,6 +29,10 @@ sub write_health {
print FILE_LCK "disable-source-nat\n";
}
+ if ($config->exists("load-balancing wan enable-source-based-routing")) {
+ print FILE_LCK "enable-source-based-routing\n";
+ }
+
if ($config->exists("load-balancing wan flush-connections")) {
print FILE_LCK "flush-conntrack\n";
}
diff --git a/src/lbdata.hh b/src/lbdata.hh
index 03e617f..3bfdf76 100644
--- a/src/lbdata.hh
+++ b/src/lbdata.hh
@@ -116,7 +116,7 @@ class LBData {
typedef map<string,LBHealth>::iterator InterfaceHealthIter;
typedef map<string,LBHealth>::const_iterator InterfaceHealthConstIter;
- LBData() : _disable_source_nat(false),_flush_conntrack(false) {}
+ LBData() : _disable_source_nat(false),_enable_source_based_routing(false),_flush_conntrack(false) {}
bool
error() {return false;}
@@ -140,6 +140,7 @@ class LBData {
InterfaceHealthColl _iface_health_coll;
bool _disable_source_nat;
+ bool _enable_source_based_routing;
bool _flush_conntrack;
};
diff --git a/src/lbdatafactory.cc b/src/lbdatafactory.cc
index ebe63d0..17b4260 100644
--- a/src/lbdatafactory.cc
+++ b/src/lbdatafactory.cc
@@ -123,6 +123,9 @@ LBDataFactory::process(const vector<string> &path, int depth, const string &key,
if (path[0] == "disable-source-nat") {
process_disablesourcenat(l_key,l_value);
}
+ else if (path[0] == "enable-source-based-routing") {
+ process_enablesourcebasedrouting(l_key,l_value);
+ }
else if (path[0] == "flush-conntrack") {
process_flushconntrack(l_key,l_value);
}
@@ -175,6 +178,13 @@ LBDataFactory::process_flushconntrack(const string &key, const string &value)
}
void
+LBDataFactory::process_enablesourcebasedrouting(const string &key, const string &value)
+{
+ _lb_data._enable_source_based_routing = true;
+}
+
+
+void
LBDataFactory::process_health(const string &key, const string &value)
{
if (value.empty() == false) {
diff --git a/src/lbdatafactory.hh b/src/lbdatafactory.hh
index 6d2211c..9aefda0 100644
--- a/src/lbdatafactory.hh
+++ b/src/lbdatafactory.hh
@@ -47,6 +47,9 @@ private:
process_flushconntrack(const string &key, const string &value);
void
+ process_enablesourcebasedrouting(const string &key, const string &value);
+
+ void
process_health(const string &key, const string &value);
void
diff --git a/src/lbdecision.cc b/src/lbdecision.cc
index 70f9a8e..5373b9e 100644
--- a/src/lbdecision.cc
+++ b/src/lbdecision.cc
@@ -273,10 +273,20 @@ LBDecision::run(LBData &lb_data)
for (w_iter = weights.begin(); w_iter != (--weights.end()); w_iter++) {
sprintf(fbuf,"%f",w_iter->second);
sprintf(dbuf,"%d",w_iter->first);
- execute(string("iptables -t mangle -A PREROUTING ") + app_cmd + " -m state --state NEW -m statistic --mode random --probability " + fbuf + " -j ISP_" + dbuf, stdout);
+ if (lb_data._enable_source_based_routing) {
+ execute(string("iptables -t mangle -A PREROUTING ") + app_cmd + " -m statistic --mode random --probability " + fbuf + " -j ISP_" + dbuf, stdout);
+ }
+ else {
+ execute(string("iptables -t mangle -A PREROUTING ") + app_cmd + " -m state --state NEW -m statistic --mode random --probability " + fbuf + " -j ISP_" + dbuf, stdout);
+ }
}
sprintf(dbuf,"%d",(--weights.end())->first);
- execute(string("iptables -t mangle -A PREROUTING ") + app_cmd + " -m state --state NEW -j ISP_" + dbuf, stdout);
+ if (lb_data._enable_source_based_routing) {
+ execute(string("iptables -t mangle -A PREROUTING ") + app_cmd + " -j ISP_" + dbuf, stdout);
+ }
+ else {
+ execute(string("iptables -t mangle -A PREROUTING ") + app_cmd + " -m state --state NEW -j ISP_" + dbuf, stdout);
+ }
execute(string("iptables -t mangle -A PREROUTING ") + app_cmd + " -j CONNMARK --restore-mark", stdout);
}
}