resolved: filter out our own stub resolvers when parsing servers
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 15 Dec 2021 10:42:59 +0000 (11:42 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 15 Dec 2021 10:47:06 +0000 (11:47 +0100)
commit0ad4efb14beea9148838a0d974821e3b98cafc47
tree241f08e7b21fe542871588544d302cf9de135043
parent9d84fdec287532c0d58914c64988b3027902c4e7
resolved: filter out our own stub resolvers when parsing servers

We get "upstream" dns server config from ~three places: /etc/resolv.conf,
config files, and runtime config via dbus. With this commit, we'll filter out
our own stub listeners if they are configured in either of the first two
sources. For /etc/resolv.conf this is done quitely, and for our own config
files, a LOG_INFO message is emitted, since this is a small inconsistency in
the config.

Setting loops like this over dbus is still allowed. The reason is that in the
past we didn't treat this as an error, and if we were to start responding with
an error, we could break a scenario that worked previously. E.g. NM sends us a
list of servers, and one happens to be the our own. We would just not use that
stub server before, but it'd still be shown in the dbus properties and such.
We would have to return error for the whole message, also rejecting the other
valid servers. I think it's easier to just keep that part unchanged.

Test case:
$ ls -l /etc/resolv.conf
-rw-r--r-- 1 root root 57 Dec 15 10:26 /etc/resolv.conf
$ cat /etc/resolv.conf
nameserver 192.168.150.1
options edns0 trust-ad
search .
$ cat /etc/systemd/resolved.conf.d/stub.conf
[Resolve]
DNSStubListenerExtra=192.168.150.1

$ resolvectl
...
Global
    resolv.conf mode: foreign
         DNS Servers: 192.168.150.1
Fallback DNS Servers: ...
(with the patch):
Global
    resolv.conf mode: foreign
Fallback DNS Servers: ...
src/resolve/resolved-conf.c
src/resolve/resolved-conf.h
src/resolve/resolved-manager.c
src/resolve/resolved-manager.h
src/resolve/resolved-resolv-conf.c