1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

dnssd: don't advertise subtype PTRs to the browsing domain

The RFC6763 § 9 recommendation is to advertise only the two-label
service names.

Fixes: 88123aa21c ("dnssd: support service subtypes")
This commit is contained in:
Ronan Pigott 2024-03-19 01:56:03 -07:00 committed by Luca Boccassi
parent 30f08c303a
commit cd40efc671
3 changed files with 21 additions and 2 deletions

View File

@ -182,6 +182,23 @@ bool dns_resource_key_is_dnssd_ptr(const DnsResourceKey *key) {
dns_name_endswith(dns_resource_key_name(key), "_udp.local");
}
bool dns_resource_key_is_dnssd_two_label_ptr(const DnsResourceKey *key) {
assert(key);
/* Check if this is a PTR resource key used in Service Instance
* Enumeration as described in RFC6763 § 4.1, excluding selective
* service names described in RFC6763 § 7.1. */
if (key->type != DNS_TYPE_PTR)
return false;
const char *name = dns_resource_key_name(key);
if (dns_name_parent(&name) <= 0)
return false;
return dns_name_equal(name, "_tcp.local") || dns_name_equal(name, "_udp.local");
}
int dns_resource_key_equal(const DnsResourceKey *a, const DnsResourceKey *b) {
int r;

View File

@ -334,6 +334,7 @@ DnsResourceKey* dns_resource_key_unref(DnsResourceKey *key);
const char* dns_resource_key_name(const DnsResourceKey *key);
bool dns_resource_key_is_address(const DnsResourceKey *key);
bool dns_resource_key_is_dnssd_ptr(const DnsResourceKey *key);
bool dns_resource_key_is_dnssd_two_label_ptr(const DnsResourceKey *key);
int dns_resource_key_equal(const DnsResourceKey *a, const DnsResourceKey *b);
int dns_resource_key_match_rr(const DnsResourceKey *key, DnsResourceRecord *rr, const char *search_domain);
int dns_resource_key_match_cname_or_dname(const DnsResourceKey *key, const DnsResourceKey *cname, const char *search_domain);

View File

@ -1504,9 +1504,10 @@ int dns_scope_announce(DnsScope *scope, bool goodbye) {
continue;
}
/* Collect service types for _services._dns-sd._udp.local RRs in a set */
/* Collect service types for _services._dns-sd._udp.local RRs in a set. Only two-label names
* (not selective names) are considered according to RFC6763 § 9. */
if (!scope->announced &&
dns_resource_key_is_dnssd_ptr(z->rr->key)) {
dns_resource_key_is_dnssd_two_label_ptr(z->rr->key)) {
if (!set_contains(types, dns_resource_key_name(z->rr->key))) {
r = set_ensure_put(&types, &dns_name_hash_ops, dns_resource_key_name(z->rr->key));
if (r < 0)