networkd-network.c revision f46685a4c0780173e5291fb7c3caa1c35cb1d0af
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek This file is part of systemd.
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek Copyright 2013 Tom Gundersen <teg@jklm.no>
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek systemd is free software; you can redistribute it and/or modify it
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek under the terms of the GNU Lesser General Public License as published by
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek the Free Software Foundation; either version 2.1 of the License, or
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek (at your option) any later version.
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek systemd is distributed in the hope that it will be useful, but
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek WITHOUT ANY WARRANTY; without even the implied warranty of
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek Lesser General Public License for more details.
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek You should have received a copy of the GNU Lesser General Public License
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek along with systemd; If not, see <http://www.gnu.org/licenses/>.
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmekstatic int network_load_one(Manager *manager, const char *filename) {
73f860db9893deab6aebceb53dd7d0deb662e832Zbigniew Jędrzejewski-Szmek _cleanup_network_free_ Network *network = NULL;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek _cleanup_fclose_ FILE *file = NULL;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek LIST_HEAD_INIT(network->static_addresses);
603938e0a9b5379984d7397e3cf81683c0037a53Lennart Poettering network->addresses_by_section = hashmap_new(uint64_hash_func, uint64_compare_func);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek network->routes_by_section = hashmap_new(uint64_hash_func, uint64_compare_func);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (!network->routes_by_section)
eb56eb9b40950f1edcffdb7313f8de4f8572a6d5Michal Schmidt r = config_parse(NULL, filename, file, "Match\0Network\0Address\0Route\0", config_item_perf_lookup,
eb56eb9b40950f1edcffdb7313f8de4f8572a6d5Michal Schmidt (void*) network_gperf_lookup, false, false, network);
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering log_warning("Could not parse config file %s: %s", filename, strerror(-r));
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering LIST_PREPEND(networks, manager->networks, network);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek LIST_FOREACH(static_routes, route, network->static_routes) {
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering log_warning("Route section without Gateway field configured in %s. "
c099716487df4a4f5394e57e7ca14da1d358166aZbigniew Jędrzejewski-Szmek if (route->dst_family && route->family != route->dst_family) {
c099716487df4a4f5394e57e7ca14da1d358166aZbigniew Jędrzejewski-Szmek log_warning("Route section with conflicting Gateway and Destination address "
c099716487df4a4f5394e57e7ca14da1d358166aZbigniew Jędrzejewski-Szmek "family configured in %s. Ignoring", filename);
c099716487df4a4f5394e57e7ca14da1d358166aZbigniew Jędrzejewski-Szmek LIST_FOREACH(static_addresses, address, network->static_addresses) {
fff40a51ccbb02e8dec4ff2ee505bc84f75e445cZbigniew Jędrzejewski-Szmek log_warning("Address section without Address field configured in %s. "
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmekint network_load(Manager *manager) {
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek _cleanup_strv_free_ char **files = NULL;
c099716487df4a4f5394e57e7ca14da1d358166aZbigniew Jędrzejewski-Szmek while ((network = manager->networks))
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek r = conf_files_list_strv(&files, ".network", NULL, network_dirs);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek log_error("Failed to enumerate network files: %s", strerror(-r));
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmekvoid network_free(Network *network) {
892213bf1fd23e48d64a407ece6e10b07bef1926Zbigniew Jędrzejewski-Szmek while ((address = network->static_addresses))
5e65c93a433447b15180249166f7b3944c3e6156Zbigniew Jędrzejewski-Szmek hashmap_free(network->addresses_by_section);
5e65c93a433447b15180249166f7b3944c3e6156Zbigniew Jędrzejewski-Szmek if (network->manager && network->manager->networks)
23ea3dab15181a3966ec45fa2ccbb81e59d2e0a7Zbigniew Jędrzejewski-Szmek LIST_REMOVE(networks, network->manager->networks, network);
5e65c93a433447b15180249166f7b3944c3e6156Zbigniew Jędrzejewski-Szmekint network_get(Manager *manager, struct udev_device *device, Network **ret) {
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek LIST_FOREACH(networks, network, manager->networks) {
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (net_match_config(network->match_mac, network->match_path,
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek network->match_driver, network->match_type,
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek udev_device_get_sysattr_value(device, "address"),
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek udev_device_get_property_value(device, "ID_PATH"),
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek udev_device_get_devtype(device),
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek udev_device_get_sysname(device))) {
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek log_debug("%s: found matching network '%s'",
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek udev_device_get_sysname(device),
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmekint network_apply(Manager *manager, Network *network, Link *link) {
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmekint config_parse_bridge(const char *unit,
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek r = bridge_get(network->manager, rvalue, &bridge);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek log_syntax(unit, LOG_ERR, filename, line, EINVAL,
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek "Bridge is invalid, ignoring assignment: %s", rvalue);