ericpaulbishop / gargoyle

Gargoyle Router Management Utility
http://www.gargoyle-router.com
465 stars 222 forks source link

configure_printer: improve service discovery records #987

Closed EricFromCanada closed 1 year ago

EricFromCanada commented 1 year ago

This PR corrects the service discovery DNS records that are added to the dnsmasq configuration when a printer is detected.

For static service discovery records being served from a unicast DNS server, the PTR record that associates a service (e.g. _pdl-datastream._tcp) with a hostname needs to have matching SRV and TXT records for that hostname. Currently the SRV is always set to "Gargoyle"; I've changed it and the PTR and TXT records to use the printer name with spaces replaced with underscores.

This also adds some logic that fetches the device manufacturer from the USB device and includes it as the usb_MFG attribute, which may help OSes with picking the correct printer driver, along with two more attributes that set the note to the router hostname and pdl to "raw".

On macOS with these changes, the printer now shows up in the printer browser with the printer name and the hostname as the Location.

printers3

For reference, here's what a series of DNS queries for successful unicast service discovery could look like (assuming a search domain of "home" is set on a 10.10.1.0/24 network):

$ dig +short PTR b._dns-sd._udp.0.1.10.10.in-addr.arpa
home.
$ dig +short PTR _services._dns-sd._udp.home
_pdl-datastream._tcp.home.
$ dig +short PTR _pdl-datastream._tcp.home
HP_LaserJet_1020._pdl-datastream._tcp.home.
$ dig +short SRV HP_LaserJet_1020._pdl-datastream._tcp.home
0 0 9100 ArcherC7v4.home.
$ dig +short TXT HP_LaserJet_1020._pdl-datastream._tcp.home
"ty=HP LaserJet 1020" "product=(HP LaserJet 1020)" "usb_MDL=HP LaserJet 1020" "usb_MFG=Hewlett-Packard" "note=ArcherC7v4" "pdl=raw" "txtvers=1" "qtotal=1" "priority=20"
EricFromCanada commented 1 year ago

Revised to have the service discovery records use the name of the printer instead of the router hostname, so added printers won't need to be re-associated if the router hostname changes.

lantis1008 commented 1 year ago

Thanks for your contribution!