Skip to content

Commit

Permalink
Fix how group multicast addresses are constructed. (#19023)
Browse files Browse the repository at this point in the history
They should be using fabric id, not fabric index.

Fixes #18935
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Aug 1, 2023
1 parent eeede21 commit 2582210
Show file tree
Hide file tree
Showing 5 changed files with 785 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams)
#endif
);

err = mListener.Init(&mTransports);
err = mListener.Init(this);
SuccessOrExit(err);
mGroupsProvider->SetListener(&mListener);

Expand Down Expand Up @@ -309,7 +309,7 @@ void Server::RejoinExistingMulticastGroups()
while (iterator->Next(groupInfo))
{
err = mTransports.MulticastGroupJoinLeave(
Transport::PeerAddress::Multicast(fabric.GetFabricIndex(), groupInfo.group_id), true);
Transport::PeerAddress::Multicast(fabric.GetFabricId(), groupInfo.group_id), true);
if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "Error when trying to join Group %u of fabric index %u : %" CHIP_ERROR_FORMAT,
Expand Down
29 changes: 22 additions & 7 deletions src/app/server/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,30 +270,45 @@ class Server
public:
GroupDataProviderListener() {}

CHIP_ERROR Init(ServerTransportMgr * transports)
CHIP_ERROR Init(Server * server)
{
VerifyOrReturnError(transports != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(server != nullptr, CHIP_ERROR_INVALID_ARGUMENT);

mTransports = transports;
mServer = server;
return CHIP_NO_ERROR;
};

void OnGroupAdded(chip::FabricIndex fabric_index, const Credentials::GroupDataProvider::GroupInfo & new_group) override
{
if (mTransports->MulticastGroupJoinLeave(Transport::PeerAddress::Multicast(fabric_index, new_group.group_id), true) !=
CHIP_NO_ERROR)
FabricInfo * fabric = mServer->GetFabricTable().FindFabricWithIndex(fabric_index);
if (fabric == nullptr)
{
ChipLogError(AppServer, "Group added to nonexistent fabric?");
return;
}

if (mServer->GetTransportManager().MulticastGroupJoinLeave(
Transport::PeerAddress::Multicast(fabric->GetFabricId(), new_group.group_id), true) != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "Unable to listen to group");
}
};

void OnGroupRemoved(chip::FabricIndex fabric_index, const Credentials::GroupDataProvider::GroupInfo & old_group) override
{
mTransports->MulticastGroupJoinLeave(Transport::PeerAddress::Multicast(fabric_index, old_group.group_id), false);
FabricInfo * fabric = mServer->GetFabricTable().FindFabricWithIndex(fabric_index);
if (fabric == nullptr)
{
ChipLogError(AppServer, "Group added to nonexistent fabric?");
return;
}

mServer->GetTransportManager().MulticastGroupJoinLeave(
Transport::PeerAddress::Multicast(fabric->GetFabricId(), old_group.group_id), false);
};

private:
ServerTransportMgr * mTransports;
Server * mServer;
};

class ServerFabricDelegate final : public chip::FabricTable::Delegate
Expand Down
Loading

0 comments on commit 2582210

Please sign in to comment.