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

[avahi] Fix usage of searched address type #11377

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion src/lib/dnssd/platform/Dnssd.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ struct DnssdService
char mHostName[kHostNameMaxLength + 1] = "";
char mType[kDnssdTypeMaxSize + 1];
DnssdServiceProtocol mProtocol;
Inet::IPAddressType mAddressType;
Inet::IPAddressType mAddressType; // Address record type to query or publish (A or AAAA)
Inet::IPAddressType mTransportType; // Transport to use for the query.
uint16_t mPort;
chip::Inet::InterfaceId mInterface;
TextEntry * mTextEntries;
Expand Down
41 changes: 18 additions & 23 deletions src/platform/Linux/DnssdImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,16 +532,17 @@ CHIP_ERROR MdnsAvahi::Browse(const char * type, DnssdServiceProtocol protocol, c
BrowseContext * browseContext = chip::Platform::New<BrowseContext>();
AvahiIfIndex avahiInterface = static_cast<AvahiIfIndex>(interface.GetPlatformInterface());

browseContext->mInstance = this;
browseContext->mContext = context;
browseContext->mCallback = callback;
browseContext->mInstance = this;
browseContext->mContext = context;
browseContext->mCallback = callback;
browseContext->mAddressType = addressType;
if (!interface.IsPresent())
{
avahiInterface = AVAHI_IF_UNSPEC;
}

browser = avahi_service_browser_new(mClient, avahiInterface, ToAvahiProtocol(addressType), GetFullType(type, protocol).c_str(),
nullptr, static_cast<AvahiLookupFlags>(0), HandleBrowse, browseContext);
browser = avahi_service_browser_new(mClient, avahiInterface, AVAHI_PROTO_UNSPEC, GetFullType(type, protocol).c_str(), nullptr,
static_cast<AvahiLookupFlags>(0), HandleBrowse, browseContext);
// Otherwise the browser will be freed in the callback
if (browser == nullptr)
{
Expand Down Expand Up @@ -613,9 +614,10 @@ void MdnsAvahi::HandleBrowse(AvahiServiceBrowser * browser, AvahiIfIndex interfa

Platform::CopyString(service.mName, name);
CopyTypeWithoutProtocol(service.mType, type);
service.mProtocol = GetProtocolInType(type);
service.mAddressType = ToAddressType(protocol);
service.mInterface = Inet::InterfaceId::Null();
service.mProtocol = GetProtocolInType(type);
service.mAddressType = context->mAddressType;
service.mTransportType = ToAddressType(protocol);
service.mInterface = Inet::InterfaceId::Null();
if (interface != AVAHI_IF_UNSPEC)
{
service.mInterface = static_cast<chip::Inet::InterfaceId>(interface);
Expand Down Expand Up @@ -645,9 +647,9 @@ void MdnsAvahi::HandleBrowse(AvahiServiceBrowser * browser, AvahiIfIndex interfa
}
}

CHIP_ERROR MdnsAvahi::Resolve(const char * name, const char * type, DnssdServiceProtocol protocol,
chip::Inet::IPAddressType addressType, chip::Inet::InterfaceId interface,
DnssdResolveCallback callback, void * context)
CHIP_ERROR MdnsAvahi::Resolve(const char * name, const char * type, DnssdServiceProtocol protocol, Inet::IPAddressType addressType,
Inet::IPAddressType transportType, Inet::InterfaceId interface, DnssdResolveCallback callback,
void * context)
{
AvahiServiceResolver * resolver;
AvahiIfIndex avahiInterface = static_cast<AvahiIfIndex>(interface.GetPlatformInterface());
Expand All @@ -661,7 +663,8 @@ CHIP_ERROR MdnsAvahi::Resolve(const char * name, const char * type, DnssdService
{
avahiInterface = AVAHI_IF_UNSPEC;
}
resolver = avahi_service_resolver_new(mClient, avahiInterface, ToAvahiProtocol(addressType), name,

resolver = avahi_service_resolver_new(mClient, avahiInterface, ToAvahiProtocol(transportType), name,
GetFullType(type, protocol).c_str(), nullptr, ToAvahiProtocol(addressType),
static_cast<AvahiLookupFlags>(0), HandleResolve, resolveContext);
// Otherwise the resolver will be freed in the callback
Expand Down Expand Up @@ -813,18 +816,10 @@ CHIP_ERROR ChipDnssdResolve(DnssdService * browseResult, chip::Inet::InterfaceId
void * context)

{
CHIP_ERROR error;
VerifyOrReturnError(browseResult != nullptr, CHIP_ERROR_INVALID_ARGUMENT);

if (browseResult != nullptr)
{
error = MdnsAvahi::GetInstance().Resolve(browseResult->mName, browseResult->mType, browseResult->mProtocol,
browseResult->mAddressType, interface, callback, context);
}
else
{
error = CHIP_ERROR_INVALID_ARGUMENT;
}
return error;
return MdnsAvahi::GetInstance().Resolve(browseResult->mName, browseResult->mType, browseResult->mProtocol,
browseResult->mAddressType, Inet::IPAddressType::kAny, interface, callback, context);
}

} // namespace Dnssd
Expand Down
4 changes: 3 additions & 1 deletion src/platform/Linux/DnssdImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ class MdnsAvahi
CHIP_ERROR Browse(const char * type, DnssdServiceProtocol protocol, chip::Inet::IPAddressType addressType,
chip::Inet::InterfaceId interface, DnssdBrowseCallback callback, void * context);
CHIP_ERROR Resolve(const char * name, const char * type, DnssdServiceProtocol protocol, chip::Inet::IPAddressType addressType,
chip::Inet::InterfaceId interface, DnssdResolveCallback callback, void * context);
chip::Inet::IPAddressType transportType, chip::Inet::InterfaceId interface, DnssdResolveCallback callback,
void * context);

Poller & GetPoller() { return mPoller; }

Expand All @@ -123,6 +124,7 @@ class MdnsAvahi
MdnsAvahi * mInstance;
DnssdBrowseCallback mCallback;
void * mContext;
Inet::IPAddressType mAddressType;
std::vector<DnssdService> mServices;
};

Expand Down