+ /* Add the full list to a set, to filter out duplicates */
+ dns = set_new(dns_server_hash_func, dns_server_compare_func);
+ if (!dns)
+ return -ENOMEM;
+
+ domains = set_new(dns_name_hash_func, dns_name_compare_func);
+ if (!domains)
+ return -ENOMEM;
+
+ /* First add the system-wide servers */
+ LIST_FOREACH(servers, s, m->dns_servers) {
+ r = set_put(dns, s);
+ if (r == -EEXIST)
+ continue;
+ if (r < 0)
+ return r;
+ }
+
+ /* Then, add the per-link servers and domains */
+ HASHMAP_FOREACH(l, m->links, i) {
+ char **domain;
+
+ LIST_FOREACH(servers, s, l->dns_servers) {
+ r = set_put(dns, s);
+ if (r == -EEXIST)
+ continue;
+ if (r < 0)
+ return r;
+ }
+
+ if (!l->unicast_scope)
+ continue;
+
+ STRV_FOREACH(domain, l->unicast_scope->domains) {
+ r = set_put(domains, *domain);
+ if (r == -EEXIST)
+ continue;
+ if (r < 0)
+ return r;
+ }
+ }
+
+ /* If we found nothing, add the fallback servers */
+ if (set_isempty(dns)) {
+ LIST_FOREACH(servers, s, m->fallback_dns_servers) {
+ r = set_put(dns, s);
+ if (r == -EEXIST)
+ continue;
+ if (r < 0)
+ return r;
+ }
+ }
+