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=638343459ce81b09840c5001aa45b64243c5955c;hb=b3070dc0258831c7e2b13624f75fa3dbd80d9833;hpb=f882c247ad59776c3a7753bb963c1f8e2386cb79 diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 638343459..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) @@ -42,21 +48,54 @@ static int network_load_one(Manager *manager, const char *filename) { if (!network) return log_oom(); - LIST_HEAD_INIT(network->addresses); + network->manager = manager; - r = config_parse(NULL, filename, file, "Match\0Network\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)); - return r; - } else - log_debug("Parsed configuration file %s", filename); + 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) + 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\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)); + return r; + } + 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; @@ -64,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); @@ -72,12 +112,9 @@ 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)); + log_error("Failed to enumerate network files: %s", strerror(-r)); return r; } @@ -87,15 +124,9 @@ int network_load(Manager *manager) { return r; } - strv_free(files); - 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; @@ -113,13 +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); - LIST_REMOVE(networks, network->manager->networks, network); + hashmap_free(network->addresses_by_section); + hashmap_free(network->routes_by_section); + + if (network->manager && network->manager->networks) + LIST_REMOVE(networks, network->manager->networks, network); free(network); } @@ -131,8 +166,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, @@ -143,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; } @@ -159,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 '%u'", - network->description, (unsigned) link->ifindex); - link->network = network; r = link_configure(link); @@ -170,3 +202,34 @@ int network_apply(Manager *manager, Network *network, Link *link) { 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; +}