X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fnetwork%2Fnetworkd-manager.c;h=2a0d5342daeb4672f84bc9aa3fda69e71d0cc2ea;hb=ac78d81a35fae1c10464992dac25f1527a05cbc9;hp=8bdc60f19c980dd940a3820a9ece37f6757d1ba4;hpb=fbbeb65a93e2f90f6576001b69def877cd98722d;p=elogind.git diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index 8bdc60f19..2a0d5342d 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -19,11 +19,13 @@ along with systemd; If not, see . ***/ -#include +#include #include +#include "conf-parser.h" #include "path-util.h" #include "networkd.h" +#include "network-internal.h" #include "libudev-private.h" #include "udev-util.h" #include "rtnl-util.h" @@ -81,7 +83,7 @@ int manager_new(Manager **ret) { if (!m) return -ENOMEM; - m->state_file = strdup("/run/systemd/network/state"); + m->state_file = strdup("/run/systemd/netif/state"); if (!m->state_file) return -ENOMEM; @@ -411,102 +413,13 @@ int manager_bus_listen(Manager *m) { return 0; } -static void append_dns(FILE *f, struct in_addr *dns, unsigned char family, unsigned *count) { - char buf[INET6_ADDRSTRLEN]; - const char *address; - - address = inet_ntop(family, dns, buf, INET6_ADDRSTRLEN); - if (!address) { - log_warning("Invalid DNS address. Ignoring."); - return; - } - - if (*count == MAXNS) - fputs("# Too many DNS servers configured, the following entries " - "will be ignored\n", f); - - fprintf(f, "nameserver %s\n", address); - - (*count) ++; -} - -int manager_update_resolv_conf(Manager *m) { - _cleanup_free_ char *temp_path = NULL; - _cleanup_fclose_ FILE *f = NULL; - Link *link; - Iterator i; - unsigned count = 0; - const char *domainname = NULL; - int r; - - assert(m); - - r = fopen_temporary("/run/systemd/network/resolv.conf", &f, &temp_path); - if (r < 0) - return r; - - fchmod(fileno(f), 0644); - - fputs("# This file is managed by systemd-networkd(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); - - HASHMAP_FOREACH(link, m->links, i) { - if (link->dhcp_lease) { - struct in_addr *nameservers; - size_t nameservers_size; - - if (link->network->dhcp_dns) { - r = sd_dhcp_lease_get_dns(link->dhcp_lease, &nameservers, &nameservers_size); - if (r >= 0) { - unsigned j; - - for (j = 0; j < nameservers_size; j++) - append_dns(f, &nameservers[j], AF_INET, &count); - } - } - - if (link->network->dhcp_domainname && !domainname) { - r = sd_dhcp_lease_get_domainname(link->dhcp_lease, &domainname); - if (r >= 0) - fprintf(f, "domain %s\n", domainname); - } - } - } - - HASHMAP_FOREACH(link, m->links, i) { - if (link->network && link->network->dns) { - Address *address; - Iterator j; - - SET_FOREACH(address, link->network->dns, j) { - append_dns(f, &address->in_addr.in, - address->family, &count); - } - } - } - - fflush(f); - - if (ferror(f) || rename(temp_path, "/run/systemd/network/resolv.conf") < 0) { - r = -errno; - unlink("/run/systemd/network/resolv.conf"); - unlink(temp_path); - return r; - } - - return 0; -} - int manager_save(Manager *m) { Link *link; Iterator i; _cleanup_free_ char *temp_path = NULL; _cleanup_fclose_ FILE *f = NULL; - const char *oper_state = "unknown"; - bool dormant = false, carrier = false; + LinkOperationalState operstate = LINK_OPERSTATE_UNKNOWN; + const char *operstate_str; int r; assert(m); @@ -516,16 +429,12 @@ int manager_save(Manager *m) { if (link->flags & IFF_LOOPBACK) continue; - if (link_has_carrier(link->flags, link->operstate)) - carrier = true; - else if (link->operstate == IF_OPER_DORMANT) - dormant = true; + if (link->operstate > operstate) + operstate = link->operstate; } - if (carrier) - oper_state = "carrier"; - else if (dormant) - oper_state = "dormant"; + operstate_str = link_operstate_to_string(operstate); + assert(operstate_str); r = fopen_temporary(m->state_file, &f, &temp_path); if (r < 0) @@ -535,7 +444,7 @@ int manager_save(Manager *m) { fprintf(f, "# This is private data. Do not parse.\n" - "OPER_STATE=%s\n", oper_state); + "OPER_STATE=%s\n", operstate_str); fflush(f);