Skip to content

Commit

Permalink
[routing-manager] include Stub Router flag in emitted RAs by BR (open…
Browse files Browse the repository at this point in the history
…thread#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.
  • Loading branch information
abtink authored Oct 5, 2023
1 parent e64f38a commit 4f6b492
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/core/border_router/routing_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,15 +593,16 @@ 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.
// Factor two is used for RIO to account for entries invalidating
// 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];
Expand All @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions src/core/config/border_routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
19 changes: 19 additions & 0 deletions src/core/net/nd6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,25 @@ Error RouterAdvertMessage::AppendRouteInfoOption(const Prefix &aPrefix,
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

Expand Down
11 changes: 11 additions & 0 deletions src/core/net/nd6.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,17 @@ class RouterAdvertMessage
*/
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.
*
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/test_routing_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit 4f6b492

Please sign in to comment.