Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Linux] DnssdImpl: rework avahi implementation #26397

Merged
merged 5 commits into from
Jul 15, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
DnssdImpl.cpp: avoid shadowing local vars to prevent warning/error
  • Loading branch information
plan44 committed Jul 15, 2023
commit 1f577415202ddb4af6041d7e9fb4ff9ad7b63e2d
22 changes: 11 additions & 11 deletions src/platform/Linux/DnssdImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,17 +441,17 @@ CHIP_ERROR MdnsAvahi::PublishService(const DnssdService & service, DnssdPublishC
keyBuilder << service.mName << "." << type << service.mPort << "." << interface;
key = keyBuilder.str();
ChipLogProgress(DeviceLayer, "PublishService %s", key.c_str());
auto it = mPublishedGroups.find(key);
if (it != mPublishedGroups.end())
auto publishedgroups_it = mPublishedGroups.find(key);
if (publishedgroups_it != mPublishedGroups.end())
{
// same service was already published, we need to de-publish it first
int avahiRet = avahi_entry_group_free(it->second);
int avahiRet = avahi_entry_group_free(publishedgroups_it->second);
if (avahiRet != AVAHI_OK)
{
ChipLogError(DeviceLayer, "Cannot remove avahi group: %s", avahi_strerror(avahiRet));
ExitNow(error = CHIP_ERROR_INTERNAL);
}
mPublishedGroups.erase(it);
mPublishedGroups.erase(publishedgroups_it);
}

// create fresh group
Expand All @@ -474,34 +474,34 @@ CHIP_ERROR MdnsAvahi::PublishService(const DnssdService & service, DnssdPublishC
ChipLogDetail(DeviceLayer, "Using addresses from interface id=%d name=%s", service.mInterface.GetPlatformInterface(), b);
matterHostname = std::string(service.mHostName) + ".local";
// find addresses to publish
for (chip::Inet::InterfaceAddressIterator it; it.HasCurrent(); it.Next())
for (chip::Inet::InterfaceAddressIterator addr_it; addr_it.HasCurrent(); addr_it.Next())
{
// only specific interface?
if (service.mInterface.IsPresent() && it.GetInterfaceId() != service.mInterface)
if (service.mInterface.IsPresent() && addr_it.GetInterfaceId() != service.mInterface)
{
continue;
}
if (it.IsUp())
if (addr_it.IsUp())
{
if (it.IsLoopback())
if (addr_it.IsLoopback())
{
// do not advertise loopback interface addresses
continue;
}
chip::Inet::IPAddress addr;
if ((it.GetAddress(addr) == CHIP_NO_ERROR) &&
if ((addr_it.GetAddress(addr) == CHIP_NO_ERROR) &&
((service.mAddressType == chip::Inet::IPAddressType::kAny) ||
(addr.IsIPv6() && service.mAddressType == chip::Inet::IPAddressType::kIPv6) ||
(addr.IsIPv4() && service.mAddressType == chip::Inet::IPAddressType::kIPv4)))
{
VerifyOrExit(addr.ToString(b) != nullptr, error = CHIP_ERROR_INTERNAL);
AvahiAddress a;
VerifyOrExit(avahi_address_parse(b, AVAHI_PROTO_UNSPEC, &a) != nullptr, error = CHIP_ERROR_INTERNAL);
AvahiIfIndex interface = static_cast<AvahiIfIndex>(it.GetInterfaceId().GetPlatformInterface());
AvahiIfIndex thisinterface = static_cast<AvahiIfIndex>(addr_it.GetInterfaceId().GetPlatformInterface());
// Note: NO_REVERSE publish flag is needed because otherwise we can't have more than one hostname
// for reverse resolving IP addresses back to hostnames
VerifyOrExit(avahi_entry_group_add_address(group, // group
interface, // interface
thisinterface, // interface
ToAvahiProtocol(addr.Type()), // protocol
AVAHI_PUBLISH_NO_REVERSE, // publish flags
matterHostname.c_str(), // hostname
Expand Down