Skip to content

Commit efd77e0

Browse files
committed
net: dns_sd, mdns: support service type enumeration
Support DNS-SD Service Type Enumeration in the dns_sd library and mdns_responder sample application. For more information, please see Section 9, "Service Type Enumeration" in RFC 6763. https://datatracker.ietf.org/doc/html/rfc6763 Fixes #38673 Signed-off-by: Christopher Friedt <[email protected]>
1 parent b3affe6 commit efd77e0

File tree

5 files changed

+459
-94
lines changed

5 files changed

+459
-94
lines changed

include/net/dns_sd.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,38 @@ extern "C" {
5050
/** RFC 1034 Section 3.1, RFC 6763 Section 7.2 */
5151
#define DNS_SD_DOMAIN_MAX_SIZE 63
5252

53+
/**
54+
* Minimum number of segments in a fully-qualified name
55+
*
56+
* This reqpresents FQN's of the form below
57+
* ```
58+
* <sn>._tcp.<domain>.
59+
* ```
60+
* Currently sub-types and service domains are unsupported and only the
61+
* "local" domain is supported. Specifically, that excludes the following:
62+
* ```
63+
* <sub>._sub.<sn>._tcp.<servicedomain>.<parentdomain>.
64+
* ```
65+
* @see <a href="https://datatracker.ietf.org/doc/html/rfc6763">RFC 6763</a>, Section 7.2.
66+
*/
67+
#define DNS_SD_MIN_LABELS 3
68+
/**
69+
* Maximum number of segments in a fully-qualified name
70+
*
71+
* This reqpresents FQN's of the form below
72+
* ```
73+
* <instance>.<sn>._tcp.<domain>.
74+
* ```
75+
*
76+
* Currently sub-types and service domains are unsupported and only the
77+
* "local" domain is supported. Specifically, that excludes the following:
78+
* ```
79+
* <sub>._sub.<sn>._tcp.<servicedomain>.<parentdomain>.
80+
* ```
81+
* @see <a href="https://datatracker.ietf.org/doc/html/rfc6763">RFC 6763</a>, Section 7.2.
82+
*/
83+
#define DNS_SD_MAX_LABELS 4
84+
5385
/**
5486
* @brief Register a service for DNS Service Discovery
5587
*
@@ -209,6 +241,12 @@ struct dns_sd_rec {
209241
* @internal
210242
*/
211243
extern const char dns_sd_empty_txt[1];
244+
/**
245+
* @brief Wildcard Port specifier for DNS-SD
246+
*
247+
* @internal
248+
*/
249+
extern const uint16_t dns_sd_port_zero;
212250

213251
/** @endcond */
214252

@@ -223,6 +261,32 @@ static inline size_t dns_sd_txt_size(const struct dns_sd_rec *rec)
223261
return rec->text_size;
224262
}
225263

264+
/**
265+
* @brief Check if @a rec is a DNS-SD Service Type Enumeration
266+
*
267+
* DNS-SD Service Type Enumeration is used by network tooling to
268+
* acquire a list of all mDNS-advertised services belonging to a
269+
* particular host on a particular domain.
270+
*
271+
* For example, for the domain '.local', the equivalent query
272+
* would be '_services._dns-sd._udp.local'.
273+
*
274+
* Currently, only the '.local' domain is supported.
275+
*
276+
* @see <a href="https://datatracker.ietf.org/doc/html/rfc6763#section-9">Service Type Enumeration, RFC 6763</a>.
277+
*
278+
* @param rec the record to in question
279+
* @return true if @a rec is a DNS-SD Service Type Enumeration
280+
*/
281+
bool dns_sd_is_service_type_enumeration(const struct dns_sd_rec *rec);
282+
283+
/**
284+
* @brief Create a wildcard filter for DNS-SD records
285+
*
286+
* @param filter a pointer to the filter to use
287+
*/
288+
void dns_sd_create_wildcard_filter(struct dns_sd_rec *filter);
289+
226290
/**
227291
* @}
228292
*/

subsys/net/lib/dns/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,17 @@ config MDNS_RESPONDER_DNS_SD
159159
By doing so, Zephyr network services are discoverable
160160
using e.g. 'avahi-browse -t -r _greybus._tcp'.
161161

162+
if MDNS_RESPONDER_DNS_SD
163+
config MDNS_RESPONDER_DNS_SD_SERVICE_TYPE_ENUMERATION
164+
bool "Enable DNS SD Service Type Enumeration"
165+
default y
166+
help
167+
Selecting this option ensures that the MDNS Responder
168+
performs DNS-SD Service Type Enumeration according to RFC 6763,
169+
Chapter 9. By doing so, Zephyr network services are discoverable
170+
using e.g. 'avahi-browse -t -r _services._dns-sd._udp.local'.
171+
endif # MDNS_RESPONDER_DNS_SD
172+
162173
module = MDNS_RESPONDER
163174
module-dep = NET_LOG
164175
module-str = Log level for mDNS responder

0 commit comments

Comments
 (0)