networkd-network.c revision 1ac608c9ccb6b69a6bc8a458e10a05e0fc9a8301
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer/***
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer This file is part of systemd.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer Copyright 2013 Tom Gundersen <teg@jklm.no>
0fe15dc8ddddeb39a5cad1f4f4afa25fa074a5d1Evgeny Vereshchagin
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer systemd is free software; you can redistribute it and/or modify it
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer under the terms of the GNU Lesser General Public License as published by
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer the Free Software Foundation; either version 2.1 of the License, or
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pitt (at your option) any later version.
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pitt
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pitt systemd is distributed in the hope that it will be useful, but
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pitt WITHOUT ANY WARRANTY; without even the implied warranty of
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pitt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4be4833ece2856e0cacc09f8f8b2c02b320751faMartin Pitt Lesser General Public License for more details.
c50a4525aa8151b180d5a325e88c5f3812e66c36Martin Pitt
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier You should have received a copy of the GNU Lesser General Public License
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier along with systemd; If not, see <http://www.gnu.org/licenses/>.
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier***/
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include <ctype.h>
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include <net/if.h>
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "conf-files.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "conf-parser.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "util.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "hostname-util.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "networkd.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "networkd-netdev.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "networkd-link.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "network-internal.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "dns-domain.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalierstatic int network_load_one(Manager *manager, const char *filename) {
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier _cleanup_network_free_ Network *network = NULL;
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier _cleanup_fclose_ FILE *file = NULL;
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier char *d;
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier Route *route;
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier Address *address;
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier int r;
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier assert(manager);
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier assert(filename);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
b6f0c419e38a960873fe68bf8f89bbb0268eed02Harald Hoyer file = fopen(filename, "re");
b6f0c419e38a960873fe68bf8f89bbb0268eed02Harald Hoyer if (!file) {
b6f0c419e38a960873fe68bf8f89bbb0268eed02Harald Hoyer if (errno == ENOENT)
b6f0c419e38a960873fe68bf8f89bbb0268eed02Harald Hoyer return 0;
b6f0c419e38a960873fe68bf8f89bbb0268eed02Harald Hoyer else
b6f0c419e38a960873fe68bf8f89bbb0268eed02Harald Hoyer return -errno;
b6f0c419e38a960873fe68bf8f89bbb0268eed02Harald Hoyer }
b6f0c419e38a960873fe68bf8f89bbb0268eed02Harald Hoyer
61fea35e14d84144e6e2122f5cd247f9c7e6245eEvgeny Vereshchagin if (null_or_empty_fd(fileno(file))) {
61fea35e14d84144e6e2122f5cd247f9c7e6245eEvgeny Vereshchagin log_debug("Skipping empty file: %s", filename);
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier return 0;
61fea35e14d84144e6e2122f5cd247f9c7e6245eEvgeny Vereshchagin }
61fea35e14d84144e6e2122f5cd247f9c7e6245eEvgeny Vereshchagin
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier network = new0(Network, 1);
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier if (!network)
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier return log_oom();
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier network->manager = manager;
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier LIST_HEAD_INIT(network->static_addresses);
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier LIST_HEAD_INIT(network->static_routes);
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pitt LIST_HEAD_INIT(network->static_fdb_entries);
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier network->stacked_netdevs = hashmap_new(&string_hash_ops);
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier if (!network->stacked_netdevs)
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier return log_oom();
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier network->addresses_by_section = hashmap_new(NULL);
dbf43a42b8bb66d53c7cbab05f104c28097f811eDaniel Mack if (!network->addresses_by_section)
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier return log_oom();
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier network->routes_by_section = hashmap_new(NULL);
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier if (!network->routes_by_section)
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier return log_oom();
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier network->fdb_entries_by_section = hashmap_new(NULL);
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier if (!network->fdb_entries_by_section)
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier return log_oom();
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier
dbf43a42b8bb66d53c7cbab05f104c28097f811eDaniel Mack network->filename = strdup(filename);
dbf43a42b8bb66d53c7cbab05f104c28097f811eDaniel Mack if (!network->filename)
dbf43a42b8bb66d53c7cbab05f104c28097f811eDaniel Mack return log_oom();
dbf43a42b8bb66d53c7cbab05f104c28097f811eDaniel Mack
8a8332f77e61d41f3bb28b8f929ed41e0ffaf721Zbigniew Jędrzejewski-Szmek network->name = strdup(basename(filename));
8a8332f77e61d41f3bb28b8f929ed41e0ffaf721Zbigniew Jędrzejewski-Szmek if (!network->name)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return log_oom();
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier d = strrchr(network->name, '.');
8a8332f77e61d41f3bb28b8f929ed41e0ffaf721Zbigniew Jędrzejewski-Szmek if (!d)
2c393ed7611a586ef5665aa62453ec57c0f5fef6Evgeny Vereshchagin return -EINVAL;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier assert(streq(d, ".network"));
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier *d = '\0';
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier network->dhcp = ADDRESS_FAMILY_NO;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier network->dhcp_ntp = true;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier network->dhcp_dns = true;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier network->dhcp_hostname = true;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier network->dhcp_routes = true;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier network->dhcp_sendhost = true;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier network->dhcp_route_metric = DHCP_ROUTE_METRIC;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier network->dhcp_client_identifier = DHCP_CLIENT_ID_DUID;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier network->use_bpdu = true;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier network->allow_port_to_be_root = true;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier network->unicast_flood = true;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier network->llmnr = RESOLVE_SUPPORT_YES;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier network->link_local = ADDRESS_FAMILY_IPV6;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier network->ipv6_privacy_extensions = IPV6_PRIVACY_EXTENSIONS_NO;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier r = config_parse(NULL, filename, file,
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier "Match\0"
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier "Link\0"
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier "Network\0"
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier "Address\0"
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier "Route\0"
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier "DHCP\0"
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier "DHCPv4\0"
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier "Bridge\0"
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier "BridgeFDB\0",
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier config_item_perf_lookup, network_network_gperf_lookup,
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier false, false, true, network);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (r < 0)
8a8332f77e61d41f3bb28b8f929ed41e0ffaf721Zbigniew Jędrzejewski-Szmek return r;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
2375607039517c88df51ef16ddbb624ec1c10654Kay Sievers /* IPMasquerade=yes implies IPForward=yes */
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (network->ip_masquerade)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier network->ip_forward |= ADDRESS_FAMILY_IPV4;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier LIST_PREPEND(networks, manager->networks, network);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier r = hashmap_ensure_allocated(&manager->networks_by_name, &string_hash_ops);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (r < 0)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return r;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier r = hashmap_put(manager->networks_by_name, network->name, network);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (r < 0)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return r;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
739d81ddd005fae2bb82edce5b8a6173c7c48b34Zbigniew Jędrzejewski-Szmek LIST_FOREACH(routes, route, network->static_routes) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (!route->family) {
1b1eae69ce52ef6c89a1200e8d3758549b291991Daniel Mack log_warning("Route section without Gateway field configured in %s. "
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier "Ignoring", filename);
739d81ddd005fae2bb82edce5b8a6173c7c48b34Zbigniew Jędrzejewski-Szmek return 0;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier }
edbced8a151c1b7ded685e2ec644950d2adec5f5Harald Hoyer }
1b1eae69ce52ef6c89a1200e8d3758549b291991Daniel Mack
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier LIST_FOREACH(addresses, address, network->static_addresses) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (!address->family) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier log_warning("Address section without Address field configured in %s. "
739d81ddd005fae2bb82edce5b8a6173c7c48b34Zbigniew Jędrzejewski-Szmek "Ignoring", filename);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return 0;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier }
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier }
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier network = NULL;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return 0;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierint network_load(Manager *manager) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier Network *network;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier _cleanup_strv_free_ char **files = NULL;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier char **f;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier int r;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier assert(manager);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier while ((network = manager->networks))
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier network_free(network);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier r = conf_files_list_strv(&files, ".network", NULL, network_dirs);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (r < 0)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return log_error_errno(r, "Failed to enumerate network files: %m");
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier STRV_FOREACH_BACKWARDS(f, files) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier r = network_load_one(manager, *f);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (r < 0)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return r;
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin }
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin return 0;
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin}
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchaginvoid network_free(Network *network) {
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin NetDev *netdev;
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin Route *route;
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin Address *address;
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin FdbEntry *fdb_entry;
c7eda0133b6bf13a182337cbe8a61bf2faf9b32eEvgeny Vereshchagin Iterator i;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (!network)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier free(network->filename);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier free(network->match_mac);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier strv_free(network->match_path);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier strv_free(network->match_driver);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier strv_free(network->match_type);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier strv_free(network->match_name);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier free(network->description);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier free(network->dhcp_vendor_class_identifier);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier free(network->hostname);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier free(network->mac);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier strv_free(network->ntp);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier strv_free(network->dns);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier strv_free(network->domains);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier strv_free(network->bind_carrier);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier netdev_unref(network->bridge);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier netdev_unref(network->bond);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier HASHMAP_FOREACH(netdev, network->stacked_netdevs, i) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier hashmap_remove(network->stacked_netdevs, netdev->ifname);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier netdev_unref(netdev);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier }
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier hashmap_free(network->stacked_netdevs);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier while ((route = network->static_routes))
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier route_free(route);
bf3a947cb44f31359bba313e0252cbcc0dc95b03Evgeny Vereshchagin
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier while ((address = network->static_addresses))
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier address_free(address);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier while ((fdb_entry = network->static_fdb_entries))
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier fdb_entry_free(fdb_entry);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier hashmap_free(network->addresses_by_section);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier hashmap_free(network->routes_by_section);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier hashmap_free(network->fdb_entries_by_section);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (network->manager) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (network->manager->networks)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier LIST_REMOVE(networks, network->manager->networks, network);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (network->manager->networks_by_name)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier hashmap_remove(network->manager->networks_by_name, network->name);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier }
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier free(network->name);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
4be4833ece2856e0cacc09f8f8b2c02b320751faMartin Pitt condition_free_list(network->match_host);
7d023341c765c205068e33d23d63a4000ec211dfMartin Pitt condition_free_list(network->match_virt);
7d023341c765c205068e33d23d63a4000ec211dfMartin Pitt condition_free_list(network->match_kernel);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier condition_free_list(network->match_arch);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier free(network);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierint network_get_by_name(Manager *manager, const char *name, Network **ret) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier Network *network;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
cffae62bcb6912fbaf1b7b282d9d170c9d308897Martin Pitt assert(manager);
99877b7e3782a51b31bf191825f0335500f52fe5Harald Hoyer assert(name);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier assert(ret);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier network = hashmap_get(manager->networks_by_name, name);
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pitt if (!network)
3486cb6cfa3d32a95c0daf02c7510fdf372507bfMartin Pitt return -ENOENT;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier *ret = network;
e63b61be5350dbe92ea12e1eeb96dde251ed9292Evgeny Vereshchagin
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return 0;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierint network_get(Manager *manager, struct udev_device *device,
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier const char *ifname, const struct ether_addr *address,
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier Network **ret) {
0fe15dc8ddddeb39a5cad1f4f4afa25fa074a5d1Evgeny Vereshchagin Network *network;
0fe15dc8ddddeb39a5cad1f4f4afa25fa074a5d1Evgeny Vereshchagin struct udev_device *parent;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier const char *path = NULL, *parent_driver = NULL, *driver = NULL, *devtype = NULL;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier assert(manager);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier assert(ret);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
0fe15dc8ddddeb39a5cad1f4f4afa25fa074a5d1Evgeny Vereshchagin if (device) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier path = udev_device_get_property_value(device, "ID_PATH");
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
417491f122b346a31cf8dc406c4f9195a5900cecEvgeny Vereshchagin parent = udev_device_get_parent(device);
417491f122b346a31cf8dc406c4f9195a5900cecEvgeny Vereshchagin if (parent)
417491f122b346a31cf8dc406c4f9195a5900cecEvgeny Vereshchagin parent_driver = udev_device_get_driver(parent);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier driver = udev_device_get_property_value(device, "ID_NET_DRIVER");
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier devtype = udev_device_get_devtype(device);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier }
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier LIST_FOREACH(networks, network, manager->networks) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (net_match_config(network->match_mac, network->match_path,
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier network->match_driver, network->match_type,
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier network->match_name, network->match_host,
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier network->match_virt, network->match_kernel,
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier network->match_arch,
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier address, path, parent_driver, driver,
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier devtype, ifname)) {
25b47f96d9601ff566257b2a31bfb5f4bd25d661Marko Myllynen if (network->match_name && device) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier const char *attr;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier uint8_t name_assign_type = NET_NAME_UNKNOWN;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier attr = udev_device_get_sysattr_value(device, "name_assign_type");
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (attr)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier (void) safe_atou8(attr, &name_assign_type);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (name_assign_type == NET_NAME_ENUM)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier log_warning("%-*s: found matching network '%s', based on potentially unpredictable ifname",
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier IFNAMSIZ, ifname, network->filename);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier else
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier log_debug("%-*s: found matching network '%s'", IFNAMSIZ, ifname, network->filename);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier } else
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier log_debug("%-*s: found matching network '%s'", IFNAMSIZ, ifname, network->filename);
53d90f9582f96208b3674da823ad1a3d2c3b1aa4Martin Pitt
5c404f1ab8e96efedb983806443ca982a1b2a372Evgeny Vereshchagin *ret = network;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return 0;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier }
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier }
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier *ret = NULL;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return -ENOENT;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier}
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalierint network_apply(Manager *manager, Network *network, Link *link) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier int r;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier link->network = network;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (network->ipv4ll_route) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier Route *route;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer r = route_new_static(network, 0, &route);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier if (r < 0)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier return r;
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier r = inet_pton(AF_INET, "169.254.0.0", &route->dst_addr.in);
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer if (r == 0)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return -EINVAL;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (r < 0)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return -errno;
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer route->family = AF_INET;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer route->dst_prefixlen = 16;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer route->scope = RT_SCOPE_LINK;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer route->metrics = IPV4LL_ROUTE_METRIC;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer route->protocol = RTPROT_STATIC;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (network->dns || network->ntp) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer r = link_save(link);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (r < 0)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return r;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerint config_parse_netdev(const char *unit,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *filename,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer unsigned line,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *section,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer unsigned section_line,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *lvalue,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer int ltype,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *rvalue,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer void *data,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer void *userdata) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer Network *network = userdata;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer _cleanup_free_ char *kind_string = NULL;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer char *p;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer NetDev *netdev;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer NetDevKind kind;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer int r;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(filename);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(lvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(data);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer kind_string = strdup(lvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (!kind_string)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return log_oom();
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier /* the keys are CamelCase versions of the kind */
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier for (p = kind_string; *p; p++)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier *p = tolower(*p);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier kind = netdev_kind_from_string(kind_string);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (kind == _NETDEV_KIND_INVALID) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer log_syntax(unit, LOG_ERR, filename, line, EINVAL,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer "Invalid NetDev kind: %s", lvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer r = netdev_get(network->manager, rvalue, &netdev);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (r < 0) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer log_syntax(unit, LOG_ERR, filename, line, EINVAL,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer "%s could not be found, ignoring assignment: %s", lvalue, rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (netdev->kind != kind) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer log_syntax(unit, LOG_ERR, filename, line, EINVAL,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer "NetDev is not a %s, ignoring assignment: %s", lvalue, rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer switch (kind) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer case NETDEV_KIND_BRIDGE:
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer network->bridge = netdev;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer break;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer case NETDEV_KIND_BOND:
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer network->bond = netdev;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer break;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer case NETDEV_KIND_VLAN:
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer case NETDEV_KIND_MACVLAN:
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer case NETDEV_KIND_MACVTAP:
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer case NETDEV_KIND_IPVLAN:
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer case NETDEV_KIND_VXLAN:
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer r = hashmap_put(network->stacked_netdevs, netdev->ifname, netdev);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (r < 0) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer log_syntax(unit, LOG_ERR, filename, line, EINVAL,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer "Can not add VLAN '%s' to network: %m",
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer break;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer default:
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert_not_reached("Can not parse NetDev");
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer netdev_ref(netdev);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerint config_parse_domains(const char *unit,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *filename,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer unsigned line,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *section,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer unsigned section_line,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *lvalue,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer int ltype,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *rvalue,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer void *data,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer void *userdata) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer Network *network = userdata;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer char ***domains = data;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer char **domain;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer int r;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer r = config_parse_strv(unit, filename, line, section, section_line,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer lvalue, ltype, rvalue, domains, userdata);
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer if (r < 0)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return r;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer strv_uniq(*domains);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer network->wildcard_domain = !!strv_find(*domains, "*");
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer STRV_FOREACH(domain, *domains) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (is_localhost(*domain))
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer log_syntax(unit, LOG_ERR, filename, line, EINVAL, "'localhost' domain names may not be configured, ignoring assignment: %s", *domain);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer else {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer r = dns_name_is_valid(*domain);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (r <= 0 && !streq(*domain, "*")) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (r < 0)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer log_error_errno(r, "Failed to validate domain name: %s: %m", *domain);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (r == 0)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer log_warning("Domain name is not valid, ignoring assignment: %s", *domain);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer } else
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer continue;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer strv_remove(*domains, *domain);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer /* We removed one entry, make sure we don't skip the next one */
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer domain--;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerint config_parse_tunnel(const char *unit,
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer const char *filename,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer unsigned line,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *section,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer unsigned section_line,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *lvalue,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer int ltype,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *rvalue,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer void *data,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer void *userdata) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer Network *network = userdata;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer NetDev *netdev;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer int r;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(filename);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(lvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(data);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer r = netdev_get(network->manager, rvalue, &netdev);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (r < 0) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer log_syntax(unit, LOG_ERR, filename, line, r, "Tunnel is invalid, ignoring assignment: %s", rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (netdev->kind != NETDEV_KIND_IPIP &&
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer netdev->kind != NETDEV_KIND_SIT &&
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer netdev->kind != NETDEV_KIND_GRE &&
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer netdev->kind != NETDEV_KIND_GRETAP &&
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer netdev->kind != NETDEV_KIND_IP6GRE &&
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer netdev->kind != NETDEV_KIND_IP6GRETAP &&
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer netdev->kind != NETDEV_KIND_VTI &&
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer netdev->kind != NETDEV_KIND_VTI6 &&
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer netdev->kind != NETDEV_KIND_IP6TNL
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer ) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer log_syntax(unit, LOG_ERR, filename, line, EINVAL,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer "NetDev is not a tunnel, ignoring assignment: %s", rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer r = hashmap_put(network->stacked_netdevs, netdev->ifname, netdev);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (r < 0) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer log_syntax(unit, LOG_ERR, filename, line, r, "Cannot add VLAN '%s' to network, ignoring: %m", rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer netdev_ref(netdev);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerint config_parse_ipv4ll(
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char* unit,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *filename,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer unsigned line,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *section,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer unsigned section_line,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *lvalue,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer int ltype,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *rvalue,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer void *data,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer void *userdata) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer AddressFamilyBoolean *link_local = data;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(filename);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(lvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(data);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer /* Note that this is mostly like
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer * config_parse_address_family_boolean(), except that it
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer * applies only to IPv4 */
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (parse_boolean(rvalue))
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer *link_local |= ADDRESS_FAMILY_IPV4;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer else
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer *link_local &= ~ADDRESS_FAMILY_IPV4;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerint config_parse_dhcp(
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char* unit,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *filename,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer unsigned line,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *section,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer unsigned section_line,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *lvalue,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer int ltype,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *rvalue,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer void *data,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer void *userdata) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer AddressFamilyBoolean *dhcp = data, s;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(filename);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(lvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(data);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer /* Note that this is mostly like
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer * config_parse_address_family_boolean(), except that it
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer * understands some old names for the enum values */
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer s = address_family_boolean_from_string(rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (s < 0) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer /* Previously, we had a slightly different enum here,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer * support its values for compatbility. */
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (streq(rvalue, "none"))
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer s = ADDRESS_FAMILY_NO;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer else if (streq(rvalue, "v4"))
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer s = ADDRESS_FAMILY_IPV4;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer else if (streq(rvalue, "v6"))
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer s = ADDRESS_FAMILY_IPV6;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer else if (streq(rvalue, "both"))
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer s = ADDRESS_FAMILY_YES;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer else {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer log_syntax(unit, LOG_ERR, filename, line, s, "Failed to parse DHCP option, ignoring: %s", rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer *dhcp = s;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerstatic const char* const dhcp_client_identifier_table[_DHCP_CLIENT_ID_MAX] = {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [DHCP_CLIENT_ID_MAC] = "mac",
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [DHCP_CLIENT_ID_DUID] = "duid"
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer};
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald HoyerDEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(dhcp_client_identifier, DCHPClientIdentifier);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald HoyerDEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp_client_identifier, dhcp_client_identifier, DCHPClientIdentifier, "Failed to parse client identifier type");
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerstatic const char* const resolve_support_table[_RESOLVE_SUPPORT_MAX] = {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [RESOLVE_SUPPORT_NO] = "no",
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [RESOLVE_SUPPORT_YES] = "yes",
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [RESOLVE_SUPPORT_RESOLVE] = "resolve",
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer};
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald HoyerDEFINE_STRING_TABLE_LOOKUP(resolve_support, ResolveSupport);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerint config_parse_resolve(
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char* unit,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *filename,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer unsigned line,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *section,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer unsigned section_line,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *lvalue,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer int ltype,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *rvalue,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer void *data,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer void *userdata) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer ResolveSupport *resolve = data;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer int k;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(filename);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(lvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(resolve);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer /* Our enum shall be a superset of booleans, hence first try
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer * to parse as boolean, and then as enum */
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer k = parse_boolean(rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (k > 0)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer *resolve = RESOLVE_SUPPORT_YES;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer else if (k == 0)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer *resolve = RESOLVE_SUPPORT_NO;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer else {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer ResolveSupport s;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer s = resolve_support_from_string(rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (s < 0){
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer log_syntax(unit, LOG_ERR, filename, line, -s, "Failed to parse %s option, ignoring: %s", lvalue, rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer *resolve = s;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerint config_parse_ipv6token(
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char* unit,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *filename,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer unsigned line,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *section,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer unsigned section_line,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *lvalue,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer int ltype,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *rvalue,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer void *data,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer void *userdata) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer union in_addr_union buffer;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer struct in6_addr *token = data;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer int r;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(filename);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(lvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(token);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer r = in_addr_from_string(AF_INET6, rvalue, &buffer);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (r < 0) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse IPv6 token, ignoring: %s", rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer r = in_addr_is_null(AF_INET6, &buffer);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (r < 0) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer log_syntax(unit, LOG_ERR, filename, line, r, "IPv6 token can not be the ANY address, ignoring: %s", rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if ((buffer.in6.s6_addr32[0] | buffer.in6.s6_addr32[1]) != 0) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer log_syntax(unit, LOG_ERR, filename, line, EINVAL, "IPv6 token can not be longer than 64 bits, ignoring: %s", rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer *token = buffer.in6;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerint config_parse_address_family_boolean_with_kernel(
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char* unit,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *filename,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer unsigned line,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *section,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer unsigned section_line,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *lvalue,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer int ltype,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *rvalue,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer void *data,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer void *userdata) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer AddressFamilyBoolean *fwd = data, s;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(filename);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(lvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(data);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer s = address_family_boolean_from_string(rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (s < 0) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (streq(rvalue, "kernel"))
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer s = _ADDRESS_FAMILY_BOOLEAN_INVALID;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer else {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer log_syntax(unit, LOG_ERR, filename, line, s, "Failed to parse IPForwarding option, ignoring: %s", rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer *fwd = s;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerstatic const char* const ipv6_privacy_extensions_table[_IPV6_PRIVACY_EXTENSIONS_MAX] = {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [IPV6_PRIVACY_EXTENSIONS_NO] = "no",
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [IPV6_PRIVACY_EXTENSIONS_PREFER_PUBLIC] = "prefer-public",
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer [IPV6_PRIVACY_EXTENSIONS_YES] = "yes",
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer};
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald HoyerDEFINE_STRING_TABLE_LOOKUP(ipv6_privacy_extensions, IPv6PrivacyExtensions);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerint config_parse_ipv6_privacy_extensions(
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char* unit,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *filename,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer unsigned line,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *section,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer unsigned section_line,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *lvalue,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer int ltype,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *rvalue,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer void *data,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer void *userdata) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer IPv6PrivacyExtensions *ipv6_privacy_extensions = data;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer int k;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(filename);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(lvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(ipv6_privacy_extensions);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer /* Our enum shall be a superset of booleans, hence first try
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer * to parse as boolean, and then as enum */
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer k = parse_boolean(rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (k > 0)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer *ipv6_privacy_extensions = IPV6_PRIVACY_EXTENSIONS_YES;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer else if (k == 0)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer *ipv6_privacy_extensions = IPV6_PRIVACY_EXTENSIONS_NO;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer else {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer IPv6PrivacyExtensions s;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer s = ipv6_privacy_extensions_from_string(rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (s < 0) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (streq(rvalue, "kernel"))
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer s = _IPV6_PRIVACY_EXTENSIONS_INVALID;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer else {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer log_syntax(unit, LOG_ERR, filename, line, s, "Failed to parse IPv6 privacy extensions option, ignoring: %s", rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer *ipv6_privacy_extensions = s;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerint config_parse_hostname(
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *unit,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *filename,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer unsigned line,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *section,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer unsigned section_line,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *lvalue,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer int ltype,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer const char *rvalue,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer void *data,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer void *userdata) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer char **hostname = data, *hn = NULL;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer int r;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(filename);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(lvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert(rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer r = config_parse_string(unit, filename, line, section, section_line, lvalue, ltype, rvalue, &hn, userdata);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (r < 0)
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return r;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer if (!hostname_is_valid(hn, false)) {
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Hostname is not valid, ignoring assignment: %s", rvalue);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer free(hn);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer }
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer free(*hostname);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer *hostname = hostname_cleanup(hn);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer return 0;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer}
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer