brutella / dnssd

This library implements Multicast DNS (mDNS) and DNS-Based Service Discovery (DNS-SD) for Zero Configuration Networking in Go.
MIT License
207 stars 33 forks source link

Lookup services will fail to list ips if the service name contains more than one dot #17

Closed dubo-dubon-duponey closed 1 year ago

dubo-dubon-duponey commented 4 years ago

Browsing services with multiple dots in their domain name fails to read A records.

Consider the following answer:

****** ;; opcode: QUERY, status: NOERROR, id: 0
;; flags: qr aa; QUERY: 0, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 4

;; ANSWER SECTION:
_raop._tcp.local.       4500    IN      PTR     CEDD39ACA62E\@Corpisone._raop._tcp.local.

;; ADDITIONAL SECTION:
CEDD39ACA62E\@Corpisone._raop._tcp.local.       4500    CLASS32769      TXT     "sf=0x4" "fv=76400.10" "am=ShairportSync" "vs=105.1" "tp=TCP,UDP" "vn=65537" "ss=16" "sr=44100" "da=true" "sv=false" "et=0,1" "ek=1" "cn=0,1" "ch=2" "txtvers=1" "pw=false"
CEDD39ACA62E\@Corpisone._raop._tcp.local.       4500    CLASS32769      SRV     0 0 5000 airport.corpisone.container.local.
airport.corpisone.container.local.      120     CLASS32769      A       10.0.4.18
airport.corpisone.container.local.      120     CLASS32769      NSEC    airport.corpisone.container.local. A

While parsing the srv record: https://github.com/brutella/dnssd/blob/7335cb43c5600dcddd3ce2656ef06517673788b9/cache.go#L63

ParseHostName will apparently fail to set the hostname https://github.com/brutella/dnssd/blob/7335cb43c5600dcddd3ce2656ef06517673788b9/service.go#L175

In turn, when parsing the A record, it will fail to recognize the entry as valid: https://github.com/brutella/dnssd/blob/7335cb43c5600dcddd3ce2656ef06517673788b9/cache.go#L70

... ultimately not listing the service IP.

The above works well if the service name contains just one level (eg: "foobar.local.")

Maybe I'm missing something here - plus I'm not familiar with the spec...

What are your thoughts?

Thanks.

dubo-dubon-duponey commented 4 years ago

Note that this service above ^ is properly recognized and used by other software (it's an airplay receiver).

eg:

Screen Shot 2020-06-17 at 4 47 21 PM
brutella commented 4 years ago

It looks like a dot "." in a host name is not recommended because it is used as a separator.

From RFC1033

The domain system allows a label to contain any 8-bit character. Although the domain system has no restrictions, other protocols such as SMTP do have name restrictions. Because of other protocol restrictions, only the following characters are recommended for use in a host name (besides the dot separator):

    "A-Z", "a-z", "0-9", dash and underscore
dubo-dubon-duponey commented 4 years ago

I see. Thanks for the clarification.

Would you still welcome a PR that would handle that case (albeit not recommended)?

brutella commented 4 years ago

Not sure if it is a good idea to allow hostnames, which are actually not valid.

dubo-dubon-duponey commented 4 years ago

Mmm... "dots" do not appear in "labels" (as defined in the extract you quoted above), but a serie of dot separated labels form a valid domain name right?

SRV records do not seem to be limited to one level domain names, nor are A record, right? (https://en.wikipedia.org/wiki/SRV_record)

Specifically, Apple implementation (for Airplay), and other mDNS stacks seem to be happy with multi level domain names in SRV / A records.

Again I'm not exactly on top of my game with mDNS ;-), so, maybe I'm unaware of another RFC that would further limit this.

Either way, not opinionated one way or the other here, just curious about the bottom line :-).

brutella commented 4 years ago

From wikipedia

The Internet standards (Requests for Comments) for protocols specify that labels may contain only the ASCII letters a through z (in a case-insensitive manner), the digits 0 through 9, and the hyphen-minus character ('-'). The original specification of hostnames in RFC 952 disallowed labels from starting with a digit or with a hyphen character, and could not end with a hyphen. However, a subsequent specification (RFC 1123) permitted hostname labels to start with digits. No other symbols, punctuation characters, or white space are permitted. Internationalized domain names are stored in the Domain Name System as ASCII strings using Punycode transcription.[4]

To me this sounds like dots should not be included in hostnames.


The accepted answer for Can I have dots in a hostname? states that as well.

Using a hostname with a dot in it will cause inconsistent results from any system that consumes DNS. [...] Don't use dotted name.

dubo-dubon-duponey commented 4 years ago

To me this sounds like dots should not be included in hostnames.

This is where I'm struggling... From that same wikipedia page: "Hostnames are composed of a sequence of labels concatenated with dots. For example, "en.wikipedia.org" is a hostname."

To me, this reads as "a hostname may contain any number of labels separated by dots".

Either way, it's fine :-)

Thanks for taking the time to discuss this - I'll just rename these services.