mirror of
https://github.com/espressif/openthread.git
synced 2026-08-18 16:39:52 +00:00
[bbr] validate BBR configuration (#5221)
This commit makes sure BBR configuration is valid according to Thread Spec 5.21.3.3.
This commit is contained in:
@@ -115,13 +115,16 @@ void otBackboneRouterGetConfig(otInstance *aInstance, otBackboneRouterConfig *aC
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
* @param[in] aConfig A pointer to the Backbone Router configuration to take effect.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully updated configuration.
|
||||
* @retval OT_ERROR_INVALID_ARGS The configuration in @p aConfig is invalid.
|
||||
*
|
||||
* @sa otBackboneRouterSetEnabled
|
||||
* @sa otBackboneRouterGetState
|
||||
* @sa otBackboneRouterGetConfig
|
||||
* @sa otBackboneRouterRegister
|
||||
*
|
||||
*/
|
||||
void otBackboneRouterSetConfig(otInstance *aInstance, const otBackboneRouterConfig *aConfig);
|
||||
otError otBackboneRouterSetConfig(otInstance *aInstance, const otBackboneRouterConfig *aConfig);
|
||||
|
||||
/**
|
||||
* This function explicitly registers local Backbone Router configuration.
|
||||
|
||||
@@ -53,7 +53,7 @@ extern "C" {
|
||||
* @note This number versions both OpenThread platform and user APIs.
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_API_VERSION (13)
|
||||
#define OPENTHREAD_API_VERSION (14)
|
||||
|
||||
/**
|
||||
* @addtogroup api-instance
|
||||
|
||||
+1
-1
@@ -582,7 +582,7 @@ otError Interpreter::ProcessBackboneRouterLocal(uint8_t aArgsLength, char *aArgs
|
||||
}
|
||||
}
|
||||
|
||||
otBackboneRouterSetConfig(mInstance, &config);
|
||||
SuccessOrExit(error = otBackboneRouterSetConfig(mInstance, &config));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -64,13 +64,13 @@ void otBackboneRouterGetConfig(otInstance *aInstance, otBackboneRouterConfig *aC
|
||||
instance.Get<BackboneRouter::Local>().GetConfig(*aConfig);
|
||||
}
|
||||
|
||||
void otBackboneRouterSetConfig(otInstance *aInstance, const otBackboneRouterConfig *aConfig)
|
||||
otError otBackboneRouterSetConfig(otInstance *aInstance, const otBackboneRouterConfig *aConfig)
|
||||
{
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
|
||||
OT_ASSERT(aConfig != nullptr);
|
||||
|
||||
instance.Get<BackboneRouter::Local>().SetConfig(*aConfig);
|
||||
return instance.Get<BackboneRouter::Local>().SetConfig(*aConfig);
|
||||
}
|
||||
|
||||
otError otBackboneRouterRegister(otInstance *aInstance)
|
||||
|
||||
@@ -137,9 +137,18 @@ void Local::GetConfig(BackboneRouterConfig &aConfig) const
|
||||
aConfig.mMlrTimeout = mMlrTimeout;
|
||||
}
|
||||
|
||||
void Local::SetConfig(const BackboneRouterConfig &aConfig)
|
||||
otError Local::SetConfig(const BackboneRouterConfig &aConfig)
|
||||
{
|
||||
bool update = false;
|
||||
otError error = OT_ERROR_NONE;
|
||||
bool update = false;
|
||||
|
||||
VerifyOrExit(aConfig.mMlrTimeout >= Mle::kMlrTimeoutMin, error = OT_ERROR_INVALID_ARGS);
|
||||
// Validate configuration according to Thread 1.2.1 Specification 5.21.3.3:
|
||||
// "The Reregistration Delay in seconds MUST be lower than (0.5 * MLR Timeout). It MUST be at least 1."
|
||||
VerifyOrExit(aConfig.mReregistrationDelay >= 1, error = OT_ERROR_INVALID_ARGS);
|
||||
static_assert(sizeof(aConfig.mReregistrationDelay) < sizeof(aConfig.mMlrTimeout),
|
||||
"the calculation below might overflow");
|
||||
VerifyOrExit(aConfig.mReregistrationDelay * 2 < aConfig.mMlrTimeout, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
if (aConfig.mReregistrationDelay != mReregistrationDelay)
|
||||
{
|
||||
@@ -169,7 +178,9 @@ void Local::SetConfig(const BackboneRouterConfig &aConfig)
|
||||
}
|
||||
}
|
||||
|
||||
LogBackboneRouterService("Set", OT_ERROR_NONE);
|
||||
exit:
|
||||
LogBackboneRouterService("Set", error);
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Local::AddService(bool aForce)
|
||||
|
||||
@@ -104,8 +104,11 @@ public:
|
||||
*
|
||||
* @param[in] aConfig The configuration to set.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully updated configuration.
|
||||
* @retval OT_ERROR_INVALID_ARGS The configuration in @p aConfig is invalid.
|
||||
*
|
||||
*/
|
||||
void SetConfig(const BackboneRouterConfig &aConfig);
|
||||
otError SetConfig(const BackboneRouterConfig &aConfig);
|
||||
|
||||
/**
|
||||
* This method registers Backbone Router Dataset to Leader.
|
||||
|
||||
@@ -258,9 +258,13 @@ enum
|
||||
{
|
||||
kRegistrationDelayDefault = 1200, //< In seconds.
|
||||
kMlrTimeoutDefault = 3600, //< In seconds.
|
||||
kMlrTimeoutMin = 300, //< In seconds.
|
||||
kBackboneRouterRegistrationJitter = 5, //< In seconds.
|
||||
};
|
||||
|
||||
static_assert(kMlrTimeoutDefault >= kMlrTimeoutMin,
|
||||
"kMlrTimeoutDefault must be larger than or equal to kMlrTimeoutMin");
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user