From 122771269f5b46428c8fb9779d9874b274e19b61 Mon Sep 17 00:00:00 2001 From: Jerry Johns Date: Fri, 8 Jul 2022 15:11:24 -0700 Subject: [PATCH] Fix setting port to 0 in Server (#20489) 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. --- src/app/server/Server.cpp | 9 ++++++++- src/app/server/Server.h | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index b9994f54ff7227..4330446f410698 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -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); diff --git a/src/app/server/Server.h b/src/app/server/Server.h index 7045dcad598381..9ef21431d9772b 100644 --- a/src/app/server/Server.h +++ b/src/app/server/Server.h @@ -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