1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-03 01:17:45 +03:00

resolvectl: don't filter loopback DNS server from global DNS server list

"resolvectl status" shows per-link DNS servers separately from global
ones. When querying the global list, it will contain both per-link and
global servers however. Thus, to not show duplicate info we filter all
entries that actually have a non-zero ifindex set (under the assumption
that that's a per-link server).

This doesn't work if people configured 127.0.0.1 as global server
though, as we'll add ifindex 1 to it since
6e32414a66 unconditionally even for global
servers.

Let's address that by excluding entries with ifindex 1 from suppression.
This is safe as resolved ignores loopback ifaces, hence never will have
per-link servers on ifindex 1.

Note that this splits up the "with_ifindex" parameter into a second
parameter "only_global", since they semantically do two different
things. One controls whether we shall expect/parse an ifindex dbus
field. The other controls whether we shall filter all ifindex values set
!= 0. These are effectively always used in conjunction hence making them
the same actually worked. However this is utterly confusing I think,
which as I guess is resulting in the confusion around #25796 (which
removes the whole check)

Replaces: #25796
(cherry picked from commit 889a1b9f4e)
(cherry picked from commit b71ade8779)
This commit is contained in:
Lennart Poettering 2023-01-04 16:36:15 +01:00 committed by Luca Boccassi
parent 87307bfdd1
commit fa04709a3d

View File

@ -1186,7 +1186,13 @@ static int reset_server_features(int argc, char **argv, void *userdata) {
return 0;
}
static int read_dns_server_one(sd_bus_message *m, bool with_ifindex, bool extended, char **ret) {
static int read_dns_server_one(
sd_bus_message *m,
bool with_ifindex, /* read "ifindex" reply that also carries an interface index */
bool extended, /* read "extended" reply, i.e. with port number and server name */
bool only_global, /* suppress entries with an (non-loopback) ifindex set (i.e. which are specific to some interface) */
char **ret) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_free_ char *pretty = NULL;
union in_addr_union a;
@ -1232,8 +1238,8 @@ static int read_dns_server_one(sd_bus_message *m, bool with_ifindex, bool extend
return 1;
}
if (with_ifindex && ifindex != 0) {
/* only show the global ones here */
if (only_global && ifindex > 0 && ifindex != LOOPBACK_IFINDEX) {
/* This one has an (non-loopback) ifindex set, and we were told to suppress those. Hence do so. */
*ret = NULL;
return 1;
}
@ -1263,7 +1269,7 @@ static int map_link_dns_servers_internal(sd_bus *bus, const char *member, sd_bus
for (;;) {
_cleanup_free_ char *pretty = NULL;
r = read_dns_server_one(m, false, extended, &pretty);
r = read_dns_server_one(m, /* with_ifindex= */ false, extended, /* only_global= */ false, &pretty);
if (r < 0)
return r;
if (r == 0)
@ -1296,14 +1302,14 @@ static int map_link_current_dns_server(sd_bus *bus, const char *member, sd_bus_m
assert(m);
assert(userdata);
return read_dns_server_one(m, false, false, userdata);
return read_dns_server_one(m, /* with_ifindex= */ false, /* extended= */ false, /* only_global= */ false, userdata);
}
static int map_link_current_dns_server_ex(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {
assert(m);
assert(userdata);
return read_dns_server_one(m, false, true, userdata);
return read_dns_server_one(m, /* with_ifindex= */ false, /* extended= */ true, /* only_global= */ false, userdata);
}
static int read_domain_one(sd_bus_message *m, bool with_ifindex, char **ret) {
@ -1730,7 +1736,7 @@ static int map_global_dns_servers_internal(sd_bus *bus, const char *member, sd_b
for (;;) {
_cleanup_free_ char *pretty = NULL;
r = read_dns_server_one(m, true, extended, &pretty);
r = read_dns_server_one(m, /* with_ifindex= */ true, extended, /* only_global= */ true, &pretty);
if (r < 0)
return r;
if (r == 0)
@ -1760,17 +1766,11 @@ static int map_global_dns_servers_ex(sd_bus *bus, const char *member, sd_bus_mes
}
static int map_global_current_dns_server(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {
assert(m);
assert(userdata);
return read_dns_server_one(m, true, false, userdata);
return read_dns_server_one(m, /* with_ifindex= */ true, /* extended= */ false, /* only_global= */ true, userdata);
}
static int map_global_current_dns_server_ex(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {
assert(m);
assert(userdata);
return read_dns_server_one(m, true, true, userdata);
return read_dns_server_one(m, /* with_ifindex= */ true, /* extended= */ true, /* only_global= */ true, userdata);
}
static int map_global_domains(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {