[routing-manager] include Stub Router flag in emitted RAs by BR (#9486)

This commit updates `RoutingManager` to include the Flags Extension
Option with Stub Router flag in its emitted Router Advertisement
messages.

Config `STUB_ROUTER_FLAG_IN_EMITTED_RA_ENABLE` can be used to enable
or disable this behavior which is enabled by default.
This commit is contained in:
Abtin Keshavarzian
2023-10-05 13:58:21 -07:00
committed by GitHub
parent e64f38a816
commit 4f6b4923aa
5 changed files with 69 additions and 2 deletions
+8 -2
View File
@@ -593,6 +593,7 @@ void RoutingManager::SendRouterAdvertisement(RouterAdvTxMode aRaTxMode)
// RA message max length is derived to accommodate:
//
// - The RA header.
// - One RA Flags Extensions Option (with stub router flag).
// - One PIO for current local on-link prefix.
// - At most `kMaxOldPrefixes` for old deprecating on-link prefixes.
// - At most twice `kMaxOnMeshPrefixes` RIO for on-mesh prefixes.
@@ -600,8 +601,8 @@ void RoutingManager::SendRouterAdvertisement(RouterAdvTxMode aRaTxMode)
// previous prefixes while adding new ones.
static constexpr uint16_t kMaxRaLength =
sizeof(Ip6::Nd::RouterAdvertMessage::Header) + sizeof(Ip6::Nd::PrefixInfoOption) +
sizeof(Ip6::Nd::PrefixInfoOption) * OnLinkPrefixManager::kMaxOldPrefixes +
sizeof(Ip6::Nd::RouterAdvertMessage::Header) + sizeof(Ip6::Nd::RaFlagsExtOption) +
sizeof(Ip6::Nd::PrefixInfoOption) + sizeof(Ip6::Nd::PrefixInfoOption) * OnLinkPrefixManager::kMaxOldPrefixes +
2 * kMaxOnMeshPrefixes * (sizeof(Ip6::Nd::RouteInfoOption) + sizeof(Ip6::Prefix));
uint8_t buffer[kMaxRaLength];
@@ -611,6 +612,11 @@ void RoutingManager::SendRouterAdvertisement(RouterAdvTxMode aRaTxMode)
LogInfo("Preparing RA");
#if OPENTHREAD_CONFIG_BORDER_ROUTING_STUB_ROUTER_FLAG_IN_EMITTED_RA_ENABLE
SuccessOrAssert(raMsg.AppendFlagsExtensionOption(/* aStubRouterFlag */ true));
LogInfo("- FlagsExt - StubRouter:1");
#endif
// Append PIO for local on-link prefix if is either being
// advertised or deprecated and for old prefix if is being
// deprecated.
+11
View File
@@ -126,6 +126,17 @@
#define OPENTHREAD_CONFIG_BORDER_ROUTING_ROUTER_ACTIVE_CHECK_TIMEOUT (60 * 1000) // (in msec).
#endif
/**
* @def OPENTHREAD_CONFIG_BORDER_ROUTING_STUB_ROUTER_FLAG_IN_EMITTED_RA_ENABLE
*
* Define to 1 so for the routing manager to include the Flags Extension Option with Stub Router flag in the emitted
* Router Advertisement messages from this Border Router.
*
*/
#ifndef OPENTHREAD_CONFIG_BORDER_ROUTING_STUB_ROUTER_FLAG_IN_EMITTED_RA_ENABLE
#define OPENTHREAD_CONFIG_BORDER_ROUTING_STUB_ROUTER_FLAG_IN_EMITTED_RA_ENABLE 1
#endif
/**
* @def OPENTHREAD_CONFIG_BORDER_ROUTING_DHCP6_PD_ENABLE
*
+19
View File
@@ -269,6 +269,25 @@ exit:
return error;
}
Error RouterAdvertMessage::AppendFlagsExtensionOption(bool aStubRouterFlag)
{
Error error = kErrorNone;
RaFlagsExtOption *flagsOption;
flagsOption = static_cast<RaFlagsExtOption *>(AppendOption(sizeof(RaFlagsExtOption)));
VerifyOrExit(flagsOption != nullptr, error = kErrorNoBufs);
flagsOption->Init();
if (aStubRouterFlag)
{
flagsOption->SetStubRouterFlag();
}
exit:
return error;
}
//----------------------------------------------------------------------------------------------------------------------
// RouterSolicitMessage
+11
View File
@@ -761,6 +761,17 @@ public:
*/
Error AppendRouteInfoOption(const Prefix &aPrefix, uint32_t aRouteLifetime, RoutePreference aPreference);
/**
* Appends a Flags Extension Option to the RA message.
*
* @param[in] aStubRouterFlag The stub router flag.
*
* @retval kErrorNone Option is appended successfully.
* @retval kErrorNoBufs No more space in the buffer to append the option.
*
*/
Error AppendFlagsExtensionOption(bool aStubRouterFlag);
/**
* Indicates whether or not the RA message contains any options.
*
+20
View File
@@ -449,6 +449,17 @@ void ValidateRouterAdvert(const Icmp6Packet &aPacket)
break;
}
#if OPENTHREAD_CONFIG_BORDER_ROUTING_STUB_ROUTER_FLAG_IN_EMITTED_RA_ENABLE
case Ip6::Nd::Option::kTypeRaFlagsExtension:
{
const Ip6::Nd::RaFlagsExtOption &flagsOption = static_cast<const Ip6::Nd::RaFlagsExtOption &>(option);
VerifyOrQuit(flagsOption.IsValid());
VerifyOrQuit(flagsOption.IsStubRouterFlagSet());
break;
}
#endif
default:
VerifyOrQuit(false, "Unexpected option type in RA msg");
}
@@ -545,6 +556,15 @@ void LogRouterAdvert(const Icmp6Packet &aPacket)
break;
}
case Ip6::Nd::Option::kTypeRaFlagsExtension:
{
const Ip6::Nd::RaFlagsExtOption &flagsOption = static_cast<const Ip6::Nd::RaFlagsExtOption &>(option);
VerifyOrQuit(flagsOption.IsValid());
Log(" FlagsExt - StubRouter:%u", flagsOption.IsStubRouterFlagSet());
break;
}
default:
VerifyOrQuit(false, "Bad option type in RA msg");
}