From 7582db6df204e151b0766d5a4ad3b2242eebc8be Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 22 Dec 2008 19:44:08 +0000 Subject: some cleanup fixed locking error at routingtable --- src/routingTable.cpp | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/routingTable.cpp b/src/routingTable.cpp index 608c420..3c79e8f 100644 --- a/src/routingTable.cpp +++ b/src/routingTable.cpp @@ -60,6 +60,8 @@ RoutingTable::~RoutingTable() void RoutingTable::updateRouteTree(const NetworkPrefix & pref) { + Lock lock(mutex_); + u_int8_t length=pref.getNetworkPrefixLength(); network_address_type_t type=pref.getNetworkAddressType(); u_int16_t mux = routes_[pref.getNetworkAddressType()].find(pref)->second; @@ -86,20 +88,26 @@ void RoutingTable::updateRouteTree(const NetworkPrefix & pref) //root_[type].print(0); } -void RoutingTable::addRoute(const NetworkPrefix & pref,u_int16_t mux ) +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 ret = routes_[pref.getNetworkAddressType()].insert(RoutingMap::value_type(pref,mux)); - if(!ret.second) - { - routes_[pref.getNetworkAddressType()].erase(ret.first); - routes_[pref.getNetworkAddressType()].insert(RoutingMap::value_type(pref,mux)); - } - updateRouteTree(pref); + network_address_type_t type=pref.getNetworkAddressType(); + + if (type==ipv4 || type==ipv6) + { + std::pair ret = routes_[type].insert(RoutingMap::value_type(pref,mux)); + if(!ret.second) + { + routes_[pref.getNetworkAddressType()].erase(ret.first); + routes_[pref.getNetworkAddressType()].insert(RoutingMap::value_type(pref,mux)); + } + updateRouteTree(pref); + } else if (type==ethernet) { + return; // TODO: add support for ethernet + } else { + throw std::runtime_error("illegal protocoll type"); + } } -- cgit v1.2.3