avahi
avahi copied to clipboard
avahi-client does not remove all services when specifying interfaces
This is more than likely a problem between the keyboard and chair... My application needs the ability to advertise on specific network interfaces, and thankfully avahi-client
supports that.
Assume there's error checking in there:
...
// Create an entry group
auto grp_ptr = std::shared_ptr<AvahiEntryGroup>{
avahi_entry_group_new(client_.get(), group_callback, this),
[](auto&& g) {
avahi_entry_group_free(g);
}};
...
// Create a service for each required interface
for (auto if_it = interface_indices.begin(); if_it != interface_indices.end(); ++if_it) {
auto ret = avahi_entry_group_add_service_strlst(grp_ptr.get(),
*if_it,
AVAHI_PROTO_UNSPEC,
static_cast<AvahiPublishFlags>(0),
"mdns_test_publish_service_specify_multiple_NICs",
"_http._tcp",
nullptr,
nullptr,
port,
txt_raw.get());
}
...
// And commit
avahi_entry_group_commit(grp_ptr.get());
And this works great, I can see the expected result using avahi-browse _http._tcp
:
+ docker0 IPv4 mdns_test_publish_service_specify_multiple_NICs Web Site local
+ virbr0 IPv4 mdns_test_publish_service_specify_multiple_NICs Web Site local
+ enp0s10 IPv6 mdns_test_publish_service_specify_multiple_NICs Web Site local
+ enp0s10 IPv4 mdns_test_publish_service_specify_multiple_NICs Web Site local
+ enp0s9 IPv6 mdns_test_publish_service_specify_multiple_NICs Web Site local
+ enp0s9 IPv4 mdns_test_publish_service_specify_multiple_NICs Web Site local
+ enp0s8 IPv6 mdns_test_publish_service_specify_multiple_NICs Web Site local
+ enp0s8 IPv4 mdns_test_publish_service_specify_multiple_NICs Web Site local
+ enp0s3 IPv6 mdns_test_publish_service_specify_multiple_NICs Web Site local
+ enp0s3 IPv4 mdns_test_publish_service_specify_multiple_NICs Web Site local
Until I come to remove the service (which I do just by destroying grp_ptr
, i.e. calling avahi_entry_group_free(..)
):
- enp0s3 IPv6 mdns_test_publish_service_specify_multiple_NICs Web Site local
- enp0s3 IPv4 mdns_test_publish_service_specify_multiple_NICs Web Site local
Only the first created service is actually removed, the rest stay as stale entries. Eventually they fail to resolve with Timeout reached
errors.
What am I doing wrong?
It's a bug. When avahi
looks for duplicate entries is_duplicate_entry
doesn't take interfaces and protocols into account:
https://github.com/avahi/avahi/blob/42939e1e8a3f9a0c4ef9b81b006027def293b39e/avahi-core/announce.c#L381-L390
It works with AVAHI_IF_UNSPEC/AVAHI_PROTO_UNSPEC
and prevents avahi from sending goodbye packets if there are other active entry groups publishing the same entries with AVAHI_IF_UNSPEC/AVAHI_PROTO_UNSPEC
but entries explicitly published on different interfaces aren't duplicates of course.