From 81139be41389e5b4183f18d0b2ccf5ab8a2b3544 Mon Sep 17 00:00:00 2001 From: Yang Sun Date: Mon, 4 Nov 2024 13:31:41 +0800 Subject: [PATCH] [trel] updates for switching trel interface As it's possible to switch network interface for TREL in https://github.com/openthread/openthread/pull/10872, updated trel_dnssd.cpp in 2 places: 1). Initialize() can be called multiple times now, so it should clear the mTrelNetifIndex at the beginning to refresh the index according to the given interface name. 2). HandleMdnsState() may be invoked when TrelDnssd is not initialized, we should still update the mMdnsPublisherReady status, so it's ready to publish a service when TrelDnssd becomes initialized. --- src/trel_dnssd/trel_dnssd.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/trel_dnssd/trel_dnssd.cpp b/src/trel_dnssd/trel_dnssd.cpp index 7cf4adc2e4e..a80a2e7713d 100644 --- a/src/trel_dnssd/trel_dnssd.cpp +++ b/src/trel_dnssd/trel_dnssd.cpp @@ -91,6 +91,9 @@ TrelDnssd::TrelDnssd(Ncp::RcpHost &aHost, Mdns::Publisher &aPublisher) void TrelDnssd::Initialize(std::string aTrelNetif) { mTrelNetif = std::move(aTrelNetif); + // Reset mTrelNetifIndex to 0 so that when this function is called with a different aTrelNetif + // than the current mTrelNetif, CheckTrelNetifReady() will update mTrelNetifIndex accordingly. + mTrelNetifIndex = 0; if (IsInitialized()) { @@ -190,7 +193,6 @@ void TrelDnssd::UnregisterService(void) void TrelDnssd::HandleMdnsState(Mdns::Publisher::State aState) { - VerifyOrExit(IsInitialized()); VerifyOrExit(aState == Mdns::Publisher::State::kReady); otbrLogDebug("mDNS Publisher is Ready"); @@ -202,6 +204,7 @@ void TrelDnssd::HandleMdnsState(Mdns::Publisher::State aState) mRegisterInfo.mInstanceName = ""; } + VerifyOrExit(IsInitialized()); OnBecomeReady(); exit: