networkd-network.c revision 4f882b2a5007e51032459e29d15a86df6b5ea9f4
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering This file is part of systemd.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Copyright 2013 Tom Gundersen <teg@jklm.no>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is free software; you can redistribute it and/or modify it
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering under the terms of the GNU Lesser General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is distributed in the hope that it will be useful, but
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Lesser General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering You should have received a copy of the GNU Lesser General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
f2f1dbe50fea13abadc9c1e845a29031b90b40f3Lennart Poetteringstatic int network_load_one(Manager *manager, const char *filename) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering _cleanup_network_free_ Network *network = NULL;
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering LIST_HEAD_INIT(network->static_addresses);
eed857b71702f8551b46b66b31fa0d08583cf23cLennart Poettering network->addresses_by_section = hashmap_new(uint64_hash_func, uint64_compare_func);
eed857b71702f8551b46b66b31fa0d08583cf23cLennart Poettering network->routes_by_section = hashmap_new(uint64_hash_func, uint64_compare_func);
91b14d6ff362b938a72db17b095ee9903d07381bTom Gundersen r = config_parse(NULL, filename, file, "Match\0Network\0Address\0Route\0DHCPv4\0", config_item_perf_lookup,
0b58db658b5c3f586ac3a837427f1f7fec2abb2eLennart Poettering (void*) network_gperf_lookup, false, false, network);
f4461e5641d53f27d6e76e0607bdaa9c0c58c1f6Lennart Poettering log_warning("Could not parse config file %s: %s", filename, strerror(-r));
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering LIST_PREPEND(networks, manager->networks, network);
9df3ba6c6cb65eecec06f39dfe85a3596cedac4eTom Gundersen LIST_FOREACH(static_routes, route, network->static_routes) {
0b58db658b5c3f586ac3a837427f1f7fec2abb2eLennart Poettering log_warning("Route section without Gateway field configured in %s. "
eed857b71702f8551b46b66b31fa0d08583cf23cLennart Poettering if (route->dst_family && route->family != route->dst_family) {
0b58db658b5c3f586ac3a837427f1f7fec2abb2eLennart Poettering log_warning("Route section with conflicting Gateway and Destination address "
0b58db658b5c3f586ac3a837427f1f7fec2abb2eLennart Poettering "family configured in %s. Ignoring", filename);
0b58db658b5c3f586ac3a837427f1f7fec2abb2eLennart Poettering LIST_FOREACH(static_addresses, address, network->static_addresses) {
eed857b71702f8551b46b66b31fa0d08583cf23cLennart Poettering log_warning("Address section without Address field configured in %s. "
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering r = conf_files_list_strv(&files, ".network", NULL, network_dirs);
91b14d6ff362b938a72db17b095ee9903d07381bTom Gundersen log_error("Failed to enumerate network files: %s", strerror(-r));
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart Poettering hashmap_free(network->addresses_by_section);
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart Poettering hashmap_free(network->routes_by_section);
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart Poettering if (network->manager && network->manager->networks)
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart Poettering LIST_REMOVE(networks, network->manager->networks, network);
eed857b71702f8551b46b66b31fa0d08583cf23cLennart Poetteringint network_get(Manager *manager, struct udev_device *device, Network **ret) {
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart Poettering LIST_FOREACH(networks, network, manager->networks) {
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart Poettering if (net_match_config(network->match_mac, network->match_path,
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart Poettering network->match_driver, network->match_type,
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart Poettering udev_device_get_sysattr_value(device, "address"),
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart Poettering udev_device_get_property_value(device, "ID_PATH"),
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart Poettering log_debug("%s: found matching network '%s'",
0b58db658b5c3f586ac3a837427f1f7fec2abb2eLennart Poetteringint network_apply(Manager *manager, Network *network, Link *link) {
6bb2c08597c999c429e889cd2403b2fef5f3e1a0Lennart Poettering r = bridge_get(network->manager, rvalue, &bridge);
b652d4a2099d1c167584dcc1d179d47c58dc38a2Lennart Poettering log_syntax(unit, LOG_ERR, filename, line, EINVAL,
6bb2c08597c999c429e889cd2403b2fef5f3e1a0Lennart Poettering "Bridge is invalid, ignoring assignment: %s", rvalue);