Skip to content

Commit

Permalink
Fix setting port to 0 in Server (#20489)
Browse files Browse the repository at this point in the history
When setting ServerInitParams::operationalServicePort to 0 before
calling Server::Init(), commissioning would fail due to a failure to
discover the commissionee. This was because DNS-SD was advertising port
0 instead of the actual bound port.
  • Loading branch information
mrjerryjohns authored and pull[bot] committed Jul 14, 2022
1 parent df66eae commit f23dbc3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,14 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams)
SuccessOrExit(err);
#endif

app::DnssdServer::Instance().SetSecuredPort(mOperationalServicePort);
//
// We need to advertise the port that we're listening to for unsolicited messages over UDP. However, we have both a IPv4
// and IPv6 endpoint to pick from. Given that the listen port passed in may be set to 0 (which then has the kernel select
// a valid port at bind time), that will result in two possible ports being provided back from the resultant endpoint
// initializations. Since IPv6 is POR for Matter, let's go ahead and pick that port.
//
app::DnssdServer::Instance().SetSecuredPort(mTransports.GetTransport().GetImplAtIndex<0>().GetBoundPort());

app::DnssdServer::Instance().SetUnsecuredPort(mUserDirectedCommissioningPort);
app::DnssdServer::Instance().SetInterfaceId(mInterfaceId);

Expand Down
4 changes: 4 additions & 0 deletions src/app/server/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ namespace chip {

constexpr size_t kMaxBlePendingPackets = 1;

//
// NOTE: Please do not alter the order of template specialization here as the logic
// in the Server impl depends on this.
//
using ServerTransportMgr = chip::TransportMgr<chip::Transport::UDP
#if INET_CONFIG_ENABLE_IPV4
,
Expand Down

0 comments on commit f23dbc3

Please sign in to comment.