network: save DNS servers specified by DBus interface

Also, filter out DNS servers which do not match link ifindex.
This commit is contained in:
Yu Watanabe 2020-07-03 18:34:37 +09:00
parent 6458176514
commit 87d6489776

View file

@ -1425,13 +1425,16 @@ static int manager_connect_rtnl(Manager *m) {
return 0; return 0;
} }
static int ordered_set_put_dns_server(OrderedSet *s, struct in_addr_full *dns) { static int ordered_set_put_dns_server(OrderedSet *s, int ifindex, struct in_addr_full *dns) {
const char *p; const char *p;
int r; int r;
assert(s); assert(s);
assert(dns); assert(dns);
if (dns->ifindex != 0 && dns->ifindex != ifindex)
return 0;
p = in_addr_full_to_string(dns); p = in_addr_full_to_string(dns);
if (!p) if (!p)
return 0; return 0;
@ -1443,7 +1446,7 @@ static int ordered_set_put_dns_server(OrderedSet *s, struct in_addr_full *dns) {
return r; return r;
} }
static int ordered_set_put_dns_servers(OrderedSet *s, struct in_addr_full **dns, unsigned n) { static int ordered_set_put_dns_servers(OrderedSet *s, int ifindex, struct in_addr_full **dns, unsigned n) {
int r, c = 0; int r, c = 0;
unsigned i; unsigned i;
@ -1451,7 +1454,7 @@ static int ordered_set_put_dns_servers(OrderedSet *s, struct in_addr_full **dns,
assert(dns || n == 0); assert(dns || n == 0);
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
r = ordered_set_put_dns_server(s, dns[i]); r = ordered_set_put_dns_server(s, ifindex, dns[i]);
if (r < 0) if (r < 0)
return r; return r;
@ -1558,7 +1561,10 @@ static int manager_save(Manager *m) {
continue; continue;
/* First add the static configured entries */ /* First add the static configured entries */
r = ordered_set_put_dns_servers(dns, link->network->dns, link->network->n_dns); if (link->n_dns != (unsigned) -1)
r = ordered_set_put_dns_servers(dns, link->ifindex, link->dns, link->n_dns);
else
r = ordered_set_put_dns_servers(dns, link->ifindex, link->network->dns, link->network->n_dns);
if (r < 0) if (r < 0)
return r; return r;