When "listen-hostname" is specified, use it as the system hostname as well
Currently if you try to restrict PAPPL to advertising locally with the "-o listen-hostname=localhost" mainloop option, the DNS-SD advertisements still use the system hostname which is usually something like "hostname.local". Since Avahi doesn't include the loopback interface addresses in a local resolver request like mDNSResponder does on macOS, this leads to connectivity issues.
Update papplSystemAddListeners to force the pappl_system_t value for hostname to "localhost" when the listen address is "localhost".
Note based on https://github.com/michaelrsweet/pappl/pull/345#issuecomment-2416988480 : changing "system-hostname" with "listen-hostname" won't cut in the current implementation, because it changes the machine hostname, which is undesirable if the printer application runs in the system and not in container.
@zdohnal The changes will necessarily only set the local value and not the system hostname.
OK, so after further reflection I'm going to update things so that when a "listen-hostname" value is supplied that is not an IP address, domain socket path, or "*", we use it as the system hostname. The value is set along with a boolean flag indicating that we are sticking with the original listen hostname rather than following any mDNS hostname changes.
This will make "-o listen-hostname=localhost" only advertise localhost and on the loopback interface while "-o listen-hostname=mysystem.example.com" will listen to the addresses registered for that hostname and only advertise the named hostname.
I'm not bothering supporting multiple hostnames from one printer application instance, as that configuration is relatively unusual and I'm not implementing any kind of access partitioning based on the network or hostname you use.
@zdohnal Please test:
[v1.4.x fba6a47] Use listen-hostname as hostname (Issue #369)
[master 9be7ffb] Use listen-hostname as hostname (Issue #369)
It is a start:
# avahi-browse -avrt
Server version: avahi 0.8; Host name: zdohnal-fedora.local
E Ifce Prot Name Type Domain
+ lo IPv4 test _printer._tcp local
= lo IPv4 test _printer._tcp local
hostname = [zdohnal-fedora.local]
address = [127.0.0.1]
port = [0]
txt = []
: Cache exhausted
: All for now
Log:
Oct 17 16:00:27 zdohnal-fedora systemd[1]: Started lprint.service - LPrint Service.
Oct 17 16:00:27 zdohnal-fedora lprint[2179]: I [2024-10-17T16:00:27.199Z] Starting log, system up 0 second(s), 0 printer(s), listening for connections on 'zdohnal-fedora.local:8000' from up to 32768 clients.
Oct 17 16:00:27 zdohnal-fedora lprint[2179]: I [2024-10-17T16:00:27.202Z] Listening for connections on 'localhost:8000'.
Oct 17 16:00:27 zdohnal-fedora lprint[2179]: I [2024-10-17T16:00:27.203Z] Loading system state from '/var/lib/lprint.state'.
Oct 17 16:00:27 zdohnal-fedora lprint[2179]: I [2024-10-17T16:00:27.203Z] Listening for connections on '/run/lprint.sock'.
Oct 17 16:00:27 zdohnal-fedora lprint[2179]: I [2024-10-17T16:00:27.203Z] Starting system.
Oct 17 16:00:27 zdohnal-fedora lprint[2179]: E [2024-10-17T16:00:27.204Z] Unable to register 'LPrint._ipps-system._tcp': Invalid host name
Oct 17 16:00:32 zdohnal-fedora lprint[2179]: I [2024-10-17T16:00:32.423Z] [Client 1] Accepted connection from 'localhost'.
Oct 17 16:00:32 zdohnal-fedora lprint[2179]: I [2024-10-17T16:00:32.423Z] [Client 1] HTTP_STATE_POST http://localhost:0/ipp/system HTTP/1.1 ()
Oct 17 16:00:32 zdohnal-fedora lprint[2179]: I [2024-10-17T16:00:32.423Z] [Client 1] Continue
Oct 17 16:00:32 zdohnal-fedora lprint[2179]: I [2024-10-17T16:00:32.423Z] Printer 'test' at resource path '/ipp/print/test'.
Oct 17 16:00:32 zdohnal-fedora lprint[2179]: W [2024-10-17T16:00:32.423Z] [Printer test] Driver does not support identification.
Oct 17 16:00:32 zdohnal-fedora lprint[2179]: E [2024-10-17T16:00:32.424Z] Unable to register 'LPrint._ipps-system._tcp': Invalid host name
Oct 17 16:00:32 zdohnal-fedora lprint[2179]: W [2024-10-17T16:00:32.426Z] [Printer test] Driver does not support identification.
Oct 17 16:00:32 zdohnal-fedora lprint[2179]: I [2024-10-17T16:00:32.426Z] [Printer test] Listening for socket print jobs on '*:9101'.
Oct 17 16:00:32 zdohnal-fedora lprint[2179]: I [2024-10-17T16:00:32.427Z] [Client 1] Create-Printer successful-ok
Oct 17 16:00:32 zdohnal-fedora lprint[2179]: E [2024-10-17T16:00:32.428Z] [Printer test] Unable to register 'test._ipp._tcp': Invalid host name
Oct 17 16:00:32 zdohnal-fedora lprint[2179]: E [2024-10-17T16:00:32.429Z] [Printer test] Unable to register 'test._ipps._tcp': Invalid host name
Oct 17 16:00:32 zdohnal-fedora lprint[2179]: E [2024-10-17T16:00:32.430Z] [Printer test] Unable to register 'test._pdl-datastream._tcp': Invalid host name
Oct 17 16:00:32 zdohnal-fedora lprint[2179]: I [2024-10-17T16:00:32.430Z] [Client 1] OK application/ipp 376
Oct 17 16:00:32 zdohnal-fedora lprint[2179]: I [2024-10-17T16:00:32.430Z] [Client 1] Closing connection from 'localhost'.
Oct 17 16:01:02 zdohnal-fedora lprint[2179]: I [2024-10-17T16:01:02.029Z] Saving system state to '/var/lib/lprint.state'.
So it is a step towards the fix, but not complete :( .
Ah, so Avahi is rejecting the registration because the hostname is "localhost"... This is a known Avahi bug that supposedly was fixed in Avahi 0.8. Can you look for messages from Avahi in the system log/journal?
@michaelrsweet IIUC the outcome of the mentioned bug was to enable registering service on loopback, not allowing localhost as hostname for registration.
Basically I wanted to fix that by https://github.com/avahi/avahi/pull/572 , but it was deemed insufficient and required more discussion I don't have enough knowledge to argue, so that's why I went with the solution I presented in my PAPPL PR.
IIUC enabling localhost as valid hostname is no-go in Avahi upstream due protocol specs, see https://github.com/avahi/avahi/commit/2fd76baeb8298ef1b5b177bf7fd70f6cda3eab00#commitcomment-37347888 , so we should use their implementation...
Either way, here is the debug log from Avahi - avahi-log.txt
Hmm, OK well the CUPS DNS-SD APIs are smart enough to resolve any service with an IP address of 127.0.0.1 to "localhost", so maybe we can just update to use a NULL hostname (which works for both mDNSResponder and Avahi).
OK, try this:
[master f6bcbb7] Use NULL registration hostname (Issue #369)
[v1.4.x 0e1c0a3] Use NULL registration hostname (Issue #369)
@zdohnal Meant to mention you on the previous message - try the latest master/v1.4.x and let me know how it works for you...
@zdohnal ???
@michaelrsweet I'm sorry for delay, the last related PR does the trick :) thanks!
@zdohnal Great, thank you!