Skip to content

resolvectl: Add show-multicast verb to show discovered LLMNR/mDNS hosts - #18355

Merged
keszybz merged 3 commits into
systemd:mainfrom
daandemeyer:resolved-discover
Feb 4, 2021
Merged

keszybz merged 3 commits into
systemd:mainfrom
daandemeyer:resolved-discover

Conversation

@daandemeyer

@daandemeyer daandemeyer commented Jan 23, 2021 •

Copy link
Copy Markdown
Collaborator

resolvectl currently lacks an easy way to list what hosts have been discovered on the local network via LLMNR or mDNS. With the show-multicast verb, this information is displayed (formatted in a table).

Fixes #14796

Depends on #18354

Test plan:

mkosi qemu
systemctl start systemd-resolved
resolvectl show-multicast

Output:

[root@archlinux ~]# resolvectl show-multicast
HOSTNAME  ADDRESS         SOURCE    
archlinux 169.254.194.202 LLMNR/IPv4
archlinux 192.168.91.17   LLMNR/IPv4

@bluca

bluca commented Jan 23, 2021

Copy link
Copy Markdown
Member

Discover() returns an array of hostnames/addresses discovered via
LLMNR or Multicast DNS. It does not trigger any discover on its own

From the UI point of view, this sounds a bit confusing to me - is there a different verb that could best describe what it does? show-discovered maybe?

@boucman

boucman commented Jan 23, 2021

Copy link
Copy Markdown
Contributor

list-known maybe ?

Comment thread src/resolve/resolvectl.c Resolved
@Hendrikto

Copy link
Copy Markdown

I suggest list-hosts.

@daandemeyer

daandemeyer commented Jan 23, 2021 •

Copy link
Copy Markdown
Collaborator Author

As Visual Studio Code now supports only formatting modified lines and we have a .clang-format config in the repository, I tried using clang-format while writing this PR, formatting only the modified lines. For tables, clang-format unfortunately doesn't do the right thing, so I added directives to turn off clang-format for the tables I touched to the source code.

Let me know if we want to allow these directives in the source code to allow more seamless usage of clang-format or if these should be removed. The comma change is also done by clang-format as the comma's are part of the printf function call.

Maybe list-discovered-hosts? A bit long but very self-explanatory. Also looking for suggestions on a better name for the D-Bus method.

@boucman

boucman commented Jan 24, 2021

Copy link
Copy Markdown
Contributor

list-discovered is shorter, and in the context of resolvectl it's probably clear enough...

@daandemeyer daandemeyer changed the title resolvectl: Add discover verb to list discover LLMNR/mDNS info resolvectl: Add list-discovered verb to list discover LLMNR/mDNS info Jan 25, 2021
@daandemeyer

Copy link
Copy Markdown
Collaborator Author

Renamed to list-discovered (D-Bus method to ListDiscovered)

@daandemeyer

daandemeyer commented Jan 25, 2021 •

Copy link
Copy Markdown
Collaborator Author

Two interesting things I noticed while testing this:

  1. There seem to be no LLMNR entries in the cache when booting the mkosi container using systemd-nspawn. Anyone got any ideas why LLMNR discovery would differ depending on whether we run in a container or a VM?
  2. When testing using QEMU, resolvectl list-discovered's table will only ever contain IPv4 or IPv6 addresses for the host machine, but never both at the same time. Is this inherent to the LLMNR protocol?

@daandemeyer
daandemeyer force-pushed the resolved-discover branch 3 times, most recently from 8d670d7 to d9f45ad Compare January 25, 2021 18:00
@daandemeyer daandemeyer changed the title resolvectl: Add list-discovered verb to list discover LLMNR/mDNS info resolvectl: Add list-discovered verb to list discovered LLMNR/mDNS info Jan 25, 2021
@daandemeyer daandemeyer changed the title resolvectl: Add list-discovered verb to list discovered LLMNR/mDNS info resolvectl: Add list-discovered verb to list discovered LLMNR/mDNS hosts Jan 25, 2021

@keszybz keszybz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks all good, except for the name. I know naming is hard, but "discovered" is pretty much meaningless without explanation. In particular, classis DNS names we have in the cache have also been "discovered", and it wouldn't be clear why they are not included in this output. We call mDNS + LLMNR "multicast dns", but that name is very close to MulticastDNS/mDNS, so can't be used directly. My other idea would be something like "local hosts", but obviously that is too close to "localhost". But I think we need to find some word that emphasizes that this about non-unicast-dns names. Maybe "list-multicast-names" or "list-multicast-hosts"?

Comment thread mkosi.postinst Resolved
Comment thread man/org.freedesktop.resolve1.xml Resolved
Comment thread src/resolve/resolvectl.c Resolved
@keszybz

keszybz commented Jan 30, 2021

Copy link
Copy Markdown
Member

Maybe "list-multicast-names" or "list-multicast-hosts"?

Another approach. We currently don't have a show-cache verb, but I'm pretty sure we will want to add this at some point. We could "attach" the functionality in this PR to that verb, by implementing show-cache --multicast. --multicast would be required or implicit for now. Later on, if we implement dumping of other entry types, we can add more switches.

I don't think cache dumping should be totally unprivileged. It may create an information leak. It seems OK for mDNS/LLMNR names, but for classic DNS we should probably go through polkit.

@daandemeyer

Copy link
Copy Markdown
Collaborator Author

What about show-multicast? I agree that this is pretty narrow and maybe a larger dump-cache verb would be better but is dumping the entire dns cache really going to be useful for users? I'd think users would primarily be interested in the multicast hosts. For developers, having the dns cache could be useful but it's already possible to dump the cache by sending a signal to resolved. That should be sufficient for development purposes no?

