chiark / gitweb /
No need to canonicalize fixed paths
[elogind.git] / src / network / networkd-network.c
index e0e3878f75bb79b4addc0452a67002a5b14e1a66..1606042264b584758f9a7cd7b80076d17c1acc4b 100644 (file)
 #include "path-util.h"
 #include "conf-files.h"
 #include "conf-parser.h"
+#include "util.h"
 
 static int network_load_one(Manager *manager, const char *filename) {
         _cleanup_network_free_ Network *network = NULL;
         _cleanup_fclose_ FILE *file = NULL;
+        Route *route;
+        Address *address;
         int r;
 
         assert(manager);
@@ -70,6 +73,29 @@ static int network_load_one(Manager *manager, const char *filename) {
         }
 
         LIST_PREPEND(networks, manager->networks, network);
+
+        LIST_FOREACH(static_routes, route, network->static_routes) {
+                if (!route->family) {
+                        log_warning("Route section without Gateway field configured in %s. "
+                                    "Ignoring", filename);
+                        return 0;
+                }
+
+                if (route->dst_family && route->family != route->dst_family) {
+                        log_warning("Route section with conflicting Gateway and Destination address "
+                                    "family configured in %s. Ignoring", filename);
+                        return 0;
+                }
+        }
+
+        LIST_FOREACH(static_addresses, address, network->static_addresses) {
+                if (!address->family) {
+                        log_warning("Address section without Address field configured in %s. "
+                                    "Ignoring", filename);
+                        return 0;
+                }
+        }
+
         network = NULL;
 
         return 0;
@@ -77,7 +103,8 @@ static int network_load_one(Manager *manager, const char *filename) {
 
 int network_load(Manager *manager) {
         Network *network;
-        char **files, **f;
+        _cleanup_strv_free_ char **files = NULL;
+        char **f;
         int r;
 
         assert(manager);
@@ -85,7 +112,7 @@ int network_load(Manager *manager) {
         while ((network = manager->networks))
                 network_free(network);
 
-        r = conf_files_list_strv(&files, ".network", NULL, (const char **)manager->network_dirs);
+        r = conf_files_list_strv(&files, ".network", NULL, network_dirs);
         if (r < 0) {
                 log_error("Failed to enumerate network files: %s", strerror(-r));
                 return r;
@@ -97,8 +124,6 @@ int network_load(Manager *manager) {
                         return r;
         }
 
-        strv_free(files);
-
         return 0;
 }
 
@@ -128,7 +153,8 @@ void network_free(Network *network) {
         hashmap_free(network->addresses_by_section);
         hashmap_free(network->routes_by_section);
 
-        LIST_REMOVE(networks, network->manager->networks, network);
+        if (network->manager && network->manager->networks)
+                LIST_REMOVE(networks, network->manager->networks, network);
 
         free(network);
 }