summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOthmar Gsenger <otti@anytun.org>2008-02-27 21:25:34 +0000
committerOthmar Gsenger <otti@anytun.org>2008-02-27 21:25:34 +0000
commit0fbddcb83a4a3f79da8ba01d593f4064f0ce26ac (patch)
treea9edad038475d880e2e52a6d416eeafd0536da1b
parentadded mux to options (diff)
added mux support and routing table
-rw-r--r--anytun.cpp7
-rw-r--r--networkAddress.cpp2
-rw-r--r--networkPrefix.cpp4
-rw-r--r--networkPrefix.h1
-rw-r--r--routingTable.cpp34
-rw-r--r--routingTable.h1
6 files changed, 36 insertions, 13 deletions
diff --git a/anytun.cpp b/anytun.cpp
index a408019..023160d 100644
--- a/anytun.cpp
+++ b/anytun.cpp
@@ -94,8 +94,9 @@ void createConnection(const std::string & remote_host, u_int16_t remote_port, Co
kd->init(Buffer(key, sizeof(key)), Buffer(salt, sizeof(salt)));
cLog.msg(Log::PRIO_NOTICE) << "added connection remote host " << remote_host << ":" << remote_port;
ConnectionParam connparam ( (*kd), (*seq), seq_nr_, remote_host, remote_port);
- cl.addConnection(connparam,0);
- SyncCommand sc (cl,0);
+ cl.addConnection(connparam,gOpt.getMux());
+ gRoutingTable.addRoute(NetworkPrefix(NetworkAddress()),gOpt.getMux());
+ SyncCommand sc (cl,gOpt.getMux());
queue.push(sc);
}
@@ -154,7 +155,7 @@ void* sender(void* p)
if(param->cl.empty())
continue;
- gRoutingTable.getRoute(NetworkAddress());
+ mux = gRoutingTable.getRoute(NetworkAddress());
ConnectionMap::iterator cit = param->cl.getConnection(mux);
if(cit==param->cl.getEnd())
continue;
diff --git a/networkAddress.cpp b/networkAddress.cpp
index 3db7238..d87f5ba 100644
--- a/networkAddress.cpp
+++ b/networkAddress.cpp
@@ -36,6 +36,8 @@
NetworkAddress::NetworkAddress()
{
+ network_address_type_=ipv4;
+ ipv4_address_.s_addr=0;
}
NetworkAddress::NetworkAddress(const NetworkAddress & ref) : mutex_(),ipv4_address_(ref.ipv4_address_),ipv6_address_(ref.ipv6_address_),ethernet_address_(ref.ethernet_address_),network_address_type_(ref.network_address_type_)
diff --git a/networkPrefix.cpp b/networkPrefix.cpp
index b373eec..5d7ac49 100644
--- a/networkPrefix.cpp
+++ b/networkPrefix.cpp
@@ -33,6 +33,10 @@
#include "networkPrefix.h"
+NetworkPrefix::NetworkPrefix(const NetworkAddress & src): NetworkAddress(src),length_(0)
+{
+}
+
void NetworkPrefix::setNetworkPrefixLength(uint8_t length )
{
length_ = length;
diff --git a/networkPrefix.h b/networkPrefix.h
index 93ce386..e11f6e7 100644
--- a/networkPrefix.h
+++ b/networkPrefix.h
@@ -39,6 +39,7 @@
class NetworkPrefix : public NetworkAddress
{
public:
+ NetworkPrefix(const NetworkAddress &);
void setNetworkPrefixLength(uint8_t length );
uint8_t getNetworkPrefixLength();
bool operator<(const NetworkPrefix &s) const;
diff --git a/routingTable.cpp b/routingTable.cpp
index a6e0917..29302fb 100644
--- a/routingTable.cpp
+++ b/routingTable.cpp
@@ -27,7 +27,7 @@
* distribution); if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-
+#include "networkPrefix.h"
#include "threadUtils.hpp"
#include "datatypes.h"
@@ -56,22 +56,36 @@ RoutingTable::~RoutingTable()
{
}
-void RoutingTable::addRoute(const NetworkPrefix & ,u_int16_t )
+void RoutingTable::addRoute(const NetworkPrefix & pref,u_int16_t mux )
{
Lock lock(mutex_);
+
+
+ std::pair<RoutingMap::iterator, bool> ret = routes_.insert(RoutingMap::value_type(pref,mux));
+ if(!ret.second)
+ {
+ routes_.erase(ret.first);
+ routes_.insert(RoutingMap::value_type(pref,mux));
+ }
+}
+
-// std::pair<ConnectionMap::iterator, bool> ret = connections_.insert(ConnectionMap::value_type(mux, conn));
-// if(!ret.second)
-// {
-// connections_.erase(ret.first);
-// connections_.insert(ConnectionMap::value_type(mux, conn));
-// }
+void RoutingTable::delRoute(const NetworkPrefix & pref )
+{
+ Lock lock(mutex_);
+
+ routes_.erase(routes_.find(pref));
}
-u_int16_t RoutingTable::getRoute(const NetworkAddress &)
+u_int16_t RoutingTable::getRoute(const NetworkAddress & addr)
{
Lock lock(mutex_);
- RoutingMap::iterator it = routes_.begin();
+ NetworkPrefix prefix(addr);
+ prefix.setNetworkPrefixLength(32);
+ RoutingMap::iterator it = routes_.lower_bound(prefix);
+ it--;
+ if (it!=routes_.end())
+ return it->second;
return 0;
}
diff --git a/routingTable.h b/routingTable.h
index b406b65..f4f89c3 100644
--- a/routingTable.h
+++ b/routingTable.h
@@ -48,6 +48,7 @@ public:
RoutingTable();
~RoutingTable();
void addRoute(const NetworkPrefix & ,u_int16_t);
+ void delRoute(const NetworkPrefix & );
u_int16_t getRoute(const NetworkAddress &);
bool empty();
void clear();