chiark / gitweb /
networkd: fix several Address entries in [Network] section
[elogind.git] / src / network / networkd-manager.c
index 6a57a80..1dc7e88 100644 (file)
@@ -31,7 +31,7 @@ int manager_new(Manager **ret) {
         if (!m)
                 return -ENOMEM;
 
-        r = sd_event_new(&m->event);
+        r = sd_event_default(&m->event);
         if (r < 0)
                 return r;
 
@@ -51,6 +51,10 @@ int manager_new(Manager **ret) {
         if (!m->links)
                 return -ENOMEM;
 
+        m->bridges = hashmap_new(string_hash_func, string_compare_func);
+        if (!m->bridges)
+                return -ENOMEM;
+
         LIST_HEAD_INIT(m->networks);
 
         m->network_dirs = strv_new("/etc/systemd/network/",
@@ -73,17 +77,53 @@ int manager_new(Manager **ret) {
 }
 
 void manager_free(Manager *m) {
+        Network *network;
+        Bridge *bridge;
+        Link *link;
+
         udev_monitor_unref(m->udev_monitor);
         udev_unref(m->udev);
         sd_event_source_unref(m->udev_event_source);
         sd_event_unref(m->event);
+
+        while ((network = m->networks))
+                network_free(network);
+
+        while ((link = hashmap_first(m->links)))
+                link_free(link);
         hashmap_free(m->links);
+
+        while ((bridge = hashmap_first(m->bridges)))
+                bridge_free(bridge);
+        hashmap_free(m->bridges);
+
         strv_free(m->network_dirs);
         sd_rtnl_unref(m->rtnl);
 
         free(m);
 }
 
+int manager_load_config(Manager *m) {
+        int r;
+
+        /* update timestamp */
+        paths_check_timestamp(m->network_dirs, &m->network_dirs_ts_usec, true);
+
+        r = bridge_load(m);
+        if (r < 0)
+                return r;
+
+        r = network_load(m);
+        if (r < 0)
+                return r;
+
+        return 0;
+}
+
+bool manager_should_reload(Manager *m) {
+        return paths_check_timestamp(m->network_dirs, &m->network_dirs_ts_usec, false);
+}
+
 static int manager_process_link(Manager *m, struct udev_device *device) {
         Link *link;
         int r;
@@ -91,6 +131,8 @@ static int manager_process_link(Manager *m, struct udev_device *device) {
         if (streq_ptr(udev_device_get_action(device), "remove")) {
                 uint64_t ifindex;
 
+                log_debug("Link removed: %s", udev_device_get_sysname(device));
+
                 ifindex = udev_device_get_ifindex(device);
                 link = hashmap_get(m->links, &ifindex);
                 if (!link)
@@ -98,6 +140,8 @@ static int manager_process_link(Manager *m, struct udev_device *device) {
 
                 link_free(link);
         } else {
+                log_debug("New link: %s", udev_device_get_sysname(device));
+
                 r = link_add(m, device);
                 if (r < 0) {
                         log_error("Could not handle link %s: %s",
@@ -126,10 +170,6 @@ int manager_udev_enumerate_links(Manager *m) {
         if (r < 0)
                 goto finish;
 
-        r = udev_enumerate_add_match_tag(e, "systemd-networkd");
-        if (r < 0)
-                goto finish;
-
         r = udev_enumerate_scan_devices(e);
         if (r < 0)
                 goto finish;
@@ -187,12 +227,6 @@ int manager_udev_listen(Manager *m) {
                 return r;
         }
 
-        r = udev_monitor_filter_add_match_tag(m->udev_monitor, "systemd-networkd");
-        if (r < 0) {
-                log_error("Could not add udev monitor filter: %s", strerror(-r));
-                return r;
-        }
-
         r = udev_monitor_enable_receiving(m->udev_monitor);
         if (r < 0) {
                 log_error("Could not enable udev monitor");
@@ -208,3 +242,13 @@ int manager_udev_listen(Manager *m) {
 
         return 0;
 }
+
+int manager_rtnl_listen(Manager *m) {
+        int r;
+
+        r = sd_rtnl_attach_event(m->rtnl, m->event, 0);
+        if (r < 0)
+                return r;
+
+        return 0;
+}