mirror of
https://github.com/espressif/openthread.git
synced 2026-10-09 17:27:41 +00:00
Remove globals from ip6_routes.cpp.
This commit is contained in:
@@ -48,6 +48,7 @@ namespace Thread {
|
|||||||
namespace Ip6 {
|
namespace Ip6 {
|
||||||
|
|
||||||
Ip6::Ip6(void):
|
Ip6::Ip6(void):
|
||||||
|
mRoutes(*this),
|
||||||
mIcmp(*this),
|
mIcmp(*this),
|
||||||
mUdp(*this),
|
mUdp(*this),
|
||||||
mForwardingEnabled(false),
|
mForwardingEnabled(false),
|
||||||
@@ -530,7 +531,7 @@ ThreadError Ip6::ForwardMessage(Message &message, MessageInfo &messageInfo)
|
|||||||
// on-link global address
|
// on-link global address
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
else if ((interfaceId = Routes::Lookup(messageInfo.GetPeerAddr(), messageInfo.GetSockAddr())) > 0)
|
else if ((interfaceId = mRoutes.Lookup(messageInfo.GetPeerAddr(), messageInfo.GetSockAddr())) > 0)
|
||||||
{
|
{
|
||||||
// route
|
// route
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
#include <net/icmp6.hpp>
|
#include <net/icmp6.hpp>
|
||||||
#include <net/ip6_address.hpp>
|
#include <net/ip6_address.hpp>
|
||||||
#include <net/ip6_headers.hpp>
|
#include <net/ip6_headers.hpp>
|
||||||
|
#include <net/ip6_routes.hpp>
|
||||||
#include <net/ip6_mpl.hpp>
|
#include <net/ip6_mpl.hpp>
|
||||||
#include <net/netif.hpp>
|
#include <net/netif.hpp>
|
||||||
#include <net/socket.hpp>
|
#include <net/socket.hpp>
|
||||||
@@ -322,6 +323,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
int8_t GetOnLinkNetif(const Address &aAddress);
|
int8_t GetOnLinkNetif(const Address &aAddress);
|
||||||
|
|
||||||
|
Routes mRoutes;
|
||||||
Icmp mIcmp;
|
Icmp mIcmp;
|
||||||
Udp mUdp;
|
Udp mUdp;
|
||||||
|
|
||||||
|
|||||||
+13
-12
@@ -38,24 +38,25 @@
|
|||||||
#include <common/message.hpp>
|
#include <common/message.hpp>
|
||||||
|
|
||||||
namespace Thread {
|
namespace Thread {
|
||||||
|
|
||||||
extern Ip6::Ip6 *sIp6;
|
|
||||||
|
|
||||||
namespace Ip6 {
|
namespace Ip6 {
|
||||||
|
|
||||||
static Route *sRoutes = NULL;
|
Routes::Routes(Ip6 &aIp6):
|
||||||
|
mRoutes(NULL),
|
||||||
|
mIp6(aIp6)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
ThreadError Routes::Add(Route &aRoute)
|
ThreadError Routes::Add(Route &aRoute)
|
||||||
{
|
{
|
||||||
ThreadError error = kThreadError_None;
|
ThreadError error = kThreadError_None;
|
||||||
|
|
||||||
for (Route *cur = sRoutes; cur; cur = cur->mNext)
|
for (Route *cur = mRoutes; cur; cur = cur->mNext)
|
||||||
{
|
{
|
||||||
VerifyOrExit(cur != &aRoute, error = kThreadError_Busy);
|
VerifyOrExit(cur != &aRoute, error = kThreadError_Busy);
|
||||||
}
|
}
|
||||||
|
|
||||||
aRoute.mNext = sRoutes;
|
aRoute.mNext = mRoutes;
|
||||||
sRoutes = &aRoute;
|
mRoutes = &aRoute;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return error;
|
return error;
|
||||||
@@ -63,13 +64,13 @@ exit:
|
|||||||
|
|
||||||
ThreadError Routes::Remove(Route &aRoute)
|
ThreadError Routes::Remove(Route &aRoute)
|
||||||
{
|
{
|
||||||
if (&aRoute == sRoutes)
|
if (&aRoute == mRoutes)
|
||||||
{
|
{
|
||||||
sRoutes = aRoute.mNext;
|
mRoutes = aRoute.mNext;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (Route *cur = sRoutes; cur; cur = cur->mNext)
|
for (Route *cur = mRoutes; cur; cur = cur->mNext)
|
||||||
{
|
{
|
||||||
if (cur->mNext == &aRoute)
|
if (cur->mNext == &aRoute)
|
||||||
{
|
{
|
||||||
@@ -90,7 +91,7 @@ int8_t Routes::Lookup(const Address &aSource, const Address &aDestination)
|
|||||||
uint8_t prefixMatch;
|
uint8_t prefixMatch;
|
||||||
int8_t rval = -1;
|
int8_t rval = -1;
|
||||||
|
|
||||||
for (Route *cur = sRoutes; cur; cur = cur->mNext)
|
for (Route *cur = mRoutes; cur; cur = cur->mNext)
|
||||||
{
|
{
|
||||||
prefixMatch = cur->mPrefix.PrefixMatch(aDestination);
|
prefixMatch = cur->mPrefix.PrefixMatch(aDestination);
|
||||||
|
|
||||||
@@ -113,7 +114,7 @@ int8_t Routes::Lookup(const Address &aSource, const Address &aDestination)
|
|||||||
rval = cur->mInterfaceId;
|
rval = cur->mInterfaceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Netif *netif = sIp6->GetNetifList(); netif; netif = netif->GetNext())
|
for (Netif *netif = mIp6.GetNetifList(); netif; netif = netif->GetNext())
|
||||||
{
|
{
|
||||||
if (netif->RouteLookup(aSource, aDestination, &prefixMatch) == kThreadError_None &&
|
if (netif->RouteLookup(aSource, aDestination, &prefixMatch) == kThreadError_None &&
|
||||||
static_cast<int8_t>(prefixMatch) > maxPrefixMatch)
|
static_cast<int8_t>(prefixMatch) > maxPrefixMatch)
|
||||||
|
|||||||
@@ -68,7 +68,15 @@ class Routes
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* This static method adds an IPv6 route.
|
* This constructor initializes the object.
|
||||||
|
*
|
||||||
|
* @param[in] aIp6 A reference to the IPv6 network object.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
Routes(Ip6 &aIp6);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method adds an IPv6 route.
|
||||||
*
|
*
|
||||||
* @param[in] aRoute A reference to the IPv6 route.
|
* @param[in] aRoute A reference to the IPv6 route.
|
||||||
*
|
*
|
||||||
@@ -76,10 +84,10 @@ public:
|
|||||||
* @retval kThreadError_Busy The route was already added.
|
* @retval kThreadError_Busy The route was already added.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static ThreadError Add(Route &aRoute);
|
ThreadError Add(Route &aRoute);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This static method removes an IPv6 route.
|
* This method removes an IPv6 route.
|
||||||
*
|
*
|
||||||
* @param[in] aRoute A reference to the IPv6 route.
|
* @param[in] aRoute A reference to the IPv6 route.
|
||||||
*
|
*
|
||||||
@@ -87,10 +95,10 @@ public:
|
|||||||
* @retval kThreadError_InvalidArgs The route was not added.
|
* @retval kThreadError_InvalidArgs The route was not added.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static ThreadError Remove(Route &aRoute);
|
ThreadError Remove(Route &aRoute);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This static method performs source-destination route lookup.
|
* This method performs source-destination route lookup.
|
||||||
*
|
*
|
||||||
* @param[in] aSource The IPv6 source address.
|
* @param[in] aSource The IPv6 source address.
|
||||||
* @param[in] aDestination The IPv6 destination address.
|
* @param[in] aDestination The IPv6 destination address.
|
||||||
@@ -98,7 +106,11 @@ public:
|
|||||||
* @returns The interface identifier for the best route or -1 if no route is available.
|
* @returns The interface identifier for the best route or -1 if no route is available.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static int8_t Lookup(const Address &aSource, const Address &aDestination);
|
int8_t Lookup(const Address &aSource, const Address &aDestination);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Route *mRoutes;
|
||||||
|
Ip6 &mIp6;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user