systemd is compiled with relative source file paths so we need to
issue a directory command to make sure gdb can find systemd's
source files. Let's put this in a .gdbinit file so it's executed
automatically when we run gdb.
@keszybz

keszybz commented Jan 30, 2021

Copy link
Copy Markdown
Member

show-multicast is fine by me.

GetMulticastHosts() returns an array of hostnames/addresses discovered via
LLMNR or Multicast DNS. It does not trigger any discovery on its own.
Instead, it simply returns whatever is already in resolved's cache.
@daandemeyer daandemeyer changed the title resolvectl: Add list-discovered verb to list discovered LLMNR/mDNS hosts resolvectl: Add show-multicast verb to show discovered LLMNR/mDNS hosts Jan 30, 2021
@daandemeyer

Copy link
Copy Markdown
Collaborator Author

Renamed the verb to show-multicast and the D-Bus method to GetMulticastHosts().

daandemeyer added a commit to daandemeyer/systemd that referenced this pull request Jan 30, 2021
I think this formatting was originally used because it simplified
adding new options to the help messages. However, these days, most
tools their help message end with "\nSee the %s for details.\n" so
the final line almost never has to be edited which eliminates the
benefit of the custom formatting used for printf() help messages.
Let's make things more consistent and use the same formatting for
printf() help messages that we use everywhere else.

Prompted by systemd#18355 (comment)
yuwata pushed a commit that referenced this pull request Jan 31, 2021
I think this formatting was originally used because it simplified
adding new options to the help messages. However, these days, most
tools their help message end with "\nSee the %s for details.\n" so
the final line almost never has to be edited which eliminates the
benefit of the custom formatting used for printf() help messages.
Let's make things more consistent and use the same formatting for
printf() help messages that we use everywhere else.

Prompted by #18355 (comment)
Comment thread src/resolve/resolvectl.c Resolved
Comment thread src/resolve/resolvectl.c Resolved
The show-multicast verb calls the GetMulticastHosts() D-Bus method
and displays all its results formatted into a table.
@daandemeyer

Copy link
Copy Markdown
Collaborator Author

@keszybz @yuwata Thanks for the reviews. Fixed all the comments I think. PTAL.

@keszybz
keszybz merged commit 5623600 into systemd:main Feb 4, 2021
@poettering

Copy link
Copy Markdown
Member

hmmpf, i am not sure i like this concept. the thing is that people might believe the shown list is comprehensive, but it really is not. it's just what is cached, i.e. what was recently asked for or recently announced. there might be a lot more on the network, and there's no guarantee whatsoever that this is complete.

there's also the problem that dbus sucks for passing along huge amounts of data, and my guess is that a fully populated cache might hit the dbus message size limits if you have plenty of interfaces.

quite frankly, i#d drop this again the way this is.

what we can add is a "dump-cache" verb or so, (or "show-cache") but it should be able to dump all kinds of RRs and then hook this up with --type= and --class= to do filtering, as well as --interface= and --protocol= to limit things. You could then do "resolvectl dump-cache --protocol=mdns --type=A --type=AAAA" to get the data this command currently shows.

And i figure to make this work via dbus one approach could be to serialize the RR data into JSON, and then pass a memfd over to it.

sorry i didn't review this earlier. I know I am a bit late.

But i don't think we should leave this in as it is right now.

@poettering

Copy link
Copy Markdown
Member

my key point really is: it needs to have "cache" in the name, so that people understand this is just cached info and not comprehensive. even if we wanted to neither llmnr nor mdns actually provide a way to get a complete dump of hosts. they simply don't describe a query like that.

@daandemeyer

daandemeyer commented Feb 4, 2021 •

Copy link
Copy Markdown
Collaborator Author

I'm just wondering if show-cache isn't too extensive. I think this approach is 20% of the work for 90% of the benefit. If we exclude DNS, are we really expecting so many entries that we'll reach the D-Bus message limit? I don't mind changing it to use a memory fd but I was thinking that'd be overkill. I really want to keep it to a single verb though without having to pass tons of options just to get the LLMNR/mDNS hosts that resolved knows out. I don't mind renaming to show-multicast-cached if that's better.

@poettering

Copy link
Copy Markdown
Member

well, people run systems with thousands of interface, so yeah, i think this is a real problem.

I'd be fine to add a shortcut like "-M" to mean the same as "--type=a --type=aaaa --protocol=mdns --protocol=llmnr" or so, then you could do "resolvectl show-cache -M", which should be shorter than your current verb

@daandemeyer

Copy link
Copy Markdown
Collaborator Author

I was assuming we'd hit resolved's cache size limit long before we'd ever run into problems. Or does that not apply to LLMNR/mDNS?

But OK, I'll implement the full cache dump version when I get some time

Yamakuzure pushed a commit to elogind/elogind that referenced this pull request Aug 25, 2021
I think this formatting was originally used because it simplified
adding new options to the help messages. However, these days, most
tools their help message end with "\nSee the %s for details.\n" so
the final line almost never has to be edited which eliminates the
benefit of the custom formatting used for printf() help messages.
Let's make things more consistent and use the same formatting for
printf() help messages that we use everywhere else.

Prompted by systemd/systemd#18355 (comment)
@daandemeyer
daandemeyer deleted the resolved-discover branch October 12, 2021 08:44
julian-klode pushed a commit to ubuntu/stubble that referenced this pull request Aug 1, 2025
I think this formatting was originally used because it simplified
adding new options to the help messages. However, these days, most
tools their help message end with "\nSee the %s for details.\n" so
the final line almost never has to be edited which eliminates the
benefit of the custom formatting used for printf() help messages.
Let's make things more consistent and use the same formatting for
printf() help messages that we use everywhere else.

Prompted by systemd/systemd#18355 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

resolvectl: Add a way to show resolved's cache entries

7 participants