chiark / gitweb /
event: hook up sd-event with the service watchdog logic
[elogind.git] / src / network / networkd-network.c
index 69c55edb8fe3ef588bb5d13a45a3817cb332c581..ae8d4d160d9259585f4c8f6b74a9079079048e7f 100644 (file)
@@ -42,9 +42,24 @@ static int network_load_one(Manager *manager, const char *filename) {
         if (!network)
                 return log_oom();
 
+        network->manager = manager;
+
         LIST_HEAD_INIT(network->addresses);
+        LIST_HEAD_INIT(network->routes);
+
+        network->addresses_by_section = hashmap_new(uint64_hash_func, uint64_compare_func);
+        if (!network->addresses_by_section)
+                return log_oom();
+
+        network->routes_by_section = hashmap_new(uint64_hash_func, uint64_compare_func);
+        if (!network->routes_by_section)
+                return log_oom();
+
+        network->filename = strdup(filename);
+        if (!network->filename)
+                return log_oom();
 
-        r = config_parse(NULL, filename, file, "Match\0Network\0", config_item_perf_lookup,
+        r = config_parse(NULL, filename, file, "Match\0Network\0Address\0Route\0", config_item_perf_lookup,
                         (void*) network_gperf_lookup, false, false, network);
         if (r < 0) {
                 log_warning("Could not parse config file %s: %s", filename, strerror(-r));
@@ -52,10 +67,6 @@ static int network_load_one(Manager *manager, const char *filename) {
         } else
                 log_debug("Parsed configuration file %s", filename);
 
-        network->filename = strdup(filename);
-        if (!network->filename)
-                return log_oom();
-
         LIST_PREPEND(networks, manager->networks, network);
         network = NULL;
 
@@ -72,9 +83,6 @@ int network_load(Manager *manager) {
         while ((network = manager->networks))
                 network_free(network);
 
-        /* update timestamp */
-        paths_check_timestamp(manager->network_dirs, &manager->network_dirs_ts_usec, true);
-
         r = conf_files_list_strv(&files, ".network", NULL, (const char **)manager->network_dirs);
         if (r < 0) {
                 log_error("failed to enumerate network files: %s", strerror(-r));
@@ -92,10 +100,6 @@ int network_load(Manager *manager) {
         return 0;
 }
 
-bool network_should_reload(Manager *manager) {
-        return paths_check_timestamp(manager->network_dirs, &manager->network_dirs_ts_usec, false);
-}
-
 void network_free(Network *network) {
         Route *route;
         Address *address;
@@ -119,6 +123,9 @@ void network_free(Network *network) {
         while ((address = network->addresses))
                 address_free(address);
 
+        hashmap_free(network->addresses_by_section);
+        hashmap_free(network->routes_by_section);
+
         LIST_REMOVE(networks, network->manager->networks, network);
 
         free(network);
@@ -131,8 +138,8 @@ int network_get(Manager *manager, struct udev_device *device, Network **ret) {
         assert(device);
         assert(ret);
 
-        if (network_should_reload(manager))
-                network_load(manager);
+        if (manager_should_reload(manager))
+                manager_load_config(manager);
 
         LIST_FOREACH(networks, network, manager->networks) {
                 if (net_match_config(network->match_mac, network->match_path,
@@ -157,30 +164,47 @@ int network_get(Manager *manager, struct udev_device *device, Network **ret) {
 }
 
 int network_apply(Manager *manager, Network *network, Link *link) {
-        Address *address;
-        Route *route;
         int r;
 
-        log_info("Network '%s' being applied to link '%u'",
-                        network->description, (unsigned) link->ifindex);
+        log_info("Network '%s' being applied to link '%s'",
+                        network->description, link->ifname);
 
         link->network = network;
 
-        LIST_FOREACH(addresses, address, network->addresses) {
-                r = address_configure(manager, address, link);
-                if (r < 0)
-                        return r;
-        }
-
-        r = link_up(manager, link);
+        r = link_configure(link);
         if (r < 0)
                 return r;
 
-        LIST_FOREACH(routes, route, network->routes) {
-                r = route_configure(manager, route, link);
-                if (r < 0)
-                        return r;
+        return 0;
+}
+
+int config_parse_bridge(const char *unit,
+                const char *filename,
+                unsigned line,
+                const char *section,
+                unsigned section_line,
+                const char *lvalue,
+                int ltype,
+                const char *rvalue,
+                void *data,
+                void *userdata) {
+        Network *network = userdata;
+        Bridge *bridge;
+        int r;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+        assert(data);
+
+        r = bridge_get(network->manager, rvalue, &bridge);
+        if (r < 0) {
+                log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+                           "Bridge is invalid, ignoring assignment: %s", rvalue);
+                return 0;
         }
 
+        network->bridge = bridge;
+
         return 0;
 }