mirror of
https://github.com/espressif/openthread.git
synced 2026-10-01 21:37:39 +00:00
Only enable IPv6 forwarding for Router and Leader roles. (#390)
This commit is contained in:
@@ -49,6 +49,7 @@ namespace Ip6 {
|
|||||||
|
|
||||||
static otDEFINE_ALIGNED_VAR(sMplBuf, sizeof(Mpl), uint64_t);
|
static otDEFINE_ALIGNED_VAR(sMplBuf, sizeof(Mpl), uint64_t);
|
||||||
static Mpl *sMpl;
|
static Mpl *sMpl;
|
||||||
|
static bool sForwardingEnabled;
|
||||||
|
|
||||||
static otReceiveIp6DatagramCallback sReceiveIp6DatagramCallback = NULL;
|
static otReceiveIp6DatagramCallback sReceiveIp6DatagramCallback = NULL;
|
||||||
|
|
||||||
@@ -63,6 +64,12 @@ Message *Ip6::NewMessage(uint16_t reserved)
|
|||||||
void Ip6::Init(void)
|
void Ip6::Init(void)
|
||||||
{
|
{
|
||||||
sMpl = new(&sMplBuf) Mpl;
|
sMpl = new(&sMplBuf) Mpl;
|
||||||
|
sForwardingEnabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ip6::SetForwardingEnabled(bool aEnable)
|
||||||
|
{
|
||||||
|
sForwardingEnabled = aEnable;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t Ip6::UpdateChecksum(uint16_t checksum, uint16_t val)
|
uint16_t Ip6::UpdateChecksum(uint16_t checksum, uint16_t val)
|
||||||
@@ -405,6 +412,11 @@ ThreadError Ip6::HandleDatagram(Message &message, Netif *netif, int8_t interface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!sForwardingEnabled && netif != NULL)
|
||||||
|
{
|
||||||
|
forward = false;
|
||||||
|
}
|
||||||
|
|
||||||
message.SetOffset(sizeof(header));
|
message.SetOffset(sizeof(header));
|
||||||
|
|
||||||
// process IPv6 Extension Headers
|
// process IPv6 Extension Headers
|
||||||
|
|||||||
@@ -583,6 +583,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
static void SetReceiveDatagramCallback(otReceiveIp6DatagramCallback aCallback);
|
static void SetReceiveDatagramCallback(otReceiveIp6DatagramCallback aCallback);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This static method enables/disables IPv6 forwarding.
|
||||||
|
*
|
||||||
|
* @param[in] aEnable TRUE to enable IPv6 forwarding, FALSE otherwise.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static void SetForwardingEnabled(bool aEnable);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void ProcessReceiveCallback(Message &aMessage);
|
static void ProcessReceiveCallback(Message &aMessage);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -331,6 +331,8 @@ ThreadError Mle::SetStateDetached(void)
|
|||||||
mParentRequestTimer.Stop();
|
mParentRequestTimer.Stop();
|
||||||
mMesh.SetRxOnWhenIdle(true);
|
mMesh.SetRxOnWhenIdle(true);
|
||||||
mMleRouter.HandleDetachStart();
|
mMleRouter.HandleDetachStart();
|
||||||
|
Ip6::Ip6::SetForwardingEnabled(false);
|
||||||
|
|
||||||
otLogInfoMle("Mode -> Detached\n");
|
otLogInfoMle("Mode -> Detached\n");
|
||||||
return kThreadError_None;
|
return kThreadError_None;
|
||||||
}
|
}
|
||||||
@@ -356,6 +358,8 @@ ThreadError Mle::SetStateChild(uint16_t aRloc16)
|
|||||||
mMleRouter.HandleChildStart(mParentRequestMode);
|
mMleRouter.HandleChildStart(mParentRequestMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ip6::Ip6::SetForwardingEnabled(false);
|
||||||
|
|
||||||
otLogInfoMle("Mode -> Child\n");
|
otLogInfoMle("Mode -> Child\n");
|
||||||
return kThreadError_None;
|
return kThreadError_None;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -338,6 +338,7 @@ ThreadError MleRouter::SetStateRouter(uint16_t aRloc16)
|
|||||||
mRouters[mRouterId].mNextHop = mRouterId;
|
mRouters[mRouterId].mNextHop = mRouterId;
|
||||||
mNetworkData.Stop();
|
mNetworkData.Stop();
|
||||||
mStateUpdateTimer.Start(kStateUpdatePeriod);
|
mStateUpdateTimer.Start(kStateUpdatePeriod);
|
||||||
|
Ip6::Ip6::SetForwardingEnabled(true);
|
||||||
|
|
||||||
otLogInfoMle("Mode -> Router\n");
|
otLogInfoMle("Mode -> Router\n");
|
||||||
return kThreadError_None;
|
return kThreadError_None;
|
||||||
@@ -364,6 +365,7 @@ ThreadError MleRouter::SetStateLeader(uint16_t aRloc16)
|
|||||||
mNetif.GetPendingDataset().ApplyLocalToNetwork();
|
mNetif.GetPendingDataset().ApplyLocalToNetwork();
|
||||||
mCoapServer.AddResource(mAddressSolicit);
|
mCoapServer.AddResource(mAddressSolicit);
|
||||||
mCoapServer.AddResource(mAddressRelease);
|
mCoapServer.AddResource(mAddressRelease);
|
||||||
|
Ip6::Ip6::SetForwardingEnabled(true);
|
||||||
|
|
||||||
otLogInfoMle("Mode -> Leader %d\n", mLeaderData.GetPartitionId());
|
otLogInfoMle("Mode -> Leader %d\n", mLeaderData.GetPartitionId());
|
||||||
return kThreadError_None;
|
return kThreadError_None;
|
||||||
|
|||||||
Reference in New Issue
Block a user