X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fnetwork%2Fnetworkd-network.c;h=0326fe675bae06e3c11fae58142cd7abd80d44e7;hp=ae8d4d160d9259585f4c8f6b74a9079079048e7f;hb=b3070dc0258831c7e2b13624f75fa3dbd80d9833;hpb=02b59d57e0c08231645120077f651151f5bb2bab diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index ae8d4d160..0326fe675 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -24,12 +24,18 @@ #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); + assert(filename); + file = fopen(filename, "re"); if (!file) { if (errno == ENOENT) @@ -44,8 +50,8 @@ static int network_load_one(Manager *manager, const char *filename) { network->manager = manager; - LIST_HEAD_INIT(network->addresses); - LIST_HEAD_INIT(network->routes); + LIST_HEAD_INIT(network->static_addresses); + LIST_HEAD_INIT(network->static_routes); network->addresses_by_section = hashmap_new(uint64_hash_func, uint64_compare_func); if (!network->addresses_by_section) @@ -64,10 +70,32 @@ static int network_load_one(Manager *manager, const char *filename) { if (r < 0) { log_warning("Could not parse config file %s: %s", filename, strerror(-r)); return r; - } else - log_debug("Parsed configuration file %s", 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; @@ -75,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 +114,7 @@ int network_load(Manager *manager) { 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)); + log_error("Failed to enumerate network files: %s", strerror(-r)); return r; } @@ -95,8 +124,6 @@ int network_load(Manager *manager) { return r; } - strv_free(files); - return 0; } @@ -117,16 +144,17 @@ void network_free(Network *network) { free(network->description); - while ((route = network->routes)) + while ((route = network->static_routes)) route_free(route); - while ((address = network->addresses)) + while ((address = network->static_addresses)) address_free(address); 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); } @@ -150,9 +178,9 @@ int network_get(Manager *manager, struct udev_device *device, Network **ret) { udev_device_get_driver(device), udev_device_get_devtype(device), udev_device_get_sysname(device))) { - log_debug("Network file %s applies to link %s", - network->filename, - udev_device_get_sysname(device)); + log_debug("%s: found matching network '%s'", + udev_device_get_sysname(device), + network->filename); *ret = network; return 0; } @@ -166,9 +194,6 @@ int network_get(Manager *manager, struct udev_device *device, Network **ret) { int network_apply(Manager *manager, Network *network, Link *link) { int r; - log_info("Network '%s' being applied to link '%s'", - network->description, link->ifname); - link->network = network; r = link_configure(link);