X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fnetwork%2Fnetworkd-network.c;h=48131c1f090c1ea7af793a6c158d347771fb4aba;hb=b6e2f3293d0f9a821819d96038eec2a19062151f;hp=e0e3878f75bb79b4addc0452a67002a5b14e1a66;hpb=449f75549247b3b7b073a788f0f099ce6b7c5378;p=elogind.git diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index e0e3878f7..48131c1f0 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -24,10 +24,13 @@ #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); @@ -50,6 +53,10 @@ static int network_load_one(Manager *manager, const char *filename) { LIST_HEAD_INIT(network->static_addresses); LIST_HEAD_INIT(network->static_routes); + network->vlans = hashmap_new(uint64_hash_func, uint64_compare_func); + if (!network->vlans) + return log_oom(); + network->addresses_by_section = hashmap_new(uint64_hash_func, uint64_compare_func); if (!network->addresses_by_section) return log_oom(); @@ -62,7 +69,11 @@ static int network_load_one(Manager *manager, const char *filename) { if (!network->filename) return log_oom(); - r = config_parse(NULL, filename, file, "Match\0Network\0Address\0Route\0", config_item_perf_lookup, + network->dhcp_dns = true; + network->dhcp_hostname = true; + network->dhcp_domainname = true; + + r = config_parse(NULL, filename, file, "Match\0Network\0Address\0Route\0DHCPv4\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)); @@ -70,6 +81,23 @@ 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; + } + } + + 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 +105,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) { 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 +126,6 @@ int network_load(Manager *manager) { return r; } - strv_free(files); - return 0; } @@ -119,6 +146,10 @@ void network_free(Network *network) { free(network->description); + address_free(network->dns); + + hashmap_free(network->vlans); + while ((route = network->static_routes)) route_free(route); @@ -128,7 +159,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); } @@ -140,9 +172,6 @@ int network_get(Manager *manager, struct udev_device *device, Network **ret) { assert(device); assert(ret); - 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, network->match_driver, network->match_type, @@ -174,6 +203,12 @@ int network_apply(Manager *manager, Network *network, Link *link) { if (r < 0) return r; + if (network->dns) { + r = manager_update_resolv_conf(manager); + if (r < 0) + return r; + } + return 0; } @@ -188,7 +223,7 @@ int config_parse_bridge(const char *unit, void *data, void *userdata) { Network *network = userdata; - Bridge *bridge; + NetDev *netdev; int r; assert(filename); @@ -196,14 +231,99 @@ int config_parse_bridge(const char *unit, assert(rvalue); assert(data); - r = bridge_get(network->manager, rvalue, &bridge); + r = netdev_get(network->manager, rvalue, &netdev); if (r < 0) { log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Bridge is invalid, ignoring assignment: %s", rvalue); return 0; } - network->bridge = bridge; + if (netdev->kind != NETDEV_KIND_BRIDGE) { + log_syntax(unit, LOG_ERR, filename, line, EINVAL, + "NetDev is not a bridge, ignoring assignment: %s", rvalue); + return 0; + } + + network->bridge = netdev; + + return 0; +} + +int config_parse_bond(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; + NetDev *netdev; + int r; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + r = netdev_get(network->manager, rvalue, &netdev); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, EINVAL, + "Bond is invalid, ignoring assignment: %s", rvalue); + return 0; + } + + if (netdev->kind != NETDEV_KIND_BOND) { + log_syntax(unit, LOG_ERR, filename, line, EINVAL, + "NetDev is not a bond, ignoring assignment: %s", rvalue); + return 0; + } + + network->bond = netdev; + + return 0; +} + +int config_parse_vlan(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; + NetDev *netdev; + int r; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + r = netdev_get(network->manager, rvalue, &netdev); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, EINVAL, + "VLAN is invalid, ignoring assignment: %s", rvalue); + return 0; + } + + if (netdev->kind != NETDEV_KIND_VLAN) { + log_syntax(unit, LOG_ERR, filename, line, EINVAL, + "NetDev is not a VLAN, ignoring assignment: %s", rvalue); + return 0; + } + + r = hashmap_put(network->vlans, &netdev->vlanid, netdev); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, EINVAL, + "Can not add VLAN to network: %s", rvalue); + return 0; + } return 0; }