summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--anytun.cpp6
-rw-r--r--networkAddress.cpp5
-rw-r--r--networkAddress.h3
-rw-r--r--networkPrefix.cpp5
-rw-r--r--networkPrefix.h1
-rw-r--r--routingTable.cpp18
-rw-r--r--routingTable.h3
-rw-r--r--syncCommand.cpp4
-rw-r--r--syncCommand.h3
-rw-r--r--syncRouteCommand.cpp5
-rw-r--r--syncRouteCommand.h11
-rw-r--r--syncSocket.cpp9
12 files changed, 58 insertions, 15 deletions
diff --git a/anytun.cpp b/anytun.cpp
index acf86c9..2e27b8b 100644
--- a/anytun.cpp
+++ b/anytun.cpp
@@ -81,9 +81,13 @@ void createConnection(const std::string & remote_host, u_int16_t remote_port, Co
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,mux);
- gRoutingTable.addRoute(NetworkPrefix(NetworkAddress()),mux);
+ NetworkAddress addr(ipv4,gOpt.getIfconfigParamRemoteNetmask().c_str());
+ NetworkPrefix prefix(addr);
+ gRoutingTable.addRoute(prefix,mux);
SyncCommand sc (cl,mux);
queue.push(sc);
+ SyncCommand sc2 (prefix);
+ queue.push(sc2);
}
diff --git a/networkAddress.cpp b/networkAddress.cpp
index 8be45e2..cd93576 100644
--- a/networkAddress.cpp
+++ b/networkAddress.cpp
@@ -67,6 +67,11 @@ NetworkAddress::~NetworkAddress()
{
}
+NetworkAddress::NetworkAddress(const network_address_type_t type, const char * address )
+{
+ setNetworkAddress( type, address);
+}
+
void NetworkAddress::setNetworkAddress(const network_address_type_t type, const char * address )
{
if (type==ipv4)
diff --git a/networkAddress.h b/networkAddress.h
index 4217b4a..33cc4b5 100644
--- a/networkAddress.h
+++ b/networkAddress.h
@@ -56,6 +56,7 @@ public:
NetworkAddress(in6_addr);
NetworkAddress(in_addr);
NetworkAddress(uint64_t);
+ NetworkAddress(const network_address_type_t type, const char * address );
~NetworkAddress();
void setNetworkAddress(const network_address_type_t type, const char * address );
void getNetworkAddress(const char *);
@@ -84,7 +85,7 @@ private:
if (network_address_type_==ipv6)
for(int i=0;i<4;i++)
ar & ipv6_address_.s6_addr32;
- if (network_address_type_==ethernet_address_)
+ if (network_address_type_==ethernet)
ar & ethernet_address_;
}
};
diff --git a/networkPrefix.cpp b/networkPrefix.cpp
index 5d7ac49..ee6d9e9 100644
--- a/networkPrefix.cpp
+++ b/networkPrefix.cpp
@@ -33,6 +33,11 @@
#include "networkPrefix.h"
+
+NetworkPrefix::NetworkPrefix(): NetworkAddress(),length_(0)
+{
+}
+
NetworkPrefix::NetworkPrefix(const NetworkAddress & src): NetworkAddress(src),length_(0)
{
}
diff --git a/networkPrefix.h b/networkPrefix.h
index e11f6e7..d5316bd 100644
--- a/networkPrefix.h
+++ b/networkPrefix.h
@@ -39,6 +39,7 @@
class NetworkPrefix : public NetworkAddress
{
public:
+ NetworkPrefix();
NetworkPrefix(const NetworkAddress &);
void setNetworkPrefixLength(uint8_t length );
uint8_t getNetworkPrefixLength();
diff --git a/routingTable.cpp b/routingTable.cpp
index a2b5f56..d51d718 100644
--- a/routingTable.cpp
+++ b/routingTable.cpp
@@ -102,6 +102,24 @@ u_int16_t& RoutingTable::getOrNewRoutingTEUnlocked(const NetworkAddress & addr)
return it->second;
}
+uint16_t RoutingTable::getCountUnlocked()
+{
+ RoutingMap::iterator it = routes_.begin();
+ uint16_t routes=0;
+ for (;it!=routes_.end();++it)
+ routes++;
+ return routes;
+}
+
+RoutingMap::iterator RoutingTable::getBeginUnlocked()
+{
+ return routes_.begin();
+}
+
+RoutingMap::iterator RoutingTable::getEndUnlocked()
+{
+ return routes_.end();
+}
void RoutingTable::clear()
{
diff --git a/routingTable.h b/routingTable.h
index 4466414..a277678 100644
--- a/routingTable.h
+++ b/routingTable.h
@@ -54,6 +54,9 @@ public:
void clear();
Mutex& getMutex();
u_int16_t& getOrNewRoutingTEUnlocked(const NetworkAddress & addr);
+ uint16_t getCountUnlocked();
+ RoutingMap::iterator getBeginUnlocked();
+ RoutingMap::iterator getEndUnlocked();
private:
static Mutex instMutex;
diff --git a/syncCommand.cpp b/syncCommand.cpp
index 12d32f8..3385478 100644
--- a/syncCommand.cpp
+++ b/syncCommand.cpp
@@ -12,10 +12,10 @@ SyncCommand::SyncCommand(ConnectionList & cl, u_int16_t mux )
src_=NULL;
}
-SyncCommand::SyncCommand(u_int16_t mux )
+SyncCommand::SyncCommand(NetworkPrefix np )
{
scc_ = NULL;
- src_ = new SyncRouteCommand(mux);
+ src_ = new SyncRouteCommand(np);
}
SyncCommand::~SyncCommand()
diff --git a/syncCommand.h b/syncCommand.h
index 9d10c76..db82153 100644
--- a/syncCommand.h
+++ b/syncCommand.h
@@ -7,6 +7,7 @@
#include "threadUtils.hpp"
#include "syncConnectionCommand.h"
#include "syncRouteCommand.h"
+#include "networkPrefix.h"
#include <string>
class SyncCommand
@@ -14,7 +15,7 @@ class SyncCommand
public:
SyncCommand(ConnectionList & cl );
SyncCommand(ConnectionList & cl ,u_int16_t mux);
- SyncCommand(u_int16_t mux);
+ SyncCommand(NetworkPrefix);
~SyncCommand();
private:
diff --git a/syncRouteCommand.cpp b/syncRouteCommand.cpp
index e1b354b..21d194c 100644
--- a/syncRouteCommand.cpp
+++ b/syncRouteCommand.cpp
@@ -4,12 +4,13 @@ SyncRouteCommand::SyncRouteCommand()
{
}
-SyncRouteCommand::SyncRouteCommand( const NetworkAddress & addr )
+SyncRouteCommand::SyncRouteCommand( const NetworkPrefix & addr )
:addr_(addr)
{
}
-NetworkAddress SyncRouteCommand::getAddr() const
+
+NetworkPrefix SyncRouteCommand::getPrefix() const
{
return addr_;
}
diff --git a/syncRouteCommand.h b/syncRouteCommand.h
index 2e38eb4..a8e0e23 100644
--- a/syncRouteCommand.h
+++ b/syncRouteCommand.h
@@ -4,19 +4,20 @@
#include <boost/archive/text_iarchive.hpp>
#include "threadUtils.hpp"
-#include "networkAddress.h"
+#include "networkPrefix.h"
#include "routingTable.h"
class SyncRouteCommand
{
public:
- SyncRouteCommand(const NetworkAddress & );
+ SyncRouteCommand(const NetworkPrefix & );
SyncRouteCommand();
- NetworkAddress getAddr() const;
+ NetworkPrefix getPrefix() const;
private:
SyncRouteCommand(const SyncRouteCommand &);
- NetworkAddress addr_;
+ uint16_t count_;
+ NetworkPrefix addr_;
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
@@ -25,7 +26,7 @@ private:
ar & addr_;
u_int16_t & mux = gRoutingTable.getOrNewRoutingTEUnlocked(addr_);
ar & mux;
- }
+ };
};
diff --git a/syncSocket.cpp b/syncSocket.cpp
index ad7781b..d14ca23 100644
--- a/syncSocket.cpp
+++ b/syncSocket.cpp
@@ -36,11 +36,14 @@ void SyncSocket::OnAccept()
Send(sout.str());
}
sleep(1);
- if( ! gRoutingTable.empty())
- {
+ //TODO Locking here
+ RoutingMap::iterator it = gRoutingTable.getBeginUnlocked();
+ for (;it!=gRoutingTable.getEndUnlocked();++it)
+ {
+ NetworkPrefix tmp(it->first);
std::ostringstream sout;
boost::archive::text_oarchive oa(sout);
- const SyncCommand scom(0);
+ const SyncCommand scom(tmp);
oa << scom;
Send(sout.str());
}