aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbtin Keshavarzian <abtink@google.com>2023-10-05 13:58:21 -0700
committerGitHub <noreply@github.com>2023-10-05 13:58:21 -0700
commit4f6b4923aaf556d3d35d453020e1d2cd268d27e2 (patch)
tree2872ff8e33eabe50eba50f974ada9e79e06a4673
parente64f38a816785f3f4d691dcc3fa70c3d88168b0e (diff)
downloadopenthread-4f6b4923aaf556d3d35d453020e1d2cd268d27e2.tar.gz
[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.
-rw-r--r--src/core/border_router/routing_manager.cpp10
-rw-r--r--src/core/config/border_routing.h11
-rw-r--r--src/core/net/nd6.cpp19
-rw-r--r--src/core/net/nd6.hpp11
-rw-r--r--tests/unit/test_routing_manager.cpp20
5 files changed, 69 insertions, 2 deletions
diff --git a/src/core/border_router/routing_manager.cpp b/src/core/border_router/routing_manager.cpp
index 453f49549..97fbad55f 100644
--- a/src/core/border_router/routing_manager.cpp
+++ b/src/core/border_router/routing_manager.cpp
@@ -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.
diff --git a/src/core/config/border_routing.h b/src/core/config/border_routing.h
index a7f57d1fe..4640a081a 100644
--- a/src/core/config/border_routing.h
+++ b/src/core/config/border_routing.h
@@ -127,6 +127,17 @@
#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
*
* Specifies whether to support handling platform generated ND messages.
diff --git a/src/core/net/nd6.cpp b/src/core/net/nd6.cpp
index 3d24b6ad7..e66fb043f 100644
--- a/src/core/net/nd6.cpp
+++ b/src/core/net/nd6.cpp
@@ -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
diff --git a/src/core/net/nd6.hpp b/src/core/net/nd6.hpp
index bc116a450..bbf6a6ea7 100644
--- a/src/core/net/nd6.hpp
+++ b/src/core/net/nd6.hpp
@@ -762,6 +762,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.
*
* @retval TRUE If the RA message contains at least one option.
diff --git a/tests/unit/test_routing_manager.cpp b/tests/unit/test_routing_manager.cpp
index ae1d21e7b..c5cbb5cda 100644
--- a/tests/unit/test_routing_manager.cpp
+++ b/tests/unit/test_routing_manager.cpp
@@ -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");
}