diff options
-rw-r--r-- | src/anytun-config.cpp | 2 | ||||
-rw-r--r-- | src/anytun-showtables.cpp | 24 | ||||
-rw-r--r-- | src/anytun.cpp | 2 | ||||
-rw-r--r-- | src/networkAddress.cpp | 2 | ||||
-rw-r--r-- | src/networkAddress.h | 8 | ||||
-rw-r--r-- | src/routingTable.cpp | 50 | ||||
-rw-r--r-- | src/routingTable.h | 13 | ||||
-rw-r--r-- | src/syncOnConnect.hpp | 33 |
8 files changed, 73 insertions, 61 deletions
diff --git a/src/anytun-config.cpp b/src/anytun-config.cpp index 840804a..3f21d0e 100644 --- a/src/anytun-config.cpp +++ b/src/anytun-config.cpp @@ -70,7 +70,7 @@ void createConnection(const PacketSourceEndpoint & remote_end, ConnectionList & RouteList::const_iterator rit; for(rit = routes.begin(); rit != routes.end(); ++rit) { - NetworkAddress addr( ipv4, rit->net_addr.c_str() ); + NetworkAddress addr( rit->net_addr.c_str() ); NetworkPrefix prefix( addr, rit->prefix_length ); gRoutingTable.addRoute( prefix, mux ); diff --git a/src/anytun-showtables.cpp b/src/anytun-showtables.cpp index 6e197b1..d3e8569 100644 --- a/src/anytun-showtables.cpp +++ b/src/anytun-showtables.cpp @@ -65,15 +65,21 @@ void output(ConnectionList &cl) std::cout << std::endl; //std::cout << "Connection: Keyderivation-Type: " << conn.kd_.printType() << std::endl; cl.clear(); - } - else if( !gRoutingTable.empty() ) - { - RoutingMap::iterator it = gRoutingTable.getBeginUnlocked(); - NetworkPrefix pref( it->first ); - std::cout << "Route: " << pref.toString() << "/" << pref.getNetworkPrefixLength() << " -> "; - mux_t mux = it->second; - std::cout << mux << std::endl; - gRoutingTable.clear(); + } else { + network_address_type_t types[] = {ipv4,ipv6,ethernet}; + for (int types_idx=0; types_idx<3; types_idx++) + { + network_address_type_t type = types[types_idx]; + if( !gRoutingTable.empty(type) ) + { + RoutingMap::iterator it = gRoutingTable.getBeginUnlocked(type); + NetworkPrefix pref( it->first ); + std::cout << "Route: " << pref.toString() << "/" << pref.getNetworkPrefixLength() << " -> "; + mux_t mux = it->second; + std::cout << mux << std::endl; + gRoutingTable.clear(type); + } + } } } diff --git a/src/anytun.cpp b/src/anytun.cpp index bdb7a5d..ca77e63 100644 --- a/src/anytun.cpp +++ b/src/anytun.cpp @@ -100,7 +100,7 @@ void createConnection(const PacketSourceEndpoint & remote_end, ConnectionList & if (gOpt.getIfconfigParamRemoteNetmask() != "") { NetworkAddress addr(gOpt.getIfconfigParamRemoteNetmask()); - NetworkPrefix prefix(addr,32); + NetworkPrefix prefix(addr,128); gRoutingTable.addRoute(prefix,mux); SyncCommand sc2 (prefix); queue.push(sc2); diff --git a/src/networkAddress.cpp b/src/networkAddress.cpp index 0ec1c38..49ae704 100644 --- a/src/networkAddress.cpp +++ b/src/networkAddress.cpp @@ -100,7 +100,7 @@ void NetworkAddress::setNetworkAddress(const network_address_type_t type, const network_address_type_ = type; } -network_address_type_t NetworkAddress::getNetworkAddressType() +network_address_type_t NetworkAddress::getNetworkAddressType() const { return network_address_type_; } diff --git a/src/networkAddress.h b/src/networkAddress.h index e2228d5..3eb0b51 100644 --- a/src/networkAddress.h +++ b/src/networkAddress.h @@ -42,9 +42,9 @@ enum network_address_type_t { - ipv4, - ipv6, - ethernet + ipv4=0, + ipv6=1, + ethernet=2 }; class NetworkAddress @@ -59,7 +59,7 @@ public: NetworkAddress(const network_address_type_t type, const std::string & address ); ~NetworkAddress(); void setNetworkAddress(const network_address_type_t type, const std::string & address ); - network_address_type_t getNetworkAddressType(); + network_address_type_t getNetworkAddressType() const; std::string toString() const; bool operator<(const NetworkAddress &s) const; protected: diff --git a/src/routingTable.cpp b/src/routingTable.cpp index e0641b1..b3aae6e 100644 --- a/src/routingTable.cpp +++ b/src/routingTable.cpp @@ -59,14 +59,16 @@ RoutingTable::~RoutingTable() void RoutingTable::addRoute(const NetworkPrefix & pref,u_int16_t mux ) { + if ( pref.getNetworkAddressType()!=ipv4 && pref.getNetworkAddressType() != ipv6) + return; //TODO add ETHERNET support Lock lock(mutex_); - std::pair<RoutingMap::iterator, bool> ret = routes_.insert(RoutingMap::value_type(pref,mux)); + std::pair<RoutingMap::iterator, bool> ret = routes_[pref.getNetworkAddressType()].insert(RoutingMap::value_type(pref,mux)); if(!ret.second) { - routes_.erase(ret.first); - routes_.insert(RoutingMap::value_type(pref,mux)); + routes_[pref.getNetworkAddressType()].erase(ret.first); + routes_[pref.getNetworkAddressType()].insert(RoutingMap::value_type(pref,mux)); } } @@ -75,64 +77,64 @@ void RoutingTable::delRoute(const NetworkPrefix & pref ) { Lock lock(mutex_); - routes_.erase(routes_.find(pref)); + routes_[pref.getNetworkAddressType()].erase(routes_[pref.getNetworkAddressType()].find(pref)); } u_int16_t RoutingTable::getRoute(const NetworkAddress & addr) { Lock lock(mutex_); - if (routes_.empty()) + if (routes_[addr.getNetworkAddressType()].empty()) return 0; - NetworkPrefix prefix(addr,32); //TODO Routing algorithem isnt working!!! - RoutingMap::iterator it = routes_.lower_bound(prefix); + NetworkPrefix prefix(addr,128); + RoutingMap::iterator it = routes_[addr.getNetworkAddressType()].lower_bound(prefix); // it--; - if (it!=routes_.end()) + if (it!=routes_[addr.getNetworkAddressType()].end()) return it->second; - it=routes_.begin(); + it=routes_[addr.getNetworkAddressType()].begin(); return it->second; } u_int16_t* RoutingTable::getOrNewRoutingTEUnlocked(const NetworkPrefix & addr) { - RoutingMap::iterator it = routes_.find(addr); - if(it!=routes_.end()) + RoutingMap::iterator it = routes_[addr.getNetworkAddressType()].find(addr); + if(it!=routes_[addr.getNetworkAddressType()].end()) return &(it->second); - routes_.insert(RoutingMap::value_type(addr, 1)); - it = routes_.find(addr); + routes_[addr.getNetworkAddressType()].insert(RoutingMap::value_type(addr, 1)); + it = routes_[addr.getNetworkAddressType()].find(addr); return &(it->second); } -u_int16_t RoutingTable::getCountUnlocked() +u_int16_t RoutingTable::getCountUnlocked(network_address_type_t type) { - RoutingMap::iterator it = routes_.begin(); + RoutingMap::iterator it = routes_[type].begin(); u_int16_t routes=0; - for (;it!=routes_.end();++it) + for (;it!=routes_[type].end();++it) routes++; return routes; } -RoutingMap::iterator RoutingTable::getBeginUnlocked() +RoutingMap::iterator RoutingTable::getBeginUnlocked(network_address_type_t type) { - return routes_.begin(); + return routes_[type].begin(); } -RoutingMap::iterator RoutingTable::getEndUnlocked() +RoutingMap::iterator RoutingTable::getEndUnlocked(network_address_type_t type) { - return routes_.end(); + return routes_[type].end(); } -void RoutingTable::clear() +void RoutingTable::clear(network_address_type_t type) { Lock lock(mutex_); - routes_.clear(); + routes_[type].clear(); } -bool RoutingTable::empty() +bool RoutingTable::empty(network_address_type_t type) { Lock lock(mutex_); - return routes_.empty(); + return routes_[type].empty(); } Mutex& RoutingTable::getMutex() diff --git a/src/routingTable.h b/src/routingTable.h index eee8836..e73deea 100644 --- a/src/routingTable.h +++ b/src/routingTable.h @@ -37,7 +37,6 @@ #include "threadUtils.hpp" #include "datatypes.h" -//#include "routingTableEntry.h" #include "networkAddress.h" #include "networkPrefix.h" typedef std::map<NetworkPrefix,u_int16_t> RoutingMap; @@ -51,13 +50,13 @@ public: void addRoute(const NetworkPrefix & ,u_int16_t); void delRoute(const NetworkPrefix & ); u_int16_t getRoute(const NetworkAddress &); - bool empty(); - void clear(); + bool empty(network_address_type_t type); + void clear(network_address_type_t type); Mutex& getMutex(); u_int16_t* getOrNewRoutingTEUnlocked(const NetworkPrefix & addr); - u_int16_t getCountUnlocked(); - RoutingMap::iterator getBeginUnlocked(); - RoutingMap::iterator getEndUnlocked(); + u_int16_t getCountUnlocked(network_address_type_t type); + RoutingMap::iterator getBeginUnlocked(network_address_type_t type); + RoutingMap::iterator getEndUnlocked(network_address_type_t type); private: static Mutex instMutex; @@ -70,7 +69,7 @@ private: }; RoutingTable(const RoutingTable &s); void operator=(const RoutingTable &s); - RoutingMap routes_; + RoutingMap routes_[3]; Mutex mutex_; }; diff --git a/src/syncOnConnect.hpp b/src/syncOnConnect.hpp index caeae84..b0b8963 100644 --- a/src/syncOnConnect.hpp +++ b/src/syncOnConnect.hpp @@ -44,20 +44,25 @@ void syncOnConnect(SyncTcpConnection * connptr) connptr->Send(lengthout.str()); connptr->Send(sout.str()); } - //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(tmp); - oa << scom; - std::stringstream lengthout; - lengthout << std::setw(5) << std::setfill('0') << sout.str().size()<< ' '; - connptr->Send(lengthout.str()); - connptr->Send(sout.str()); - } + //TODO Locking here + network_address_type_t types[] = {ipv4,ipv6,ethernet}; + for (int types_idx=0; types_idx<3; types_idx++) + { + network_address_type_t type = types[types_idx]; + RoutingMap::iterator it = gRoutingTable.getBeginUnlocked(type); + for (;it!=gRoutingTable.getEndUnlocked(type);++it) + { + NetworkPrefix tmp(it->first); + std::ostringstream sout; + boost::archive::text_oarchive oa(sout); + const SyncCommand scom(tmp); + oa << scom; + std::stringstream lengthout; + lengthout << std::setw(5) << std::setfill('0') << sout.str().size()<< ' '; + connptr->Send(lengthout.str()); + connptr->Send(sout.str()); + } + } //TODO Locking here RtpSessionMap::iterator rit = gRtpSessionTable.getBeginUnlocked(); for (;rit!=gRtpSessionTable.getEndUnlocked();++rit) |