[Linux] DnssdImpl: rework avahi implementation (#26397)
* InetInterface: add IsLoopback() to InterfaceIterator and InterfaceAddressIterator
Required for improving dns-sd avahi based implementation
* [Linux] DnssdImpl: rework avahi implementation
This commit fixes two problems with the previous avahi based dns-sd implementation:
- Publishing more than one service at the same time did not work.
This needs to be possible e.g. when a node is commissioned into multiple fabrics.
The previous implementation falsely assumed that additional services can be added
to already committed (=published) AvahiEntryGroup, which is not the case.
An AvahiEntryGroup can only publish multiple services ALL AT ONCE.
The new implementation creates a new AvahiEntryGroup per service, on demand.
- The previous implementation took ownership of the platform-global default hostname,
(by overwriting it). This is not a good idea because the default hostname is usually
of relevance for other non-matter services on a given Linux platform.
The new implementation establishes the matter-mandated MAC-derived hostname separately
and explicitly adds interface addresses.
* DnssdImpl.cpp: avoid shadowing local vars to prevent warning/error
* DnssdImpl.cpp: make work without INET_CONFIG_ENABLE_IPV4
* DnssdImpl.cpp: fix missing error variable assignment in SuccessOrExit()
(found by code-lints)
diff --git a/src/platform/Linux/DnssdImpl.h b/src/platform/Linux/DnssdImpl.h
index e711180..9bad9e8 100644
--- a/src/platform/Linux/DnssdImpl.h
+++ b/src/platform/Linux/DnssdImpl.h
@@ -23,7 +23,6 @@
#include <chrono>
#include <map>
#include <memory>
-#include <set>
#include <string>
#include <vector>
@@ -142,7 +141,7 @@
uint8_t mAttempts = 0;
};
- MdnsAvahi() : mClient(nullptr), mGroup(nullptr) {}
+ MdnsAvahi() : mClient(nullptr) {}
static MdnsAvahi sInstance;
static void HandleClientState(AvahiClient * client, AvahiClientState state, void * context);
@@ -163,9 +162,8 @@
DnssdAsyncReturnCallback mErrorCallback;
void * mAsyncReturnContext;
- std::set<std::string> mPublishedServices;
AvahiClient * mClient;
- AvahiEntryGroup * mGroup;
+ std::map<std::string, AvahiEntryGroup *> mPublishedGroups;
Poller mPoller;
};