Skip to content

Commit 73a25ad

Browse files
authored
Fix DNS-SD TCP advertisement to use a bitmap for Client and Server. (#34289)
When TCP is enabled, a node, currently, advertises as both a Client and Server.
1 parent 6adf0c9 commit 73a25ad

File tree

6 files changed

+24
-11
lines changed

6 files changed

+24
-11
lines changed

src/app/server/Dnssd.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ CHIP_ERROR DnssdServer::AdvertiseOperational()
213213
AddICDKeyToAdvertisement(advertiseParameters);
214214
#endif
215215

216+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
217+
advertiseParameters.SetTCPSupportModes(chip::Dnssd::TCPModeAdvertise::kTCPClientServer);
218+
#endif
216219
auto & mdnsAdvertiser = chip::Dnssd::ServiceAdvertiser::Instance();
217220

218221
ChipLogProgress(Discovery, "Advertise operational node " ChipLogFormatX64 "-" ChipLogFormatX64,

src/app/server/Dnssd.h

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class DLL_EXPORT DnssdServer : public ICDStateObserver
9696

9797
void SetICDManager(ICDManager * manager) { mICDManager = manager; };
9898
#endif
99+
99100
/// Start operational advertising
100101
CHIP_ERROR AdvertiseOperational();
101102

src/lib/dnssd/Advertiser.h

+12-5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ enum class ICDModeAdvertise : uint8_t
5555
kLIT, // The ICD is currently operating as a LIT. ICD=1 in DNS-SD key/value pairs.
5656
};
5757

58+
enum class TCPModeAdvertise : uint16_t
59+
{
60+
kNone = 0, // The device does not support TCP.
61+
kTCPClient = 1 << 1, // The device supports the TCP client.
62+
kTCPServer = 1 << 2, // The device supports the TCP server.
63+
kTCPClientServer = (kTCPClient | kTCPServer), // The device supports both the TCP client and server.
64+
};
65+
5866
template <class Derived>
5967
class BaseAdvertisingParams
6068
{
@@ -102,13 +110,12 @@ class BaseAdvertisingParams
102110
}
103111
const std::optional<ReliableMessageProtocolConfig> & GetLocalMRPConfig() const { return mLocalMRPConfig; }
104112

105-
// NOTE: The SetTcpSupported API is deprecated and not compliant with 1.3. T flag should not be set.
106-
Derived & SetTcpSupported(std::optional<bool> tcpSupported)
113+
Derived & SetTCPSupportModes(TCPModeAdvertise tcpSupportModes)
107114
{
108-
mTcpSupported = tcpSupported;
115+
mTcpSupportModes = tcpSupportModes;
109116
return *reinterpret_cast<Derived *>(this);
110117
}
111-
std::optional<bool> GetTcpSupported() const { return mTcpSupported; }
118+
TCPModeAdvertise GetTCPSupportModes() const { return mTcpSupportModes; }
112119

113120
Derived & SetICDModeToAdvertise(ICDModeAdvertise operatingMode)
114121
{
@@ -124,7 +131,7 @@ class BaseAdvertisingParams
124131
uint8_t mMacStorage[kMaxMacSize] = {};
125132
size_t mMacLength = 0;
126133
std::optional<ReliableMessageProtocolConfig> mLocalMRPConfig;
127-
std::optional<bool> mTcpSupported;
134+
TCPModeAdvertise mTcpSupportModes = TCPModeAdvertise::kNone;
128135
ICDModeAdvertise mICDModeAdvertise = ICDModeAdvertise::kNone;
129136
};
130137

src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,10 @@ class AdvertiserMinMdns : public ServiceAdvertiser,
278278
}
279279
}
280280

281-
if (const auto & tcpSupported = params.GetTcpSupported(); tcpSupported.has_value())
281+
if (params.GetTCPSupportModes() != TCPModeAdvertise::kNone)
282282
{
283-
size_t writtenCharactersNumber =
284-
static_cast<size_t>(snprintf(storage.tcpSupportedBuf, sizeof(storage.tcpSupportedBuf), "T=%d", *tcpSupported));
283+
size_t writtenCharactersNumber = static_cast<size_t>(snprintf(storage.tcpSupportedBuf, sizeof(storage.tcpSupportedBuf),
284+
"T=%d", static_cast<int>(params.GetTCPSupportModes())));
285285
VerifyOrReturnError((writtenCharactersNumber > 0) && (writtenCharactersNumber < sizeof(storage.tcpSupportedBuf)),
286286
CHIP_ERROR_INVALID_STRING_LENGTH);
287287
txtFields[numTxtFields++] = storage.tcpSupportedBuf;

src/lib/dnssd/Discovery_ImplPlatform.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ CHIP_ERROR CopyTxtRecord(TxtFieldKey key, char * buffer, size_t bufferLen, const
240240
switch (key)
241241
{
242242
case TxtFieldKey::kTcpSupported:
243-
return CopyTextRecordValue(buffer, bufferLen, params.GetTcpSupported());
243+
VerifyOrReturnError(params.GetTCPSupportModes() != TCPModeAdvertise::kNone, CHIP_ERROR_UNINITIALIZED);
244+
return CopyTextRecordValue(buffer, bufferLen, to_underlying(params.GetTCPSupportModes()));
244245
case TxtFieldKey::kSessionIdleInterval:
245246
#if CHIP_CONFIG_ENABLE_ICD_SERVER
246247
// A ICD operating as a LIT should not advertise its slow polling interval

src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ OperationalAdvertisingParameters operationalParams1 =
8181
.SetPort(CHIP_PORT)
8282
.EnableIpV4(true)
8383
.SetLocalMRPConfig(std::make_optional<ReliableMessageProtocolConfig>(
84-
32_ms32, 30_ms32)); // Match SII, SAI. SAT not provided so it uses default 4000ms
84+
32_ms32, 30_ms32)) // Match SII, SAI. SAT not provided so it uses default 4000ms
85+
.SetTCPSupportModes(chip::Dnssd::TCPModeAdvertise::kTCPClientServer);
8586
OperationalAdvertisingParameters operationalParams2 =
8687
OperationalAdvertisingParameters().SetPeerId(kPeerId2).SetMac(ByteSpan(kMac)).SetPort(CHIP_PORT).EnableIpV4(true);
8788
OperationalAdvertisingParameters operationalParams3 =
@@ -92,7 +93,7 @@ OperationalAdvertisingParameters operationalParams5 =
9293
OperationalAdvertisingParameters().SetPeerId(kPeerId5).SetMac(ByteSpan(kMac)).SetPort(CHIP_PORT).EnableIpV4(true);
9394
OperationalAdvertisingParameters operationalParams6 =
9495
OperationalAdvertisingParameters().SetPeerId(kPeerId6).SetMac(ByteSpan(kMac)).SetPort(CHIP_PORT).EnableIpV4(true);
95-
const QNamePart txtOperational1Parts[] = { "SII=32", "SAI=30", "SAT=4000" };
96+
const QNamePart txtOperational1Parts[] = { "SII=32", "SAI=30", "SAT=4000", "T=6" };
9697
PtrResourceRecord ptrOperationalService = PtrResourceRecord(kDnsSdQueryName, kMatterOperationalQueryName);
9798
PtrResourceRecord ptrOperational1 = PtrResourceRecord(kMatterOperationalQueryName, kInstanceName1);
9899
SrvResourceRecord srvOperational1 = SrvResourceRecord(kInstanceName1, kHostnameName, CHIP_PORT);

0 commit comments

Comments
 (0)