[border-router] use `Ip6::Nd` namespace for IPv6 Neighbor Discovery (#7780)
This commit uses `Ip6::Nd` namespace for IPv6 Neighbor Discovery definitions (used for border router). It also renames and moves the source files to `net/nd6.*`.
This commit is contained in:
parent
19f8033b78
commit
ac62f7819c
|
@ -221,7 +221,6 @@ LOCAL_SRC_FILES := \
|
||||||
src/core/backbone_router/multicast_listeners_table.cpp \
|
src/core/backbone_router/multicast_listeners_table.cpp \
|
||||||
src/core/backbone_router/ndproxy_table.cpp \
|
src/core/backbone_router/ndproxy_table.cpp \
|
||||||
src/core/border_router/infra_if.cpp \
|
src/core/border_router/infra_if.cpp \
|
||||||
src/core/border_router/router_advertisement.cpp \
|
|
||||||
src/core/border_router/routing_manager.cpp \
|
src/core/border_router/routing_manager.cpp \
|
||||||
src/core/coap/coap.cpp \
|
src/core/coap/coap.cpp \
|
||||||
src/core/coap/coap_message.cpp \
|
src/core/coap/coap_message.cpp \
|
||||||
|
@ -303,6 +302,7 @@ LOCAL_SRC_FILES := \
|
||||||
src/core/net/ip6_filter.cpp \
|
src/core/net/ip6_filter.cpp \
|
||||||
src/core/net/ip6_headers.cpp \
|
src/core/net/ip6_headers.cpp \
|
||||||
src/core/net/ip6_mpl.cpp \
|
src/core/net/ip6_mpl.cpp \
|
||||||
|
src/core/net/nd6.cpp \
|
||||||
src/core/net/nd_agent.cpp \
|
src/core/net/nd_agent.cpp \
|
||||||
src/core/net/netif.cpp \
|
src/core/net/netif.cpp \
|
||||||
src/core/net/sntp_client.cpp \
|
src/core/net/sntp_client.cpp \
|
||||||
|
|
|
@ -367,8 +367,6 @@ openthread_core_files = [
|
||||||
"backbone_router/ndproxy_table.hpp",
|
"backbone_router/ndproxy_table.hpp",
|
||||||
"border_router/infra_if.cpp",
|
"border_router/infra_if.cpp",
|
||||||
"border_router/infra_if.hpp",
|
"border_router/infra_if.hpp",
|
||||||
"border_router/router_advertisement.cpp",
|
|
||||||
"border_router/router_advertisement.hpp",
|
|
||||||
"border_router/routing_manager.cpp",
|
"border_router/routing_manager.cpp",
|
||||||
"border_router/routing_manager.hpp",
|
"border_router/routing_manager.hpp",
|
||||||
"coap/coap.cpp",
|
"coap/coap.cpp",
|
||||||
|
@ -560,6 +558,8 @@ openthread_core_files = [
|
||||||
"net/ip6_mpl.cpp",
|
"net/ip6_mpl.cpp",
|
||||||
"net/ip6_mpl.hpp",
|
"net/ip6_mpl.hpp",
|
||||||
"net/ip6_types.hpp",
|
"net/ip6_types.hpp",
|
||||||
|
"net/nd6.cpp",
|
||||||
|
"net/nd6.hpp",
|
||||||
"net/nd_agent.cpp",
|
"net/nd_agent.cpp",
|
||||||
"net/nd_agent.hpp",
|
"net/nd_agent.hpp",
|
||||||
"net/netif.cpp",
|
"net/netif.cpp",
|
||||||
|
|
|
@ -87,7 +87,6 @@ set(COMMON_SOURCES
|
||||||
backbone_router/multicast_listeners_table.cpp
|
backbone_router/multicast_listeners_table.cpp
|
||||||
backbone_router/ndproxy_table.cpp
|
backbone_router/ndproxy_table.cpp
|
||||||
border_router/infra_if.cpp
|
border_router/infra_if.cpp
|
||||||
border_router/router_advertisement.cpp
|
|
||||||
border_router/routing_manager.cpp
|
border_router/routing_manager.cpp
|
||||||
coap/coap.cpp
|
coap/coap.cpp
|
||||||
coap/coap_message.cpp
|
coap/coap_message.cpp
|
||||||
|
@ -169,6 +168,7 @@ set(COMMON_SOURCES
|
||||||
net/ip6_filter.cpp
|
net/ip6_filter.cpp
|
||||||
net/ip6_headers.cpp
|
net/ip6_headers.cpp
|
||||||
net/ip6_mpl.cpp
|
net/ip6_mpl.cpp
|
||||||
|
net/nd6.cpp
|
||||||
net/nd_agent.cpp
|
net/nd_agent.cpp
|
||||||
net/netif.cpp
|
net/netif.cpp
|
||||||
net/sntp_client.cpp
|
net/sntp_client.cpp
|
||||||
|
|
|
@ -177,7 +177,6 @@ SOURCES_COMMON = \
|
||||||
backbone_router/multicast_listeners_table.cpp \
|
backbone_router/multicast_listeners_table.cpp \
|
||||||
backbone_router/ndproxy_table.cpp \
|
backbone_router/ndproxy_table.cpp \
|
||||||
border_router/infra_if.cpp \
|
border_router/infra_if.cpp \
|
||||||
border_router/router_advertisement.cpp \
|
|
||||||
border_router/routing_manager.cpp \
|
border_router/routing_manager.cpp \
|
||||||
coap/coap.cpp \
|
coap/coap.cpp \
|
||||||
coap/coap_message.cpp \
|
coap/coap_message.cpp \
|
||||||
|
@ -259,6 +258,7 @@ SOURCES_COMMON = \
|
||||||
net/ip6_filter.cpp \
|
net/ip6_filter.cpp \
|
||||||
net/ip6_headers.cpp \
|
net/ip6_headers.cpp \
|
||||||
net/ip6_mpl.cpp \
|
net/ip6_mpl.cpp \
|
||||||
|
net/nd6.cpp \
|
||||||
net/nd_agent.cpp \
|
net/nd_agent.cpp \
|
||||||
net/netif.cpp \
|
net/netif.cpp \
|
||||||
net/sntp_client.cpp \
|
net/sntp_client.cpp \
|
||||||
|
@ -416,7 +416,6 @@ HEADERS_COMMON = \
|
||||||
backbone_router/multicast_listeners_table.hpp \
|
backbone_router/multicast_listeners_table.hpp \
|
||||||
backbone_router/ndproxy_table.hpp \
|
backbone_router/ndproxy_table.hpp \
|
||||||
border_router/infra_if.hpp \
|
border_router/infra_if.hpp \
|
||||||
border_router/router_advertisement.hpp \
|
|
||||||
border_router/routing_manager.hpp \
|
border_router/routing_manager.hpp \
|
||||||
coap/coap.hpp \
|
coap/coap.hpp \
|
||||||
coap/coap_message.hpp \
|
coap/coap_message.hpp \
|
||||||
|
@ -564,6 +563,7 @@ HEADERS_COMMON = \
|
||||||
net/ip6_headers.hpp \
|
net/ip6_headers.hpp \
|
||||||
net/ip6_mpl.hpp \
|
net/ip6_mpl.hpp \
|
||||||
net/ip6_types.hpp \
|
net/ip6_types.hpp \
|
||||||
|
net/nd6.hpp \
|
||||||
net/nd_agent.hpp \
|
net/nd_agent.hpp \
|
||||||
net/netif.hpp \
|
net/netif.hpp \
|
||||||
net/sntp_client.hpp \
|
net/sntp_client.hpp \
|
||||||
|
|
|
@ -816,9 +816,9 @@ bool RoutingManager::IsRouterSolicitationInProgress(void) const
|
||||||
|
|
||||||
Error RoutingManager::SendRouterSolicitation(void)
|
Error RoutingManager::SendRouterSolicitation(void)
|
||||||
{
|
{
|
||||||
Ip6::Address destAddress;
|
Ip6::Address destAddress;
|
||||||
RouterAdv::RouterSolicitMessage routerSolicit;
|
Ip6::Nd::RouterSolicitMessage routerSolicit;
|
||||||
InfraIf::Icmp6Packet packet;
|
InfraIf::Icmp6Packet packet;
|
||||||
|
|
||||||
OT_ASSERT(IsInitialized());
|
OT_ASSERT(IsInitialized());
|
||||||
|
|
||||||
|
@ -842,11 +842,11 @@ void RoutingManager::SendRouterAdvertisement(const OmrPrefixArray &aNewOmrPrefix
|
||||||
|
|
||||||
if (mIsAdvertisingLocalOnLinkPrefix)
|
if (mIsAdvertisingLocalOnLinkPrefix)
|
||||||
{
|
{
|
||||||
RouterAdv::PrefixInfoOption *pio;
|
Ip6::Nd::PrefixInfoOption *pio;
|
||||||
|
|
||||||
OT_ASSERT(bufferLength + sizeof(RouterAdv::PrefixInfoOption) <= sizeof(buffer));
|
OT_ASSERT(bufferLength + sizeof(Ip6::Nd::PrefixInfoOption) <= sizeof(buffer));
|
||||||
|
|
||||||
pio = reinterpret_cast<RouterAdv::PrefixInfoOption *>(buffer + bufferLength);
|
pio = reinterpret_cast<Ip6::Nd::PrefixInfoOption *>(buffer + bufferLength);
|
||||||
|
|
||||||
pio->Init();
|
pio->Init();
|
||||||
pio->SetOnLinkFlag();
|
pio->SetOnLinkFlag();
|
||||||
|
@ -864,11 +864,11 @@ void RoutingManager::SendRouterAdvertisement(const OmrPrefixArray &aNewOmrPrefix
|
||||||
}
|
}
|
||||||
else if (mOnLinkPrefixDeprecateTimer.IsRunning())
|
else if (mOnLinkPrefixDeprecateTimer.IsRunning())
|
||||||
{
|
{
|
||||||
RouterAdv::PrefixInfoOption *pio;
|
Ip6::Nd::PrefixInfoOption *pio;
|
||||||
|
|
||||||
OT_ASSERT(bufferLength + sizeof(RouterAdv::PrefixInfoOption) <= sizeof(buffer));
|
OT_ASSERT(bufferLength + sizeof(Ip6::Nd::PrefixInfoOption) <= sizeof(buffer));
|
||||||
|
|
||||||
pio = reinterpret_cast<RouterAdv::PrefixInfoOption *>(buffer + bufferLength);
|
pio = reinterpret_cast<Ip6::Nd::PrefixInfoOption *>(buffer + bufferLength);
|
||||||
|
|
||||||
pio->Init();
|
pio->Init();
|
||||||
pio->SetOnLinkFlag();
|
pio->SetOnLinkFlag();
|
||||||
|
@ -891,13 +891,13 @@ void RoutingManager::SendRouterAdvertisement(const OmrPrefixArray &aNewOmrPrefix
|
||||||
{
|
{
|
||||||
if (!aNewOmrPrefixes.ContainsMatching(advertisedOmrPrefix.GetPrefix()))
|
if (!aNewOmrPrefixes.ContainsMatching(advertisedOmrPrefix.GetPrefix()))
|
||||||
{
|
{
|
||||||
RouterAdv::RouteInfoOption *rio;
|
Ip6::Nd::RouteInfoOption *rio;
|
||||||
|
|
||||||
OT_ASSERT(bufferLength + RouterAdv::RouteInfoOption::OptionSizeForPrefix(
|
OT_ASSERT(bufferLength +
|
||||||
advertisedOmrPrefix.GetPrefix().GetLength()) <=
|
Ip6::Nd::RouteInfoOption::OptionSizeForPrefix(advertisedOmrPrefix.GetPrefix().GetLength()) <=
|
||||||
sizeof(buffer));
|
sizeof(buffer));
|
||||||
|
|
||||||
rio = reinterpret_cast<RouterAdv::RouteInfoOption *>(buffer + bufferLength);
|
rio = reinterpret_cast<Ip6::Nd::RouteInfoOption *>(buffer + bufferLength);
|
||||||
|
|
||||||
// Set zero route lifetime to immediately invalidate the advertised OMR prefix.
|
// Set zero route lifetime to immediately invalidate the advertised OMR prefix.
|
||||||
rio->Init();
|
rio->Init();
|
||||||
|
@ -913,13 +913,12 @@ void RoutingManager::SendRouterAdvertisement(const OmrPrefixArray &aNewOmrPrefix
|
||||||
|
|
||||||
for (const OmrPrefix &newOmrPrefix : aNewOmrPrefixes)
|
for (const OmrPrefix &newOmrPrefix : aNewOmrPrefixes)
|
||||||
{
|
{
|
||||||
RouterAdv::RouteInfoOption *rio;
|
Ip6::Nd::RouteInfoOption *rio;
|
||||||
|
|
||||||
OT_ASSERT(bufferLength +
|
OT_ASSERT(bufferLength + Ip6::Nd::RouteInfoOption::OptionSizeForPrefix(newOmrPrefix.GetPrefix().GetLength()) <=
|
||||||
RouterAdv::RouteInfoOption::OptionSizeForPrefix(newOmrPrefix.GetPrefix().GetLength()) <=
|
|
||||||
sizeof(buffer));
|
sizeof(buffer));
|
||||||
|
|
||||||
rio = reinterpret_cast<RouterAdv::RouteInfoOption *>(buffer + bufferLength);
|
rio = reinterpret_cast<Ip6::Nd::RouteInfoOption *>(buffer + bufferLength);
|
||||||
|
|
||||||
rio->Init();
|
rio->Init();
|
||||||
rio->SetRouteLifetime(kDefaultOmrPrefixLifetime);
|
rio->SetRouteLifetime(kDefaultOmrPrefixLifetime);
|
||||||
|
@ -978,7 +977,7 @@ bool RoutingManager::IsValidOmrPrefix(const Ip6::Prefix &aOmrPrefix)
|
||||||
(aOmrPrefix.mLength >= 3 && (aOmrPrefix.GetBytes()[0] & 0xE0) == 0x20);
|
(aOmrPrefix.mLength >= 3 && (aOmrPrefix.GetBytes()[0] & 0xE0) == 0x20);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RoutingManager::IsValidOnLinkPrefix(const RouterAdv::PrefixInfoOption &aPio)
|
bool RoutingManager::IsValidOnLinkPrefix(const Ip6::Nd::PrefixInfoOption &aPio)
|
||||||
{
|
{
|
||||||
Ip6::Prefix prefix;
|
Ip6::Prefix prefix;
|
||||||
|
|
||||||
|
@ -1109,35 +1108,30 @@ void RoutingManager::HandleRouterAdvertisement(const InfraIf::Icmp6Packet &aPack
|
||||||
OT_ASSERT(mIsRunning);
|
OT_ASSERT(mIsRunning);
|
||||||
OT_UNUSED_VARIABLE(aSrcAddress);
|
OT_UNUSED_VARIABLE(aSrcAddress);
|
||||||
|
|
||||||
using RouterAdv::Option;
|
bool needReevaluate = false;
|
||||||
using RouterAdv::PrefixInfoOption;
|
const uint8_t * optionsBegin;
|
||||||
using RouterAdv::RouteInfoOption;
|
uint16_t optionsLength;
|
||||||
using RouterAdv::RouterAdvMessage;
|
const Ip6::Nd::Option * option;
|
||||||
|
const Ip6::Nd::RouterAdvMessage *routerAdvMessage;
|
||||||
|
|
||||||
bool needReevaluate = false;
|
VerifyOrExit(aPacket.GetLength() >= sizeof(Ip6::Nd::RouterAdvMessage));
|
||||||
const uint8_t * optionsBegin;
|
|
||||||
uint16_t optionsLength;
|
|
||||||
const Option * option;
|
|
||||||
const RouterAdvMessage *routerAdvMessage;
|
|
||||||
|
|
||||||
VerifyOrExit(aPacket.GetLength() >= sizeof(RouterAdvMessage));
|
|
||||||
|
|
||||||
LogInfo("Received Router Advertisement from %s on %s", aSrcAddress.ToString().AsCString(),
|
LogInfo("Received Router Advertisement from %s on %s", aSrcAddress.ToString().AsCString(),
|
||||||
mInfraIf.ToString().AsCString());
|
mInfraIf.ToString().AsCString());
|
||||||
DumpDebg("[BR-CERT] direction=recv | type=RA |", aPacket.GetBytes(), aPacket.GetLength());
|
DumpDebg("[BR-CERT] direction=recv | type=RA |", aPacket.GetBytes(), aPacket.GetLength());
|
||||||
|
|
||||||
routerAdvMessage = reinterpret_cast<const RouterAdvMessage *>(aPacket.GetBytes());
|
routerAdvMessage = reinterpret_cast<const Ip6::Nd::RouterAdvMessage *>(aPacket.GetBytes());
|
||||||
optionsBegin = aPacket.GetBytes() + sizeof(RouterAdvMessage);
|
optionsBegin = aPacket.GetBytes() + sizeof(Ip6::Nd::RouterAdvMessage);
|
||||||
optionsLength = aPacket.GetLength() - sizeof(RouterAdvMessage);
|
optionsLength = aPacket.GetLength() - sizeof(Ip6::Nd::RouterAdvMessage);
|
||||||
|
|
||||||
option = nullptr;
|
option = nullptr;
|
||||||
while ((option = Option::GetNextOption(option, optionsBegin, optionsLength)) != nullptr)
|
while ((option = Ip6::Nd::Option::GetNextOption(option, optionsBegin, optionsLength)) != nullptr)
|
||||||
{
|
{
|
||||||
switch (option->GetType())
|
switch (option->GetType())
|
||||||
{
|
{
|
||||||
case Option::Type::kPrefixInfo:
|
case Ip6::Nd::Option::Type::kPrefixInfo:
|
||||||
{
|
{
|
||||||
const PrefixInfoOption *pio = static_cast<const PrefixInfoOption *>(option);
|
const Ip6::Nd::PrefixInfoOption *pio = static_cast<const Ip6::Nd::PrefixInfoOption *>(option);
|
||||||
|
|
||||||
if (pio->IsValid())
|
if (pio->IsValid())
|
||||||
{
|
{
|
||||||
|
@ -1146,9 +1140,9 @@ void RoutingManager::HandleRouterAdvertisement(const InfraIf::Icmp6Packet &aPack
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Option::Type::kRouteInfo:
|
case Ip6::Nd::Option::Type::kRouteInfo:
|
||||||
{
|
{
|
||||||
const RouteInfoOption *rio = static_cast<const RouteInfoOption *>(option);
|
const Ip6::Nd::RouteInfoOption *rio = static_cast<const Ip6::Nd::RouteInfoOption *>(option);
|
||||||
|
|
||||||
if (rio->IsValid())
|
if (rio->IsValid())
|
||||||
{
|
{
|
||||||
|
@ -1181,7 +1175,7 @@ exit:
|
||||||
// Adds or deprecates a discovered on-link prefix (new external routes may be added
|
// Adds or deprecates a discovered on-link prefix (new external routes may be added
|
||||||
// to the Thread network). Returns a boolean which indicates whether we need to do
|
// to the Thread network). Returns a boolean which indicates whether we need to do
|
||||||
// routing policy evaluation.
|
// routing policy evaluation.
|
||||||
bool RoutingManager::UpdateDiscoveredOnLinkPrefix(const RouterAdv::PrefixInfoOption &aPio)
|
bool RoutingManager::UpdateDiscoveredOnLinkPrefix(const Ip6::Nd::PrefixInfoOption &aPio)
|
||||||
{
|
{
|
||||||
Ip6::Prefix prefix;
|
Ip6::Prefix prefix;
|
||||||
bool needReevaluate = false;
|
bool needReevaluate = false;
|
||||||
|
@ -1243,7 +1237,7 @@ exit:
|
||||||
|
|
||||||
// Adds or removes a discovered OMR prefix (external route will be added to or removed
|
// Adds or removes a discovered OMR prefix (external route will be added to or removed
|
||||||
// from the Thread network).
|
// from the Thread network).
|
||||||
void RoutingManager::UpdateDiscoveredOmrPrefix(const RouterAdv::RouteInfoOption &aRio)
|
void RoutingManager::UpdateDiscoveredOmrPrefix(const Ip6::Nd::RouteInfoOption &aRio)
|
||||||
{
|
{
|
||||||
Ip6::Prefix prefix;
|
Ip6::Prefix prefix;
|
||||||
ExternalPrefix omrPrefix;
|
ExternalPrefix omrPrefix;
|
||||||
|
@ -1398,9 +1392,9 @@ bool RoutingManager::NetworkDataContainsOmrPrefix(const Ip6::Prefix &aPrefix) co
|
||||||
|
|
||||||
// Update the `mRouterAdvMessage` with given Router Advertisement message.
|
// Update the `mRouterAdvMessage` with given Router Advertisement message.
|
||||||
// Returns a boolean which indicates whether there are changes of `mRouterAdvMessage`.
|
// Returns a boolean which indicates whether there are changes of `mRouterAdvMessage`.
|
||||||
bool RoutingManager::UpdateRouterAdvMessage(const RouterAdv::RouterAdvMessage *aRouterAdvMessage)
|
bool RoutingManager::UpdateRouterAdvMessage(const Ip6::Nd::RouterAdvMessage *aRouterAdvMessage)
|
||||||
{
|
{
|
||||||
RouterAdv::RouterAdvMessage oldRouterAdvMessage;
|
Ip6::Nd::RouterAdvMessage oldRouterAdvMessage;
|
||||||
|
|
||||||
oldRouterAdvMessage = mRouterAdvMessage;
|
oldRouterAdvMessage = mRouterAdvMessage;
|
||||||
|
|
||||||
|
@ -1493,7 +1487,7 @@ void RoutingManager::ResetDiscoveredPrefixStaleTimer(void)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
// ExtneralPrefix
|
// ExtneralPrefix
|
||||||
|
|
||||||
void RoutingManager::ExternalPrefix::InitFrom(const RouterAdv::PrefixInfoOption &aPio)
|
void RoutingManager::ExternalPrefix::InitFrom(const Ip6::Nd::PrefixInfoOption &aPio)
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
aPio.GetPrefix(mPrefix);
|
aPio.GetPrefix(mPrefix);
|
||||||
|
@ -1503,7 +1497,7 @@ void RoutingManager::ExternalPrefix::InitFrom(const RouterAdv::PrefixInfoOption
|
||||||
mLastUpdateTime = TimerMilli::GetNow();
|
mLastUpdateTime = TimerMilli::GetNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoutingManager::ExternalPrefix::InitFrom(const RouterAdv::RouteInfoOption &aRio)
|
void RoutingManager::ExternalPrefix::InitFrom(const Ip6::Nd::RouteInfoOption &aRio)
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
aRio.GetPrefix(mPrefix);
|
aRio.GetPrefix(mPrefix);
|
||||||
|
|
|
@ -50,7 +50,6 @@
|
||||||
#include <openthread/netdata.h>
|
#include <openthread/netdata.h>
|
||||||
|
|
||||||
#include "border_router/infra_if.hpp"
|
#include "border_router/infra_if.hpp"
|
||||||
#include "border_router/router_advertisement.hpp"
|
|
||||||
#include "common/array.hpp"
|
#include "common/array.hpp"
|
||||||
#include "common/error.hpp"
|
#include "common/error.hpp"
|
||||||
#include "common/locator.hpp"
|
#include "common/locator.hpp"
|
||||||
|
@ -58,6 +57,7 @@
|
||||||
#include "common/string.hpp"
|
#include "common/string.hpp"
|
||||||
#include "common/timer.hpp"
|
#include "common/timer.hpp"
|
||||||
#include "net/ip6.hpp"
|
#include "net/ip6.hpp"
|
||||||
|
#include "net/nd6.hpp"
|
||||||
#include "thread/network_data.hpp"
|
#include "thread/network_data.hpp"
|
||||||
|
|
||||||
namespace ot {
|
namespace ot {
|
||||||
|
@ -248,8 +248,8 @@ private:
|
||||||
class ExternalPrefix : private Clearable<ExternalPrefix>, public Unequatable<ExternalPrefix>
|
class ExternalPrefix : private Clearable<ExternalPrefix>, public Unequatable<ExternalPrefix>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void InitFrom(const RouterAdv::PrefixInfoOption &aPio);
|
void InitFrom(const Ip6::Nd::PrefixInfoOption &aPio);
|
||||||
void InitFrom(const RouterAdv::RouteInfoOption &aRio);
|
void InitFrom(const Ip6::Nd::RouteInfoOption &aRio);
|
||||||
bool IsOnLinkPrefix(void) const { return mIsOnLinkPrefix; }
|
bool IsOnLinkPrefix(void) const { return mIsOnLinkPrefix; }
|
||||||
const Ip6::Prefix &GetPrefix(void) const { return mPrefix; }
|
const Ip6::Prefix &GetPrefix(void) const { return mPrefix; }
|
||||||
const TimeMilli & GetLastUpdateTime(void) const { return mLastUpdateTime; }
|
const TimeMilli & GetLastUpdateTime(void) const { return mLastUpdateTime; }
|
||||||
|
@ -346,16 +346,16 @@ private:
|
||||||
void DeprecateOnLinkPrefix(void);
|
void DeprecateOnLinkPrefix(void);
|
||||||
void HandleRouterSolicit(const InfraIf::Icmp6Packet &aPacket, const Ip6::Address &aSrcAddress);
|
void HandleRouterSolicit(const InfraIf::Icmp6Packet &aPacket, const Ip6::Address &aSrcAddress);
|
||||||
void HandleRouterAdvertisement(const InfraIf::Icmp6Packet &aPacket, const Ip6::Address &aSrcAddress);
|
void HandleRouterAdvertisement(const InfraIf::Icmp6Packet &aPacket, const Ip6::Address &aSrcAddress);
|
||||||
bool UpdateDiscoveredOnLinkPrefix(const RouterAdv::PrefixInfoOption &aPio);
|
bool UpdateDiscoveredOnLinkPrefix(const Ip6::Nd::PrefixInfoOption &aPio);
|
||||||
void UpdateDiscoveredOmrPrefix(const RouterAdv::RouteInfoOption &aRio);
|
void UpdateDiscoveredOmrPrefix(const Ip6::Nd::RouteInfoOption &aRio);
|
||||||
void InvalidateDiscoveredPrefixes(void);
|
void InvalidateDiscoveredPrefixes(void);
|
||||||
void InvalidateAllDiscoveredPrefixes(void);
|
void InvalidateAllDiscoveredPrefixes(void);
|
||||||
bool NetworkDataContainsOmrPrefix(const Ip6::Prefix &aPrefix) const;
|
bool NetworkDataContainsOmrPrefix(const Ip6::Prefix &aPrefix) const;
|
||||||
bool UpdateRouterAdvMessage(const RouterAdv::RouterAdvMessage *aRouterAdvMessage);
|
bool UpdateRouterAdvMessage(const Ip6::Nd::RouterAdvMessage *aRouterAdvMessage);
|
||||||
void ResetDiscoveredPrefixStaleTimer(void);
|
void ResetDiscoveredPrefixStaleTimer(void);
|
||||||
|
|
||||||
static bool IsValidBrUlaPrefix(const Ip6::Prefix &aBrUlaPrefix);
|
static bool IsValidBrUlaPrefix(const Ip6::Prefix &aBrUlaPrefix);
|
||||||
static bool IsValidOnLinkPrefix(const RouterAdv::PrefixInfoOption &aPio);
|
static bool IsValidOnLinkPrefix(const Ip6::Nd::PrefixInfoOption &aPio);
|
||||||
static bool IsValidOnLinkPrefix(const Ip6::Prefix &aOnLinkPrefix);
|
static bool IsValidOnLinkPrefix(const Ip6::Prefix &aOnLinkPrefix);
|
||||||
|
|
||||||
// Indicates whether the Routing Manager is running (started).
|
// Indicates whether the Routing Manager is running (started).
|
||||||
|
@ -408,9 +408,9 @@ private:
|
||||||
// The RA header and parameters for the infra interface.
|
// The RA header and parameters for the infra interface.
|
||||||
// This value is initialized with `RouterAdvMessage::SetToDefault`
|
// This value is initialized with `RouterAdvMessage::SetToDefault`
|
||||||
// and updated with RA messages initiated from infra interface.
|
// and updated with RA messages initiated from infra interface.
|
||||||
RouterAdv::RouterAdvMessage mRouterAdvMessage;
|
Ip6::Nd::RouterAdvMessage mRouterAdvMessage;
|
||||||
TimeMilli mTimeRouterAdvMessageLastUpdate;
|
TimeMilli mTimeRouterAdvMessageLastUpdate;
|
||||||
bool mLearntRouterAdvMessageFromHost;
|
bool mLearntRouterAdvMessageFromHost;
|
||||||
|
|
||||||
TimerMilli mDiscoveredPrefixInvalidTimer;
|
TimerMilli mDiscoveredPrefixInvalidTimer;
|
||||||
TimerMilli mDiscoveredPrefixStaleTimer;
|
TimerMilli mDiscoveredPrefixStaleTimer;
|
||||||
|
|
|
@ -28,20 +28,18 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file
|
* @file
|
||||||
* This file includes implementations for ICMPv6 Router Advertisement.
|
* This file includes implementations for IPv6 Neighbor Discovery (ND).
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "border_router/router_advertisement.hpp"
|
#include "nd6.hpp"
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
|
||||||
|
|
||||||
#include "common/as_core_type.hpp"
|
#include "common/as_core_type.hpp"
|
||||||
#include "common/code_utils.hpp"
|
#include "common/code_utils.hpp"
|
||||||
|
|
||||||
namespace ot {
|
namespace ot {
|
||||||
namespace BorderRouter {
|
namespace Ip6 {
|
||||||
namespace RouterAdv {
|
namespace Nd {
|
||||||
|
|
||||||
const Option *Option::GetNextOption(const Option *aCurOption, const uint8_t *aBuffer, uint16_t aBufferLength)
|
const Option *Option::GetNextOption(const Option *aCurOption, const uint8_t *aBuffer, uint16_t aBufferLength)
|
||||||
{
|
{
|
||||||
|
@ -80,20 +78,20 @@ void PrefixInfoOption::Init(void)
|
||||||
OT_UNUSED_VARIABLE(mReserved2);
|
OT_UNUSED_VARIABLE(mReserved2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrefixInfoOption::SetPrefix(const Ip6::Prefix &aPrefix)
|
void PrefixInfoOption::SetPrefix(const Prefix &aPrefix)
|
||||||
{
|
{
|
||||||
mPrefixLength = aPrefix.mLength;
|
mPrefixLength = aPrefix.mLength;
|
||||||
mPrefix = AsCoreType(&aPrefix.mPrefix);
|
mPrefix = AsCoreType(&aPrefix.mPrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrefixInfoOption::GetPrefix(Ip6::Prefix &aPrefix) const
|
void PrefixInfoOption::GetPrefix(Prefix &aPrefix) const
|
||||||
{
|
{
|
||||||
aPrefix.Set(mPrefix.GetBytes(), mPrefixLength);
|
aPrefix.Set(mPrefix.GetBytes(), mPrefixLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PrefixInfoOption::IsValid(void) const
|
bool PrefixInfoOption::IsValid(void) const
|
||||||
{
|
{
|
||||||
return (GetSize() >= sizeof(*this)) && (mPrefixLength <= Ip6::Prefix::kMaxLength) &&
|
return (GetSize() >= sizeof(*this)) && (mPrefixLength <= Prefix::kMaxLength) &&
|
||||||
(GetPreferredLifetime() <= GetValidLifetime());
|
(GetPreferredLifetime() <= GetValidLifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,21 +115,21 @@ RoutePreference RouteInfoOption::GetPreference(void) const
|
||||||
return NetworkData::RoutePreferenceFromValue((mResvdPrf & kPreferenceMask) >> kPreferenceOffset);
|
return NetworkData::RoutePreferenceFromValue((mResvdPrf & kPreferenceMask) >> kPreferenceOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouteInfoOption::SetPrefix(const Ip6::Prefix &aPrefix)
|
void RouteInfoOption::SetPrefix(const Prefix &aPrefix)
|
||||||
{
|
{
|
||||||
SetLength(OptionLengthForPrefix(aPrefix.mLength));
|
SetLength(OptionLengthForPrefix(aPrefix.mLength));
|
||||||
mPrefixLength = aPrefix.mLength;
|
mPrefixLength = aPrefix.mLength;
|
||||||
memcpy(GetPrefixBytes(), aPrefix.GetBytes(), aPrefix.GetBytesSize());
|
memcpy(GetPrefixBytes(), aPrefix.GetBytes(), aPrefix.GetBytesSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouteInfoOption::GetPrefix(Ip6::Prefix &aPrefix) const
|
void RouteInfoOption::GetPrefix(Prefix &aPrefix) const
|
||||||
{
|
{
|
||||||
aPrefix.Set(GetPrefixBytes(), mPrefixLength);
|
aPrefix.Set(GetPrefixBytes(), mPrefixLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RouteInfoOption::IsValid(void) const
|
bool RouteInfoOption::IsValid(void) const
|
||||||
{
|
{
|
||||||
return (GetSize() >= kMinSize) && (mPrefixLength <= Ip6::Prefix::kMaxLength) &&
|
return (GetSize() >= kMinSize) && (mPrefixLength <= Prefix::kMaxLength) &&
|
||||||
(GetLength() >= OptionLengthForPrefix(mPrefixLength)) &&
|
(GetLength() >= OptionLengthForPrefix(mPrefixLength)) &&
|
||||||
NetworkData::IsRoutePreferenceValid(GetPreference());
|
NetworkData::IsRoutePreferenceValid(GetPreference());
|
||||||
}
|
}
|
||||||
|
@ -177,7 +175,7 @@ void RouterAdvMessage::SetToDefault(void)
|
||||||
OT_UNUSED_VARIABLE(mRetransTimer);
|
OT_UNUSED_VARIABLE(mRetransTimer);
|
||||||
|
|
||||||
Clear();
|
Clear();
|
||||||
mType = Ip6::Icmp::Header::kTypeRouterAdvert;
|
mType = Icmp::Header::kTypeRouterAdvert;
|
||||||
}
|
}
|
||||||
|
|
||||||
RoutePreference RouterAdvMessage::GetDefaultRouterPreference(void) const
|
RoutePreference RouterAdvMessage::GetDefaultRouterPreference(void) const
|
||||||
|
@ -197,11 +195,9 @@ void RouterAdvMessage::SetDefaultRouterPreference(RoutePreference aPreference)
|
||||||
RouterSolicitMessage::RouterSolicitMessage(void)
|
RouterSolicitMessage::RouterSolicitMessage(void)
|
||||||
{
|
{
|
||||||
mHeader.Clear();
|
mHeader.Clear();
|
||||||
mHeader.SetType(Ip6::Icmp::Header::kTypeRouterSolicit);
|
mHeader.SetType(Icmp::Header::kTypeRouterSolicit);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace RouterAdv
|
} // namespace Nd
|
||||||
} // namespace BorderRouter
|
} // namespace Ip6
|
||||||
} // namespace ot
|
} // namespace ot
|
||||||
|
|
||||||
#endif // OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
|
|
@ -28,19 +28,17 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file
|
* @file
|
||||||
* This file includes definitions for IPv6 Router Advertisement.
|
* This file includes definitions for IPv6 Neighbor Discovery (ND).
|
||||||
*
|
*
|
||||||
* See RFC 4861: Neighbor Discovery for IP version 6 (https://tools.ietf.org/html/rfc4861).
|
* See RFC 4861 (https://tools.ietf.org/html/rfc4861) and RFC 4191 (https://tools.ietf.org/html/rfc4191).
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef ROUTER_ADVERTISEMENT_HPP_
|
#ifndef ND6_HPP_
|
||||||
#define ROUTER_ADVERTISEMENT_HPP_
|
#define ND6_HPP_
|
||||||
|
|
||||||
#include "openthread-core-config.h"
|
#include "openthread-core-config.h"
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <openthread/netdata.h>
|
#include <openthread/netdata.h>
|
||||||
|
@ -57,8 +55,8 @@ using ot::Encoding::BigEndian::HostSwap16;
|
||||||
using ot::Encoding::BigEndian::HostSwap32;
|
using ot::Encoding::BigEndian::HostSwap32;
|
||||||
|
|
||||||
namespace ot {
|
namespace ot {
|
||||||
namespace BorderRouter {
|
namespace Ip6 {
|
||||||
namespace RouterAdv {
|
namespace Nd {
|
||||||
|
|
||||||
typedef NetworkData::RoutePreference RoutePreference; ///< Route Preference
|
typedef NetworkData::RoutePreference RoutePreference; ///< Route Preference
|
||||||
|
|
||||||
|
@ -256,15 +254,15 @@ public:
|
||||||
* @param[in] aPrefix The prefix contained in this option.
|
* @param[in] aPrefix The prefix contained in this option.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void SetPrefix(const Ip6::Prefix &aPrefix);
|
void SetPrefix(const Prefix &aPrefix);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method gets the prefix in this option.
|
* This method gets the prefix in this option.
|
||||||
*
|
*
|
||||||
* @param[out] aPrefix Reference to an `Ip6::Prefix` to return the prefix.
|
* @param[out] aPrefix Reference to a `Prefix` to return the prefix.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void GetPrefix(Ip6::Prefix &aPrefix) const;
|
void GetPrefix(Prefix &aPrefix) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method indicates whether or not the option is valid.
|
* This method indicates whether or not the option is valid.
|
||||||
|
@ -303,12 +301,12 @@ private:
|
||||||
static constexpr uint8_t kAutoConfigFlagMask = 0x40; // Autonomous address-configuration flag.
|
static constexpr uint8_t kAutoConfigFlagMask = 0x40; // Autonomous address-configuration flag.
|
||||||
static constexpr uint8_t kOnLinkFlagMask = 0x80; // On-link flag.
|
static constexpr uint8_t kOnLinkFlagMask = 0x80; // On-link flag.
|
||||||
|
|
||||||
uint8_t mPrefixLength; // The prefix length in bits.
|
uint8_t mPrefixLength; // The prefix length in bits.
|
||||||
uint8_t mFlags; // The flags field.
|
uint8_t mFlags; // The flags field.
|
||||||
uint32_t mValidLifetime; // The valid lifetime of the prefix.
|
uint32_t mValidLifetime; // The valid lifetime of the prefix.
|
||||||
uint32_t mPreferredLifetime; // The preferred lifetime of the prefix.
|
uint32_t mPreferredLifetime; // The preferred lifetime of the prefix.
|
||||||
uint32_t mReserved2; // The reserved field.
|
uint32_t mReserved2; // The reserved field.
|
||||||
Ip6::Address mPrefix; // The prefix.
|
Address mPrefix; // The prefix.
|
||||||
} OT_TOOL_PACKED_END;
|
} OT_TOOL_PACKED_END;
|
||||||
|
|
||||||
static_assert(sizeof(PrefixInfoOption) == 32, "invalid PrefixInfoOption structure");
|
static_assert(sizeof(PrefixInfoOption) == 32, "invalid PrefixInfoOption structure");
|
||||||
|
@ -370,15 +368,15 @@ public:
|
||||||
* @param[in] aPrefix The prefix contained in this option.
|
* @param[in] aPrefix The prefix contained in this option.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void SetPrefix(const Ip6::Prefix &aPrefix);
|
void SetPrefix(const Prefix &aPrefix);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method gets the prefix in this option.
|
* This method gets the prefix in this option.
|
||||||
*
|
*
|
||||||
* @param[out] aPrefix Reference to an `Ip6::Prefix` to return the prefix.
|
* @param[out] aPrefix Reference to a `Prefix` to return the prefix.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void GetPrefix(Ip6::Prefix &aPrefix) const;
|
void GetPrefix(Prefix &aPrefix) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method tells whether this option is valid.
|
* This method tells whether this option is valid.
|
||||||
|
@ -561,15 +559,13 @@ public:
|
||||||
RouterSolicitMessage(void);
|
RouterSolicitMessage(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ip6::Icmp::Header mHeader; // The common ICMPv6 header.
|
Icmp::Header mHeader; // The common ICMPv6 header.
|
||||||
} OT_TOOL_PACKED_END;
|
} OT_TOOL_PACKED_END;
|
||||||
|
|
||||||
static_assert(sizeof(RouterSolicitMessage) == 8, "invalid RouterSolicitMessage structure");
|
static_assert(sizeof(RouterSolicitMessage) == 8, "invalid RouterSolicitMessage structure");
|
||||||
|
|
||||||
} // namespace RouterAdv
|
} // namespace Nd
|
||||||
} // namespace BorderRouter
|
} // namespace Ip6
|
||||||
} // namespace ot
|
} // namespace ot
|
||||||
|
|
||||||
#endif // OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
#endif // ND6_HPP_
|
||||||
|
|
||||||
#endif // ROUTER_ADVERTISEMENT_HPP_
|
|
Loading…
Reference in New Issue