Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple TXT records to be published on the same service #19

Open
scotia70 opened this issue Mar 14, 2017 · 9 comments
Open

Allow multiple TXT records to be published on the same service #19

scotia70 opened this issue Mar 14, 2017 · 9 comments

Comments

@scotia70
Copy link

Hi,
I've built openmdnsd on FreeBSD (to replace avahi) and have found that I can't publish a service with two TXT records. In order to publish Apple's TimeMachine share on my NAS running netatalk I would normally use the avahi record:

<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
  <name replace-wildcards="yes">%h</name>
  <service>
    <type>_adisk._tcp</type>
    <port>9</port>
    <txt-record>sys=waMA=3c:d9:2b:04:2b:6f,adVF=0x100</txt-record>
    <txt-record>dk0=adVF=0xa1,adVN=tm,adVU=12D28B6D-AFD0-1D56-7161-723FBFE36EDC</txt-record>
  </service>
</service-group>

But doing the following with mdnsctl:

mdnsctl publish nas-01 adisk tcp 9 "sys=waMA=3c:d9:2b:04:2b:6f,adVF=0x100" "dk0=adVF=0xa1,adVN=tm,adVU=12D28B6D-AFD0-1D56-7161-723FBFE36EDC"

throws a superfluous argument error.
Running two mdnsctl commands with a TXT record in each throws a collision error.
Can you permit multiple TXT records on the command line?
Thanks.

@haesbaert
Copy link
Owner

haesbaert commented Mar 14, 2017

Indeed currently there is no support for publishing two TXT records, I was not aware of any service that needed that. It's possible that this became common in more recent years, I'll have to check the RFC, but this will require some modifications to the daemon as well.

@scotia70
Copy link
Author

scotia70 commented Mar 14, 2017

I was hoping just a change to mdsctl. I've attached another example of a service requiring multiple text records, my printer.
screen shot 2017-03-14 at 21 12 33
Note that when I run mdsctl browse -r it shows only the first TXT field:

+++ Brother HL-1210W                                 pdl-datastream       tcp
 Name: Brother HL-1210W
 Port: 9100
 Target: BRNC03896916881.local
 Address: 10.1.1.207
 Txt: txtvers=1

@haesbaert
Copy link
Owner

haesbaert commented Mar 14, 2017 via email

@scotia70
Copy link
Author

This might be my reason to get into serious C programming :)

FYI: this is what MacOS reports when browsing for the printer:

$ dns-sd -L "Brother HL-1210W" _pdl-datastream
Lookup Brother HL-1210W._pdl-datastream._tcp.local
DATE: ---Tue 14 Mar 2017---
21:25:57.843  ...STARTING...
21:25:58.040  Brother\032HL-1210W._pdl-datastream._tcp.local. can be reached at BRNC03896916881.local.:9100 (interface 4)
 txtvers=1 qtotal=1 pdl= note= ty=Brother\ HL-1210W\ series product=\(Brother\ HL-1210W\ series\) adminurl=http://BRNC03896916881.local./ priority=25 usb_MFG=Brother usb_MDL=HL-1210W\ series usb_CMD=PJL,HBP Color=F Copies=T Duplex=F Fax=F Scan=F PaperCustom=T Binary=T Transparent=F TBCP=T UUID=e3248000-80ce-11db-8000-c03896916881

It breaks up each TXT with a space and escapes any spaces within a TXT.

@haesbaert
Copy link
Owner

haesbaert commented Mar 14, 2017 via email

@scotia70
Copy link
Author

Hi, thanks for your prompt responses.

According to:
http://www.zeroconf.org/rendezvous/txtrecords.html

Jaguar's DNSServiceDiscovery.h APIs are, like most Unix APIs, based on C strings. How then does a client encode multiple pascal strings containing name/value pairs using a single C string? The answer is that Jaguar's DNSServiceDiscovery.h APIs use ASCII 1 as the boundary marker between constituent strings within the DNS TXT record. This value can be inserted into a C string using '\001', as shown below:

DNSServiceRegistrationCreate(..., "a=1\001b=2\001c=3", ...);

So I tried:

mdnsctl publish nas-01 adisk tcp 9 sys=waMA=3c:d9:2b:04:2b:6f,adVF=0x100$'\001'dk0=adVF=0xa1,adVN=tm,adVU=12D28B6D-AFD0-1D56-7161-723FBFE36EDC

and got this from MacOS:

Lookup nas-01._adisk._tcp.local
DATE: ---Tue 14 Mar 2017---
21:44:39.420  ...STARTING...
21:44:39.421  nas-01._adisk._tcp.local. can be reached at nas-01.local.:9 (interface 4)
 sys=waMA=3c:d9:2b:04:2b:6f,adVF=0x100\\x01dk0=adVF=0xa1,adVN=tm,adVU=12D28B6D-AFD0-1D56-7161-723FBFE36EDC

If I substitute $\001\ for $\101 which is the letter 'A' then I see the 'A' in the lookup. So the shell is expanding the octal correctly.

Anyway I'm not sure if this is an Apple thing or RFC.

Thanks

@scotia70
Copy link
Author

Ahh ok, after reading some of rfc6763 it seems I may be barking up the wrong tree. What is really needed is a single TXT record with multiple key/value pairs: As per 6.1 of the RFC:

   The format of the data within a DNS TXT record is one or more
   strings, packed together in memory without any intervening gaps or
   padding bytes for word alignment.

   The format of each constituent string within the DNS TXT record is a
   single length byte, followed by 0-255 bytes of text data.

And the example:

        -------------------------------------------------------
        | 0x09 | key=value | 0x08 | paper=A4 | 0x07 | passreq |
        -------------------------------------------------------

So the parser needs to take multiple key/value pairs and break them up using their key/value pair length as the leading byte.

I'll take a look at parser.c and see what I come up with...

@scotia70
Copy link
Author

Which is how wireshark decodes a multi key/value pair TXT:

screen shot 2017-03-14 at 22 22 31

@haesbaert
Copy link
Owner

haesbaert commented Mar 14, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants