[mdns] allow resolving IPv4 address for host or service with mDNSResponder - #3557
[mdns] allow resolving IPv4 address for host or service with mDNSResponder#3557librasungirl wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for IPv4-mapped IPv6 addresses in the Ip6Address class, adding helper methods to copy addresses from sockaddr, sockaddr_in, and in_addr structures, along with corresponding unit tests. It also updates the mDNS publisher to handle these address types. The review feedback highlights a potential null pointer dereference of aAddress in src/mdns/mdns_mdnssd.cpp and suggests avoiding union type punning in src/common/types.cpp to prevent undefined behavior and endianness issues.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3557 +/- ##
==========================================
- Coverage 55.77% 47.97% -7.80%
==========================================
Files 87 149 +62
Lines 6890 18514 +11624
Branches 0 1496 +1496
==========================================
+ Hits 3843 8883 +5040
- Misses 3047 9015 +5968
- Partials 0 616 +616 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
dc26166 to
b34941a
Compare
b34941a to
a8513df
Compare
…onder In mdns_mdnssd.cpp, DNSServiceGetAddrInfo is called with `kDNSServiceProtocol_IPv6 | kDNSServiceProtocol_IPv4` for both service instance resolution and host subscription resolution. This indicates that either an IPv6 or an IPv4 address is explicitly expected and allowed from the mDNS responder. However, the callback handlers `HandleGetAddrInfoResult` and `HandleResolveResult` previously discarded all non-IPv6 addresses with `VerifyOrExit(aAddress->sa_family == AF_INET6)`. This was a bug that caused hosts and services advertising only IPv4 A records to be ignored rather than resolved. This change fixes the bug by: - Accepting both AF_INET and AF_INET6 address families in `PublisherMDnsSd::ServiceInstanceResolution::HandleGetAddrInfoResult` and `PublisherMDnsSd::HostSubscription::HandleResolveResult`. - Extending `Ip6Address` with `CopyFrom(const struct sockaddr &)`, `CopyFrom(const struct sockaddr_in &)` and `CopyFrom(const struct in_addr &)` to convert resolved IPv4 addresses into IPv4-mapped IPv6 addresses (`::ffff:a.b.c.d`), consistent with OpenThread's DNS-SD / discovery proxy specification. - Adding unit test for `Ip6Address` covering IPv4-mapped addresses.
a8513df to
0b0c5ee
Compare
In mdns_mdnssd.cpp, DNSServiceGetAddrInfo is called with
kDNSServiceProtocol_IPv6 | kDNSServiceProtocol_IPv4for both service instance resolution and host subscription resolution. This indicates that either an IPv6 or an IPv4 address is explicitly expected and allowed from the mDNS responder.However, the callback handlers
HandleGetAddrInfoResultandHandleResolveResultpreviously discarded all non-IPv6 addresses withVerifyOrExit(aAddress->sa_family == AF_INET6). This was a bug that caused hosts and services advertising only IPv4 A records to be ignored rather than resolved.This change fixes the bug by:
PublisherMDnsSd::ServiceInstanceResolution::HandleGetAddrInfoResultandPublisherMDnsSd::HostSubscription::HandleResolveResult.Ip6AddresswithCopyFrom(const struct sockaddr &),CopyFrom(const struct sockaddr_in &)andCopyFrom(const struct in_addr &)to convert resolved IPv4 addresses into IPv4-mapped IPv6 addresses (::ffff:a.b.c.d), consistent with OpenThread's DNS-SD / discovery proxy specification.Ip6Addresscovering IPv4-mapped addresses.