mirror of
https://github.com/espressif/openthread.git
synced 2026-09-09 02:30:11 +00:00
[border-router] move configuration check from api to inner class (#5884)
This commit moves the border router configuration check into NetworkData::Local.
This commit is contained in:
@@ -53,24 +53,17 @@ otError otBorderRouterGetNetData(otInstance *aInstance, bool aStable, uint8_t *a
|
||||
|
||||
otError otBorderRouterAddOnMeshPrefix(otInstance *aInstance, const otBorderRouterConfig *aConfig)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otError error;
|
||||
Instance & instance = *static_cast<Instance *>(aInstance);
|
||||
const NetworkData::OnMeshPrefixConfig *config = static_cast<const NetworkData::OnMeshPrefixConfig *>(aConfig);
|
||||
|
||||
OT_ASSERT(aConfig != nullptr);
|
||||
// Add Prefix validation check:
|
||||
// Thread 1.1 Specification 5.13.2 says
|
||||
// "A valid prefix MUST NOT allow both DHCPv6 and SLAAC for address configuration"
|
||||
VerifyOrExit(!aConfig->mDhcp || !aConfig->mSlaac, error = OT_ERROR_INVALID_ARGS);
|
||||
// RFC 4944 Section 6 says:
|
||||
// An IPv6 address prefix used for stateless autoconfiguration [RFC4862]
|
||||
// of an IEEE 802.15.4 interface MUST have a length of 64 bits.
|
||||
VerifyOrExit(!aConfig->mSlaac || aConfig->mPrefix.mLength == OT_IP6_PREFIX_BITSIZE, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
error = instance.Get<NetworkData::Local>().AddOnMeshPrefix(*config);
|
||||
SuccessOrExit(error = instance.Get<NetworkData::Local>().AddOnMeshPrefix(*config));
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
// Only try to configure Domain Prefix after the parameter is vaidated via above `AddOnMeshPrefix()`.
|
||||
if (error == OT_ERROR_NONE && aConfig->mDp)
|
||||
// Only try to configure Domain Prefix after the parameter is validated via above `AddOnMeshPrefix()`.
|
||||
if (aConfig->mDp)
|
||||
{
|
||||
// Restore local server data
|
||||
IgnoreError(instance.Get<NetworkData::Local>().RemoveOnMeshPrefix(config->GetPrefix()));
|
||||
|
||||
@@ -56,8 +56,19 @@ Local::Local(Instance &aInstance)
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE
|
||||
otError Local::AddOnMeshPrefix(const OnMeshPrefixConfig &aConfig)
|
||||
{
|
||||
otError error;
|
||||
uint16_t flags = 0;
|
||||
|
||||
// Add Prefix validation check:
|
||||
// Thread 1.1 Specification 5.13.2 says
|
||||
// "A valid prefix MUST NOT allow both DHCPv6 and SLAAC for address configuration"
|
||||
VerifyOrExit(!aConfig.mDhcp || !aConfig.mSlaac, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
// RFC 4944 Section 6 says:
|
||||
// An IPv6 address prefix used for stateless autoconfiguration [RFC4862]
|
||||
// of an IEEE 802.15.4 interface MUST have a length of 64 bits.
|
||||
VerifyOrExit(!aConfig.mSlaac || aConfig.mPrefix.mLength == OT_IP6_PREFIX_BITSIZE, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
if (aConfig.mPreferred)
|
||||
{
|
||||
flags |= BorderRouterEntry::kPreferredFlag;
|
||||
@@ -100,8 +111,11 @@ otError Local::AddOnMeshPrefix(const OnMeshPrefixConfig &aConfig)
|
||||
}
|
||||
#endif
|
||||
|
||||
return AddPrefix(aConfig.GetPrefix(), NetworkDataTlv::kTypeBorderRouter, aConfig.mPreference, flags,
|
||||
aConfig.mStable);
|
||||
error =
|
||||
AddPrefix(aConfig.GetPrefix(), NetworkDataTlv::kTypeBorderRouter, aConfig.mPreference, flags, aConfig.mStable);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Local::RemoveOnMeshPrefix(const Ip6::Prefix &aPrefix)
|
||||
|
||||
Reference in New Issue
Block a user