networkd-network.c revision f46685a4c0780173e5291fb7c3caa1c35cb1d0af
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek/***
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek This file is part of systemd.
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek Copyright 2013 Tom Gundersen <teg@jklm.no>
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
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
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
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-Szmek***/
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek#include "networkd.h"
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek#include "net-util.h"
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek#include "path-util.h"
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek#include "conf-files.h"
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek#include "conf-parser.h"
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek#include "util.h"
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
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 Route *route;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek Address *address;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek int r;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek assert(manager);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek assert(filename);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek file = fopen(filename, "re");
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (!file) {
892213bf1fd23e48d64a407ece6e10b07bef1926Zbigniew Jędrzejewski-Szmek if (errno == ENOENT)
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek return 0;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek else
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering return errno;
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering }
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek network = new0(Network, 1);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (!network)
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek return log_oom();
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek network->manager = manager;
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek LIST_HEAD_INIT(network->static_addresses);
603938e0a9b5379984d7397e3cf81683c0037a53Lennart Poettering LIST_HEAD_INIT(network->static_routes);
603938e0a9b5379984d7397e3cf81683c0037a53Lennart Poettering
603938e0a9b5379984d7397e3cf81683c0037a53Lennart Poettering network->addresses_by_section = hashmap_new(uint64_hash_func, uint64_compare_func);
603938e0a9b5379984d7397e3cf81683c0037a53Lennart Poettering if (!network->addresses_by_section)
603938e0a9b5379984d7397e3cf81683c0037a53Lennart Poettering return log_oom();
603938e0a9b5379984d7397e3cf81683c0037a53Lennart Poettering
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)
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek return log_oom();
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering
29a5ca9baa58e55c4d9e1d008cdd014aa9c3c3e1Lennart Poettering network->filename = strdup(filename);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (!network->filename)
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek return log_oom();
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
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 if (r < 0) {
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering log_warning("Could not parse config file %s: %s", filename, strerror(-r));
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek return r;
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering }
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering LIST_PREPEND(networks, manager->networks, network);
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek LIST_FOREACH(static_routes, route, network->static_routes) {
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering if (!route->family) {
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering log_warning("Route section without Gateway field configured in %s. "
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek "Ignoring", filename);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek return 0;
c099716487df4a4f5394e57e7ca14da1d358166aZbigniew Jędrzejewski-Szmek }
c099716487df4a4f5394e57e7ca14da1d358166aZbigniew Jędrzejewski-Szmek
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 return 0;
c099716487df4a4f5394e57e7ca14da1d358166aZbigniew Jędrzejewski-Szmek }
c099716487df4a4f5394e57e7ca14da1d358166aZbigniew Jędrzejewski-Szmek }
c099716487df4a4f5394e57e7ca14da1d358166aZbigniew Jędrzejewski-Szmek
c099716487df4a4f5394e57e7ca14da1d358166aZbigniew Jędrzejewski-Szmek LIST_FOREACH(static_addresses, address, network->static_addresses) {
c099716487df4a4f5394e57e7ca14da1d358166aZbigniew Jędrzejewski-Szmek if (!address->family) {
fff40a51ccbb02e8dec4ff2ee505bc84f75e445cZbigniew Jędrzejewski-Szmek log_warning("Address section without Address field configured in %s. "
fff40a51ccbb02e8dec4ff2ee505bc84f75e445cZbigniew Jędrzejewski-Szmek "Ignoring", filename);
fff40a51ccbb02e8dec4ff2ee505bc84f75e445cZbigniew Jędrzejewski-Szmek return 0;
fff40a51ccbb02e8dec4ff2ee505bc84f75e445cZbigniew Jędrzejewski-Szmek }
fff40a51ccbb02e8dec4ff2ee505bc84f75e445cZbigniew Jędrzejewski-Szmek }
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek network = NULL;
e0aa3726103448097e5ad7cc6f427e142103a321Zbigniew Jędrzejewski-Szmek
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek return 0;
c099716487df4a4f5394e57e7ca14da1d358166aZbigniew Jędrzejewski-Szmek}
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidt
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmekint network_load(Manager *manager) {
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek Network *network;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek _cleanup_strv_free_ char **files = NULL;
175a3d25d0e8596d4ba0759aea3f89ee228e7d6dLennart Poettering char **f;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek int r;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek assert(manager);
c099716487df4a4f5394e57e7ca14da1d358166aZbigniew Jędrzejewski-Szmek
c099716487df4a4f5394e57e7ca14da1d358166aZbigniew Jędrzejewski-Szmek while ((network = manager->networks))
c099716487df4a4f5394e57e7ca14da1d358166aZbigniew Jędrzejewski-Szmek network_free(network);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek r = conf_files_list_strv(&files, ".network", NULL, network_dirs);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (r < 0) {
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek log_error("Failed to enumerate network files: %s", strerror(-r));
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek return r;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek }
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering STRV_FOREACH_BACKWARDS(f, files) {
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering r = network_load_one(manager, *f);
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering if (r < 0)
2c408cb6276e3b8d18fb4e2a81a1128d8bbaa70dLennart Poettering return r;
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering }
29a5ca9baa58e55c4d9e1d008cdd014aa9c3c3e1Lennart Poettering
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek return 0;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek}
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmekvoid network_free(Network *network) {
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek Route *route;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek Address *address;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
23ea3dab15181a3966ec45fa2ccbb81e59d2e0a7Zbigniew Jędrzejewski-Szmek if (!network)
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering return;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering free(network->filename);
7fd1b19bc9e9f5574f2877936b8ac267c7706947Harald Hoyer
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering free(network->match_mac);
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering free(network->match_path);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek free(network->match_driver);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek free(network->match_type);
892213bf1fd23e48d64a407ece6e10b07bef1926Zbigniew Jędrzejewski-Szmek free(network->match_name);
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering
5e65c93a433447b15180249166f7b3944c3e6156Zbigniew Jędrzejewski-Szmek free(network->description);
5b84559a76f30755019d6a0e6b2ccc9bbe0b3c56Lennart Poettering
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering while ((route = network->static_routes))
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering route_free(route);
5e65c93a433447b15180249166f7b3944c3e6156Zbigniew Jędrzejewski-Szmek
892213bf1fd23e48d64a407ece6e10b07bef1926Zbigniew Jędrzejewski-Szmek while ((address = network->static_addresses))
5e65c93a433447b15180249166f7b3944c3e6156Zbigniew Jędrzejewski-Szmek address_free(address);
5e65c93a433447b15180249166f7b3944c3e6156Zbigniew Jędrzejewski-Szmek
5e65c93a433447b15180249166f7b3944c3e6156Zbigniew Jędrzejewski-Szmek hashmap_free(network->addresses_by_section);
7fd1b19bc9e9f5574f2877936b8ac267c7706947Harald Hoyer hashmap_free(network->routes_by_section);
5e65c93a433447b15180249166f7b3944c3e6156Zbigniew Jędrzejewski-Szmek
5e65c93a433447b15180249166f7b3944c3e6156Zbigniew Jędrzejewski-Szmek if (network->manager && network->manager->networks)
23ea3dab15181a3966ec45fa2ccbb81e59d2e0a7Zbigniew Jędrzejewski-Szmek LIST_REMOVE(networks, network->manager->networks, network);
5e65c93a433447b15180249166f7b3944c3e6156Zbigniew Jędrzejewski-Szmek
5e65c93a433447b15180249166f7b3944c3e6156Zbigniew Jędrzejewski-Szmek free(network);
5e65c93a433447b15180249166f7b3944c3e6156Zbigniew Jędrzejewski-Szmek}
5e65c93a433447b15180249166f7b3944c3e6156Zbigniew Jędrzejewski-Szmek
5e65c93a433447b15180249166f7b3944c3e6156Zbigniew Jędrzejewski-Szmekint network_get(Manager *manager, struct udev_device *device, Network **ret) {
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek Network *network;
23ea3dab15181a3966ec45fa2ccbb81e59d2e0a7Zbigniew Jędrzejewski-Szmek
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek assert(manager);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek assert(device);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek assert(ret);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
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 network->match_name,
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_driver(device),
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),
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering network->filename);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek *ret = network;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek return 0;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek }
23ea3dab15181a3966ec45fa2ccbb81e59d2e0a7Zbigniew Jędrzejewski-Szmek }
30374ebe5e9f0b37e99dcbdc965c00fcf542f89dLennart Poettering
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek *ret = NULL;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek return -ENOENT;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek}
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmekint network_apply(Manager *manager, Network *network, Link *link) {
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek int r;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek link->network = network;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek r = link_configure(link);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (r < 0)
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek return r;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek return 0;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek}
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmekint config_parse_bridge(const char *unit,
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek const char *filename,
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek unsigned line,
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek const char *section,
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek unsigned section_line,
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek const char *lvalue,
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek int ltype,
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek const char *rvalue,
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek void *data,
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek void *userdata) {
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek Network *network = userdata;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek Bridge *bridge;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek int r;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek assert(filename);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek assert(lvalue);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek assert(rvalue);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek assert(data);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek r = bridge_get(network->manager, rvalue, &bridge);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek if (r < 0) {
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek log_syntax(unit, LOG_ERR, filename, line, EINVAL,
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek "Bridge is invalid, ignoring assignment: %s", rvalue);
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek return 0;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek }
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek network->bridge = bridge;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek return 0;
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek}
2ca0435be9359bde3020eeb528c2a6d72ac1e0b0Zbigniew Jędrzejewski-Szmek