[route-table] remove unused Ip6::Routes (#3911)

This commit is contained in:
Jonathan Hui
2019-06-13 08:32:05 -07:00
committed by GitHub
parent dbc04a8a05
commit caf268c45e
7 changed files with 34 additions and 273 deletions
-1
View File
@@ -184,7 +184,6 @@ LOCAL_SRC_FILES := \
src/core/net/ip6_filter.cpp \
src/core/net/ip6_headers.cpp \
src/core/net/ip6_mpl.cpp \
src/core/net/ip6_routes.cpp \
src/core/net/netif.cpp \
src/core/net/udp6.cpp \
src/core/phy/radio_weak.cpp \
-2
View File
@@ -190,7 +190,6 @@ SOURCES_COMMON = \
net/ip6_filter.cpp \
net/ip6_headers.cpp \
net/ip6_mpl.cpp \
net/ip6_routes.cpp \
net/netif.cpp \
net/sntp_client.cpp \
net/udp6.cpp \
@@ -359,7 +358,6 @@ HEADERS_COMMON = \
net/ip6_filter.hpp \
net/ip6_headers.hpp \
net/ip6_mpl.hpp \
net/ip6_routes.hpp \
net/netif.hpp \
net/sntp_client.hpp \
net/socket.hpp \
-5
View File
@@ -511,11 +511,6 @@ template <> inline NetworkData::Leader &Instance::Get(void)
return mThreadNetif.mNetworkDataLeader;
}
template <> inline Ip6::Routes &Instance::Get(void)
{
return mIp6.mRoutes;
}
template <> inline Ip6::Udp &Instance::Get(void)
{
return mIp6.mUdp;
+20 -3
View File
@@ -41,7 +41,6 @@
#include "common/message.hpp"
#include "net/icmp6.hpp"
#include "net/ip6_address.hpp"
#include "net/ip6_routes.hpp"
#include "net/netif.hpp"
#include "net/udp6.hpp"
#include "thread/mle.hpp"
@@ -58,7 +57,6 @@ Ip6::Ip6(Instance &aInstance)
, mNetifListHead(NULL)
, mSendQueue()
, mSendQueueTask(aInstance, HandleSendQueue, this)
, mRoutes(aInstance)
, mIcmp(aInstance)
, mUdp(aInstance)
, mMpl(aInstance)
@@ -989,7 +987,7 @@ int8_t Ip6::FindForwardInterfaceId(const MessageInfo &aMessageInfo)
// on-link global address
;
}
else if ((interfaceId = mRoutes.Lookup(aMessageInfo.GetPeerAddr(), aMessageInfo.GetSockAddr())) > 0)
else if ((interfaceId = RouteLookup(aMessageInfo.GetPeerAddr(), aMessageInfo.GetSockAddr())) > 0)
{
// route
;
@@ -1002,6 +1000,25 @@ int8_t Ip6::FindForwardInterfaceId(const MessageInfo &aMessageInfo)
return interfaceId;
}
int8_t Ip6::RouteLookup(const Address &aSource, const Address &aDestination)
{
int8_t maxPrefixMatch = -1;
uint8_t prefixMatch;
int8_t rval = -1;
for (Netif *netif = Get<Ip6>().GetNetifList(); netif; netif = netif->GetNext())
{
if (netif->RouteLookup(aSource, aDestination, &prefixMatch) == OT_ERROR_NONE &&
static_cast<int8_t>(prefixMatch) > maxPrefixMatch)
{
maxPrefixMatch = static_cast<int8_t>(prefixMatch);
rval = netif->GetInterfaceId();
}
}
return rval;
}
otError Ip6::AddNetif(Netif &aNetif)
{
otError error = OT_ERROR_NONE;
+14 -5
View File
@@ -48,7 +48,6 @@
#include "net/ip6_address.hpp"
#include "net/ip6_headers.hpp"
#include "net/ip6_mpl.hpp"
#include "net/ip6_routes.hpp"
#include "net/netif.hpp"
#include "net/socket.hpp"
#include "net/udp6.hpp"
@@ -381,6 +380,17 @@ public:
*/
int8_t GetOnLinkNetif(const Address &aAddress);
/**
* This method performs a route lookup.
*
* @param[in] aSource A reference to the IPv6 source address.
* @param[in] aDestination A reference to the IPv6 destination address.
*
* @returns The network interface identifier for the interface if a route is round, otherwise -1
*
*/
int8_t RouteLookup(const Address &aSource, const Address &aDestination);
/**
* This method returns a reference to the send queue.
*
@@ -435,10 +445,9 @@ private:
PriorityQueue mSendQueue;
Tasklet mSendQueueTask;
Routes mRoutes;
Icmp mIcmp;
Udp mUdp;
Mpl mMpl;
Icmp mIcmp;
Udp mUdp;
Mpl mMpl;
};
/**
-132
View File
@@ -1,132 +0,0 @@
/*
* Copyright (c) 2016, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file implements IPv6 route tables.
*/
#include "ip6_routes.hpp"
#include "common/code_utils.hpp"
#include "common/instance.hpp"
#include "common/locator-getters.hpp"
#include "common/message.hpp"
#include "net/ip6.hpp"
#include "net/netif.hpp"
namespace ot {
namespace Ip6 {
Routes::Routes(Instance &aInstance)
: InstanceLocator(aInstance)
, mRoutes(NULL)
{
}
otError Routes::Add(Route &aRoute)
{
otError error = OT_ERROR_NONE;
for (Route *cur = mRoutes; cur; cur = cur->mNext)
{
VerifyOrExit(cur != &aRoute, error = OT_ERROR_ALREADY);
}
aRoute.mNext = mRoutes;
mRoutes = &aRoute;
exit:
return error;
}
void Routes::Remove(Route &aRoute)
{
if (&aRoute == mRoutes)
{
mRoutes = aRoute.mNext;
}
else
{
for (Route *cur = mRoutes; cur; cur = cur->mNext)
{
if (cur->mNext == &aRoute)
{
cur->mNext = aRoute.mNext;
break;
}
}
}
aRoute.mNext = NULL;
}
int8_t Routes::Lookup(const Address &aSource, const Address &aDestination)
{
int8_t maxPrefixMatch = -1;
uint8_t prefixMatch;
int8_t rval = -1;
for (Route *cur = mRoutes; cur; cur = cur->mNext)
{
prefixMatch = cur->mPrefix.PrefixMatch(aDestination);
if (prefixMatch < cur->mPrefixLength)
{
continue;
}
if (prefixMatch > cur->mPrefixLength)
{
prefixMatch = cur->mPrefixLength;
}
if (maxPrefixMatch > static_cast<int8_t>(prefixMatch))
{
continue;
}
maxPrefixMatch = static_cast<int8_t>(prefixMatch);
rval = cur->mInterfaceId;
}
for (Netif *netif = Get<Ip6>().GetNetifList(); netif; netif = netif->GetNext())
{
if (netif->RouteLookup(aSource, aDestination, &prefixMatch) == OT_ERROR_NONE &&
static_cast<int8_t>(prefixMatch) > maxPrefixMatch)
{
maxPrefixMatch = static_cast<int8_t>(prefixMatch);
rval = netif->GetInterfaceId();
}
}
return rval;
}
} // namespace Ip6
} // namespace ot
-125
View File
@@ -1,125 +0,0 @@
/*
* Copyright (c) 2016, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef IP6_ROUTES_HPP_
#define IP6_ROUTES_HPP_
/**
* @file
* This file includes definitions for manipulating IPv6 routing tables.
*/
#include "openthread-core-config.h"
#include "common/locator.hpp"
#include "common/message.hpp"
#include "net/ip6_address.hpp"
#include "net/ip6_routes.hpp"
namespace ot {
namespace Ip6 {
class Ip6;
/**
* @addtogroup core-ip6-ip6
*
* @{
*
*/
/**
* This structure represents an IPv6 route.
*
*/
struct Route
{
Address mPrefix; ///< The IPv6 prefix.
uint8_t mPrefixLength; ///< The IPv6 prefix length.
int8_t mInterfaceId; ///< The interface identifier.
struct Route *mNext; ///< A pointer to the next IPv6 route.
};
/**
* This class implements IPv6 route management.
*
*/
class Routes : public InstanceLocator
{
public:
/**
* This constructor initializes the object.
*
* @param[in] aInstance A reference to the OpenThread instance.
*
*/
explicit Routes(Instance &aInstance);
/**
* This method adds an IPv6 route.
*
* @param[in] aRoute A reference to the IPv6 route.
*
* @retval OT_ERROR_NONE Successfully added the route.
* @retval OT_ERROR_ALREADY The route was already added.
*
*/
otError Add(Route &aRoute);
/**
* This method removes an IPv6 route.
*
* @param[in] aRoute A reference to the IPv6 route.
*
*/
void Remove(Route &aRoute);
/**
* This method performs source-destination route lookup.
*
* @param[in] aSource The IPv6 source address.
* @param[in] aDestination The IPv6 destination address.
*
* @returns The interface identifier for the best route or -1 if no route is available.
*
*/
int8_t Lookup(const Address &aSource, const Address &aDestination);
private:
Route *mRoutes;
};
/**
* @}
*
*/
} // namespace Ip6
} // namespace ot
#endif // IP6_ROUTES_HPP_