X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fresolve%2Fresolved-manager.c;h=c4a5b08773995b26b7c123f66f40fc703b52f6e5;hp=f97989754d5594a087cf89e6595e7664ab341fd3;hb=b37d45c9ab5f645502695e47d268af1a54216e0e;hpb=c4147df156835513c43260a14fc9f7af177f737f diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c index f97989754..c4a5b0877 100644 --- a/src/resolve/resolved-manager.c +++ b/src/resolve/resolved-manager.c @@ -34,6 +34,7 @@ #include "socket-util.h" #include "af-list.h" #include "utf8.h" +#include "fileio-label.h" #include "resolved-dns-domain.h" #include "resolved-conf.h" @@ -720,12 +721,44 @@ static void write_resolv_conf_search(const char *domain, FILE *f, (*count) ++; } +static int write_resolv_conf_contents(FILE *f, Set *dns, Set *domains) { + Iterator i; + + fputs("# This file is managed by systemd-resolved(8). Do not edit.\n#\n" + "# Third party programs must not access this file directly, but\n" + "# only through the symlink at /etc/resolv.conf. To manage\n" + "# resolv.conf(5) in a different way, replace the symlink by a\n" + "# static file or a different symlink.\n\n", f); + + if (set_isempty(dns)) + fputs("# No DNS servers known.\n", f); + else { + DnsServer *s; + unsigned count = 0; + + SET_FOREACH(s, dns, i) + write_resolv_conf_server(s, f, &count); + } + + if (!set_isempty(domains)) { + unsigned length = 0, count = 0; + char *domain; + + fputs("search", f); + SET_FOREACH(domain, domains, i) + write_resolv_conf_search(domain, f, &count, &length); + fputs("\n", f); + } + + return fflush_and_check(f); +} + + int manager_write_resolv_conf(Manager *m) { static const char path[] = "/run/systemd/resolve/resolv.conf"; _cleanup_free_ char *temp_path = NULL; _cleanup_fclose_ FILE *f = NULL; _cleanup_set_free_ Set *dns = NULL, *domains = NULL; - unsigned count = 0; DnsServer *s; Iterator i; Link *l; @@ -737,11 +770,11 @@ int manager_write_resolv_conf(Manager *m) { manager_read_resolv_conf(m); /* Add the full list to a set, to filter out duplicates */ - dns = set_new(dns_server_hash_func, dns_server_compare_func); + dns = set_new(&dns_server_hash_ops); if (!dns) return -ENOMEM; - domains = set_new(dns_name_hash_func, dns_name_compare_func); + domains = set_new(&dns_name_hash_ops); if (!domains) return -ENOMEM; @@ -789,38 +822,13 @@ int manager_write_resolv_conf(Manager *m) { } } - r = fopen_temporary(path, &f, &temp_path); + r = fopen_temporary_label(path, path, &f, &temp_path); if (r < 0) return r; fchmod(fileno(f), 0644); - fputs("# This file is managed by systemd-resolved(8). Do not edit.\n#\n" - "# Third party programs must not access this file directly, but\n" - "# only through the symlink at /etc/resolv.conf. To manage\n" - "# resolv.conf(5) in a different way, replace the symlink by a\n" - "# static file or a different symlink.\n\n", f); - - if (set_isempty(dns)) - fputs("# No DNS servers known.\n", f); - else { - SET_FOREACH(s, dns, i) - write_resolv_conf_server(s, f, &count); - } - - if (!set_isempty(domains)) { - unsigned length = 0; - char *domain; - - count = 0; - - fputs("search", f); - SET_FOREACH(domain, domains, i) - write_resolv_conf_search(domain, f, &count, &length); - fputs("\n", f); - } - - r = fflush_and_check(f); + r = write_resolv_conf_contents(f, dns, domains); if (r < 0) goto fail; @@ -952,7 +960,7 @@ int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret) { * device if the packet came from the local host since it * avoids the routing table in such a case. Let's unset the * interface index in such a case. */ - if (p->ifindex > 0 && manager_ifindex_is_loopback(m, p->ifindex) != 0) + if (p->ifindex == LOOPBACK_IFINDEX) p->ifindex = 0; /* If we don't know the interface index still, we look for the @@ -1687,20 +1695,6 @@ fail: return r; } -int manager_ifindex_is_loopback(Manager *m, int ifindex) { - Link *l; - assert(m); - - if (ifindex <= 0) - return -EINVAL; - - l = hashmap_get(m->links, INT_TO_PTR(ifindex)); - if (l->flags & IFF_LOOPBACK) - return 1; - - return 0; -} - int manager_find_ifindex(Manager *m, int family, const union in_addr_union *in_addr) { LinkAddress *a;