Skip to content

Commit

Permalink
[routing-manager] update OMR prefix def-route flag when publishing `:…
Browse files Browse the repository at this point in the history
…:/0` (openthread#9042)

This commit adds a new mechanism to update the default route flag on
the local OMR prefix based on whether or not the BR is publishing
the `::/0` external route prefix.

When `RoutePublisher` (the component that determines which route
prefix to publish) decides to publish/unpublish the default route as
`::/0`, it will inform `LocalOmrPrefix` (the component that manages
when the local OMR prefix is added/removed in Thread Network Data) of
the def-route flag to use.
- If the local OMR prefix is not yet added, the def-route flag will be
  remembered to be used when/if it is added.
- If the local OMR prefix is already added, the entry in Network Data
  is updated to use the new def-route flag.

This change addresses a backward compatibility issue with devices running
1.2 or earlier Thread versions. These devices may not correctly parse or
accept a zero-length `::/0` route prefix in the Network Data. Adding
the default-route flag on the OMR prefix ensures that these devices
can reach the border router that added the OMR prefix.
  • Loading branch information
abtink authored May 12, 2023
1 parent e2cb3c6 commit b200c96
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 52 deletions.
55 changes: 45 additions & 10 deletions src/core/border_router/routing_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,7 @@ bool RoutingManager::OmrPrefix::IsFavoredOver(const NetworkData::OnMeshPrefixCon
RoutingManager::LocalOmrPrefix::LocalOmrPrefix(Instance &aInstance)
: InstanceLocator(aInstance)
, mIsAddedInNetData(false)
, mDefaultRoute(false)
{
}

Expand All @@ -1961,32 +1962,45 @@ void RoutingManager::LocalOmrPrefix::GenerateFrom(const Ip6::Prefix &aBrUlaPrefi

Error RoutingManager::LocalOmrPrefix::AddToNetData(void)
{
Error error = kErrorNone;
NetworkData::OnMeshPrefixConfig config;
Error error = kErrorNone;

VerifyOrExit(!mIsAddedInNetData);
SuccessOrExit(error = AddOrUpdate());
mIsAddedInNetData = true;

exit:
return error;
}

Error RoutingManager::LocalOmrPrefix::AddOrUpdate(void)
{
// Add the local OMR prefix in Thread Network Data or update it
// (e.g., change default route flag) if it is already added.

Error error;
NetworkData::OnMeshPrefixConfig config;

config.Clear();
config.mPrefix = mPrefix;
config.mStable = true;
config.mSlaac = true;
config.mPreferred = true;
config.mOnMesh = true;
config.mDefaultRoute = false;
config.mDefaultRoute = mDefaultRoute;
config.mPreference = GetPreference();

error = Get<NetworkData::Local>().AddOnMeshPrefix(config);

if (error != kErrorNone)
{
LogWarn("Failed to add local OMR prefix %s in Thread Network Data: %s", mPrefix.ToString().AsCString(),
ErrorToString(error));
LogWarn("Failed to %s %s in Thread Network Data: %s", !mIsAddedInNetData ? "add" : "update",
ToString().AsCString(), ErrorToString(error));
ExitNow();
}

mIsAddedInNetData = true;
Get<NetworkData::Notifier>().HandleServerDataUpdated();
LogInfo("Added local OMR prefix %s in Thread Network Data", mPrefix.ToString().AsCString());

LogInfo("%s %s in Thread Network Data", !mIsAddedInNetData ? "Added" : "Updated", ToString().AsCString());

exit:
return error;
Expand All @@ -2002,19 +2016,39 @@ void RoutingManager::LocalOmrPrefix::RemoveFromNetData(void)

if (error != kErrorNone)
{
LogWarn("Failed to remove local OMR prefix %s from Thread Network Data: %s", mPrefix.ToString().AsCString(),
ErrorToString(error));
LogWarn("Failed to remove %s from Thread Network Data: %s", ToString().AsCString(), ErrorToString(error));
ExitNow();
}

mIsAddedInNetData = false;
Get<NetworkData::Notifier>().HandleServerDataUpdated();
LogInfo("Removed local OMR prefix %s from Thread Network Data", mPrefix.ToString().AsCString());
LogInfo("Removed %s from Thread Network Data", ToString().AsCString());

exit:
return;
}

void RoutingManager::LocalOmrPrefix::UpdateDefaultRouteFlag(bool aDefaultRoute)
{
VerifyOrExit(aDefaultRoute != mDefaultRoute);

mDefaultRoute = aDefaultRoute;

VerifyOrExit(mIsAddedInNetData);
IgnoreError(AddOrUpdate());

exit:
return;
}

RoutingManager::LocalOmrPrefix::InfoString RoutingManager::LocalOmrPrefix::ToString(void) const
{
InfoString string;

string.Append("local OMR prefix %s (def-route:%s)", mPrefix.ToString().AsCString(), ToYesNo(mDefaultRoute));
return string;
}

//---------------------------------------------------------------------------------------------------------------------
// OnLinkPrefixManager

Expand Down Expand Up @@ -2618,6 +2652,7 @@ void RoutingManager::RoutePublisher::Evaluate(void)
{
LogInfo("RoutePublisher state: %s -> %s", StateToString(mState), StateToString(newState));
UpdatePublishedRoute(newState);
Get<RoutingManager>().mLocalOmrPrefix.UpdateDefaultRouteFlag(newState == kPublishDefault);
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/core/border_router/routing_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,10 +716,19 @@ class RoutingManager : public InstanceLocator
Error AddToNetData(void);
void RemoveFromNetData(void);
bool IsAddedInNetData(void) const { return mIsAddedInNetData; }
void UpdateDefaultRouteFlag(bool aDefaultRoute);

private:
static constexpr uint16_t kInfoStringSize = 85;

typedef String<kInfoStringSize> InfoString;

Error AddOrUpdate(void);
InfoString ToString(void) const;

Ip6::Prefix mPrefix;
bool mIsAddedInNetData;
bool mDefaultRoute;
};

void HandleOnLinkPrefixManagerTimer(void) { mOnLinkPrefixManager.HandleTimer(); }
Expand Down
Loading

0 comments on commit b200c96

Please sign in to comment.