diff --git a/src/controller/tests/TestCommissionableNodeController.cpp b/src/controller/tests/TestCommissionableNodeController.cpp index 41d5663bafb0b6..dc841b4482e4c0 100644 --- a/src/controller/tests/TestCommissionableNodeController.cpp +++ b/src/controller/tests/TestCommissionableNodeController.cpp @@ -43,6 +43,10 @@ class MockResolver : public Resolver return CHIP_ERROR_NOT_IMPLEMENTED; } CHIP_ERROR StopDiscovery() override { return CHIP_ERROR_NOT_IMPLEMENTED; } + CHIP_ERROR ReconfirmRecord(const char * hostname, Inet::IPAddress address, Inet::InterfaceId interfaceId) override + { + return CHIP_ERROR_NOT_IMPLEMENTED; + } CHIP_ERROR InitStatus = CHIP_NO_ERROR; CHIP_ERROR ResolveNodeIdStatus = CHIP_NO_ERROR; diff --git a/src/lib/dnssd/Discovery_ImplPlatform.cpp b/src/lib/dnssd/Discovery_ImplPlatform.cpp index a5feca89881854..6d4b775f16f675 100644 --- a/src/lib/dnssd/Discovery_ImplPlatform.cpp +++ b/src/lib/dnssd/Discovery_ImplPlatform.cpp @@ -641,6 +641,12 @@ CHIP_ERROR DiscoveryImplPlatform::StopDiscovery() return mResolverProxy.StopDiscovery(); } +CHIP_ERROR DiscoveryImplPlatform::ReconfirmRecord(const char * hostname, Inet::IPAddress address, Inet::InterfaceId interfaceId) +{ + ReturnErrorOnFailure(InitImpl()); + return mResolverProxy.ReconfirmRecord(hostname, address, interfaceId); +} + DiscoveryImplPlatform & DiscoveryImplPlatform::GetInstance() { return sManager; @@ -750,5 +756,10 @@ CHIP_ERROR ResolverProxy::StopDiscovery() return err; } +CHIP_ERROR ResolverProxy::ReconfirmRecord(const char * hostname, Inet::IPAddress address, Inet::InterfaceId interfaceId) +{ + return ChipDnssdReconfirmRecord(hostname, address, interfaceId); +} + } // namespace Dnssd } // namespace chip diff --git a/src/lib/dnssd/Discovery_ImplPlatform.h b/src/lib/dnssd/Discovery_ImplPlatform.h index dcee5bc0974f7c..0723dbf0fedf0c 100644 --- a/src/lib/dnssd/Discovery_ImplPlatform.h +++ b/src/lib/dnssd/Discovery_ImplPlatform.h @@ -58,6 +58,7 @@ class DiscoveryImplPlatform : public ServiceAdvertiser, public Resolver CHIP_ERROR DiscoverCommissionableNodes(DiscoveryFilter filter = DiscoveryFilter()) override; CHIP_ERROR DiscoverCommissioners(DiscoveryFilter filter = DiscoveryFilter()) override; CHIP_ERROR StopDiscovery() override; + CHIP_ERROR ReconfirmRecord(const char * hostname, Inet::IPAddress address, Inet::InterfaceId interfaceId) override; static DiscoveryImplPlatform & GetInstance(); diff --git a/src/lib/dnssd/Resolver.h b/src/lib/dnssd/Resolver.h index dddbed07625ebe..efba2ba931a2ff 100644 --- a/src/lib/dnssd/Resolver.h +++ b/src/lib/dnssd/Resolver.h @@ -398,6 +398,12 @@ class Resolver */ virtual CHIP_ERROR StopDiscovery() = 0; + /** + * Verify the validity of an address that appears to be out of date (for example + * because establishing a connection to it has failed). + */ + virtual CHIP_ERROR ReconfirmRecord(const char * hostname, Inet::IPAddress address, Inet::InterfaceId interfaceId) = 0; + /** * Provides the system-wide implementation of the service resolver */ diff --git a/src/lib/dnssd/ResolverProxy.h b/src/lib/dnssd/ResolverProxy.h index 36ada23a486dcf..b8bf3fbacb7082 100644 --- a/src/lib/dnssd/ResolverProxy.h +++ b/src/lib/dnssd/ResolverProxy.h @@ -153,6 +153,7 @@ class ResolverProxy : public Resolver CHIP_ERROR DiscoverCommissionableNodes(DiscoveryFilter filter = DiscoveryFilter()) override; CHIP_ERROR DiscoverCommissioners(DiscoveryFilter filter = DiscoveryFilter()) override; CHIP_ERROR StopDiscovery() override; + CHIP_ERROR ReconfirmRecord(const char * hostname, Inet::IPAddress address, Inet::InterfaceId interfaceId) override; private: ResolverDelegateProxy * mDelegate = nullptr; diff --git a/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp b/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp index cf168d78139c9d..7e9c44e4d8072f 100644 --- a/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp +++ b/src/lib/dnssd/Resolver_ImplMinimalMdns.cpp @@ -282,6 +282,7 @@ class MinMdnsResolver : public Resolver, public MdnsPacketDelegate CHIP_ERROR DiscoverCommissionableNodes(DiscoveryFilter filter = DiscoveryFilter()) override; CHIP_ERROR DiscoverCommissioners(DiscoveryFilter filter = DiscoveryFilter()) override; CHIP_ERROR StopDiscovery() override; + CHIP_ERROR ReconfirmRecord(const char * hostname, Inet::IPAddress address, Inet::InterfaceId interfaceId) override; private: OperationalResolveDelegate * mOperationalDelegate = nullptr; @@ -639,6 +640,11 @@ CHIP_ERROR MinMdnsResolver::StopDiscovery() return mActiveResolves.CompleteAllBrowses(); } +CHIP_ERROR MinMdnsResolver::ReconfirmRecord(const char * hostname, Inet::IPAddress address, Inet::InterfaceId interfaceId) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + CHIP_ERROR MinMdnsResolver::BrowseNodes(DiscoveryType type, DiscoveryFilter filter) { mActiveResolves.MarkPending(filter, type); @@ -723,5 +729,10 @@ CHIP_ERROR ResolverProxy::StopDiscovery() return CHIP_ERROR_NOT_IMPLEMENTED; } +CHIP_ERROR ResolverProxy::ReconfirmRecord(const char * hostname, Inet::IPAddress address, Inet::InterfaceId interfaceId) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + } // namespace Dnssd } // namespace chip diff --git a/src/lib/dnssd/Resolver_ImplNone.cpp b/src/lib/dnssd/Resolver_ImplNone.cpp index 5fe429f8a62444..c4d4cc0f6dce84 100644 --- a/src/lib/dnssd/Resolver_ImplNone.cpp +++ b/src/lib/dnssd/Resolver_ImplNone.cpp @@ -43,6 +43,10 @@ class NoneResolver : public Resolver } CHIP_ERROR DiscoverCommissioners(DiscoveryFilter filter = DiscoveryFilter()) override { return CHIP_ERROR_NOT_IMPLEMENTED; } CHIP_ERROR StopDiscovery() override { return CHIP_ERROR_NOT_IMPLEMENTED; } + CHIP_ERROR ReconfirmRecord(const char * hostname, Inet::IPAddress address, Inet::InterfaceId interfaceId) override + { + return CHIP_ERROR_NOT_IMPLEMENTED; + } }; NoneResolver gResolver; @@ -79,5 +83,10 @@ CHIP_ERROR ResolverProxy::StopDiscovery() return CHIP_ERROR_NOT_IMPLEMENTED; } +CHIP_ERROR ResolverProxy::ReconfirmRecord(const char * hostname, Inet::IPAddress address, Inet::InterfaceId interfaceId) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + } // namespace Dnssd } // namespace chip diff --git a/src/lib/dnssd/platform/Dnssd.h b/src/lib/dnssd/platform/Dnssd.h index 1bce362b400782..263e42450e0efa 100644 --- a/src/lib/dnssd/platform/Dnssd.h +++ b/src/lib/dnssd/platform/Dnssd.h @@ -245,5 +245,15 @@ CHIP_ERROR ChipDnssdStopBrowse(intptr_t browseIdentifier); CHIP_ERROR ChipDnssdResolve(DnssdService * browseResult, chip::Inet::InterfaceId interface, DnssdResolveCallback callback, void * context); +/** + * This function ask the mdns daemon to asynchronously reconfirm an address that appears to be out of date. + * + * @param[in] hostname The hostname the address belongs to. + * @param[in] address The address to reconfirm. + * @param[in] interfaceId The interfaceId of the address. + * + */ +CHIP_ERROR ChipDnssdReconfirmRecord(const char * hostname, chip::Inet::IPAddress address, chip::Inet::InterfaceId interface); + } // namespace Dnssd } // namespace chip diff --git a/src/platform/Darwin/DnssdImpl.cpp b/src/platform/Darwin/DnssdImpl.cpp index a955941a8c633c..8d08b4c3f3daca 100644 --- a/src/platform/Darwin/DnssdImpl.cpp +++ b/src/platform/Darwin/DnssdImpl.cpp @@ -36,10 +36,11 @@ constexpr const char * kLocalDot = "local."; constexpr const char * kProtocolTcp = "._tcp"; constexpr const char * kProtocolUdp = "._udp"; -constexpr DNSServiceFlags kRegisterFlags = kDNSServiceFlagsNoAutoRename; -constexpr DNSServiceFlags kBrowseFlags = 0; -constexpr DNSServiceFlags kGetAddrInfoFlags = kDNSServiceFlagsTimeout | kDNSServiceFlagsShareConnection; -constexpr DNSServiceFlags kResolveFlags = kDNSServiceFlagsShareConnection; +constexpr DNSServiceFlags kRegisterFlags = kDNSServiceFlagsNoAutoRename; +constexpr DNSServiceFlags kBrowseFlags = 0; +constexpr DNSServiceFlags kGetAddrInfoFlags = kDNSServiceFlagsTimeout | kDNSServiceFlagsShareConnection; +constexpr DNSServiceFlags kResolveFlags = kDNSServiceFlagsShareConnection; +constexpr DNSServiceFlags kReconfirmRecordFlags = 0; bool IsSupportedProtocol(DnssdServiceProtocol protocol) { @@ -446,5 +447,49 @@ CHIP_ERROR ChipDnssdResolve(DnssdService * service, chip::Inet::InterfaceId inte return Resolve(context, callback, interfaceId, service->mAddressType, regtype.c_str(), service->mName); } +CHIP_ERROR ChipDnssdReconfirmRecord(const char * hostname, chip::Inet::IPAddress address, chip::Inet::InterfaceId interface) +{ + VerifyOrReturnError(hostname != nullptr, CHIP_ERROR_INVALID_ARGUMENT); + + auto interfaceId = interface.GetPlatformInterface(); + auto rrclass = kDNSServiceClass_IN; + auto fullname = GetHostNameWithDomain(hostname); + + uint16_t rrtype; + uint16_t rdlen; + const void * rdata; + + in6_addr ipv6; +#if INET_CONFIG_ENABLE_IPV4 + in_addr ipv4; +#endif // INET_CONFIG_ENABLE_IPV4 + + if (address.IsIPv6()) + { + ipv6 = address.ToIPv6(); + rrtype = kDNSServiceType_AAAA; + rdlen = static_cast(sizeof(in6_addr)); + rdata = &ipv6; + } +#if INET_CONFIG_ENABLE_IPV4 + else if (address.IsIPv4()) + { + ipv4 = address.ToIPv4(); + rrtype = kDNSServiceType_A; + rdlen = static_cast(sizeof(in_addr)); + rdata = &ipv4; + } +#endif // INET_CONFIG_ENABLE_IPV4 + else + { + return CHIP_ERROR_INVALID_ARGUMENT; + } + + auto error = DNSServiceReconfirmRecord(kReconfirmRecordFlags, interfaceId, fullname.c_str(), rrtype, rrclass, rdlen, rdata); + LogOnFailure(__func__, error); + + return Error::ToChipError(error); +} + } // namespace Dnssd } // namespace chip diff --git a/src/platform/ESP32/DnssdImpl.cpp b/src/platform/ESP32/DnssdImpl.cpp index 342ce11a8c3015..4f592b8666885b 100644 --- a/src/platform/ESP32/DnssdImpl.cpp +++ b/src/platform/ESP32/DnssdImpl.cpp @@ -511,5 +511,10 @@ CHIP_ERROR ChipDnssdResolve(DnssdService * service, chip::Inet::InterfaceId inte return error; } +CHIP_ERROR ChipDnssdReconfirmRecord(const char * hostname, chip::Inet::IPAddress address, chip::Inet::InterfaceId interface) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + } // namespace Dnssd } // namespace chip diff --git a/src/platform/Linux/DnssdImpl.cpp b/src/platform/Linux/DnssdImpl.cpp index 758fa1569dd8a9..c813177729ebcb 100644 --- a/src/platform/Linux/DnssdImpl.cpp +++ b/src/platform/Linux/DnssdImpl.cpp @@ -872,5 +872,10 @@ CHIP_ERROR ChipDnssdResolve(DnssdService * browseResult, chip::Inet::InterfaceId browseResult->mAddressType, Inet::IPAddressType::kAny, interface, callback, context); } +CHIP_ERROR ChipDnssdReconfirmRecord(const char * hostname, chip::Inet::IPAddress address, chip::Inet::InterfaceId interface) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + } // namespace Dnssd } // namespace chip diff --git a/src/platform/OpenThread/DnssdImpl.cpp b/src/platform/OpenThread/DnssdImpl.cpp index 654b7cab5054b4..5800afa202198b 100644 --- a/src/platform/OpenThread/DnssdImpl.cpp +++ b/src/platform/OpenThread/DnssdImpl.cpp @@ -122,5 +122,10 @@ CHIP_ERROR ChipDnssdResolve(DnssdService * browseResult, Inet::InterfaceId inter #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT && CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT } +CHIP_ERROR ChipDnssdReconfirmRecord(const char * hostname, chip::Inet::IPAddress address, chip::Inet::InterfaceId interface) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + } // namespace Dnssd } // namespace chip diff --git a/src/platform/Tizen/DnssdImpl.cpp b/src/platform/Tizen/DnssdImpl.cpp index 1d10c71574e1f5..30593f07c2408c 100644 --- a/src/platform/Tizen/DnssdImpl.cpp +++ b/src/platform/Tizen/DnssdImpl.cpp @@ -823,5 +823,10 @@ CHIP_ERROR ChipDnssdResolve(DnssdService * browseResult, chip::Inet::InterfaceId return DnssdTizen::GetInstance().Resolve(*browseResult, interface, callback, context); } +CHIP_ERROR ChipDnssdReconfirmRecord(const char * hostname, chip::Inet::IPAddress address, chip::Inet::InterfaceId interface) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + } // namespace Dnssd } // namespace chip diff --git a/src/platform/android/DnssdImpl.cpp b/src/platform/android/DnssdImpl.cpp index 7ed8e771d82546..36546689e1fc3e 100644 --- a/src/platform/android/DnssdImpl.cpp +++ b/src/platform/android/DnssdImpl.cpp @@ -214,6 +214,11 @@ CHIP_ERROR ChipDnssdResolve(DnssdService * service, Inet::InterfaceId interface, return CHIP_NO_ERROR; } +CHIP_ERROR ChipDnssdReconfirmRecord(const char * hostname, chip::Inet::IPAddress address, chip::Inet::InterfaceId interface) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + // Implemention of Java-specific functions void InitializeWithObjects(jobject resolverObject, jobject browserObject, jobject mdnsCallbackObject) diff --git a/src/platform/bouffalolab/BL602/DnssdImpl.cpp b/src/platform/bouffalolab/BL602/DnssdImpl.cpp index 143d19eb5cb374..e2e5779d0c5bf7 100644 --- a/src/platform/bouffalolab/BL602/DnssdImpl.cpp +++ b/src/platform/bouffalolab/BL602/DnssdImpl.cpp @@ -313,5 +313,10 @@ CHIP_ERROR ChipDnssdResolve(DnssdService * /*service*/, chip::Inet::InterfaceId return CHIP_ERROR_NOT_IMPLEMENTED; } +CHIP_ERROR ChipDnssdReconfirmRecord(const char * hostname, chip::Inet::IPAddress address, chip::Inet::InterfaceId interface) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + } // namespace Dnssd } // namespace chip diff --git a/src/platform/fake/DnssdImpl.cpp b/src/platform/fake/DnssdImpl.cpp index 7fcc82c7bc8931..fbce5984f7f059 100644 --- a/src/platform/fake/DnssdImpl.cpp +++ b/src/platform/fake/DnssdImpl.cpp @@ -132,6 +132,11 @@ CHIP_ERROR ChipDnssdResolve(DnssdService * browseResult, chip::Inet::InterfaceId return CHIP_ERROR_NOT_IMPLEMENTED; } +CHIP_ERROR ChipDnssdReconfirmRecord(const char * hostname, chip::Inet::IPAddress address, chip::Inet::InterfaceId interface) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + void GetMdnsTimeout(timeval & timeout) {} void HandleMdnsTimeout() {} diff --git a/src/platform/mt793x/DnssdImpl.cpp b/src/platform/mt793x/DnssdImpl.cpp index a88eeac1c62463..e61bbeeefc4ee0 100644 --- a/src/platform/mt793x/DnssdImpl.cpp +++ b/src/platform/mt793x/DnssdImpl.cpp @@ -273,5 +273,10 @@ CHIP_ERROR ChipDnssdResolve(DnssdService * service, chip::Inet::InterfaceId inte return error; } +CHIP_ERROR ChipDnssdReconfirmRecord(const char * hostname, chip::Inet::IPAddress address, chip::Inet::InterfaceId interface) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + } // namespace Dnssd } // namespace chip diff --git a/src/platform/webos/DnssdImpl.cpp b/src/platform/webos/DnssdImpl.cpp index 043d6bb01c7020..97ce39bad012aa 100644 --- a/src/platform/webos/DnssdImpl.cpp +++ b/src/platform/webos/DnssdImpl.cpp @@ -869,5 +869,10 @@ CHIP_ERROR ChipDnssdResolve(DnssdService * browseResult, chip::Inet::InterfaceId browseResult->mAddressType, Inet::IPAddressType::kAny, interface, callback, context); } +CHIP_ERROR ChipDnssdReconfirmRecord(const char * hostname, chip::Inet::IPAddress address, chip::Inet::InterfaceId interface) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + } // namespace Dnssd } // namespace chip