networkd-network.c revision 79f17ea6f8d885da063f50d966891adaee236b26
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering This file is part of systemd.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Copyright 2013 Tom Gundersen <teg@jklm.no>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is free software; you can redistribute it and/or modify it
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering under the terms of the GNU Lesser General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is distributed in the hope that it will be useful, but
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Lesser General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering You should have received a copy of the GNU Lesser General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic int network_load_one(Manager *manager, const char *filename) {
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering _cleanup_network_free_ Network *network = NULL;
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering log_debug("Skipping empty file: %s", filename);
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering LIST_HEAD_INIT(network->static_addresses);
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering LIST_HEAD_INIT(network->static_fdb_entries);
af22c65b272f0e7a1c0518c222749f3c09d05438Lennart Poettering network->stacked_netdevs = hashmap_new(&string_hash_ops);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering network->addresses_by_section = hashmap_new(NULL);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering network->routes_by_section = hashmap_new(NULL);
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poettering network->fdb_entries_by_section = hashmap_new(NULL);
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poettering network->name = strdup(basename(filename));
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering network->dhcp_route_metric = DHCP_ROUTE_METRIC;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering network->dhcp_client_identifier = DHCP_CLIENT_ID_DUID;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering network->link_local = ADDRESS_FAMILY_IPV6;
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering network->ipv6_privacy_extensions = IPV6_PRIVACY_EXTENSIONS_NO;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering "BridgeFDB\0",
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek config_item_perf_lookup, network_network_gperf_lookup,
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poettering false, false, true, network);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* IPMasquerade=yes implies IPForward=yes */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering network->ip_forward |= ADDRESS_FAMILY_IPV4;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering LIST_PREPEND(networks, manager->networks, network);
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering r = hashmap_ensure_allocated(&manager->networks_by_name, &string_hash_ops);
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering r = hashmap_put(manager->networks_by_name, network->name, network);
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering LIST_FOREACH(routes, route, network->static_routes) {
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek log_warning("Route section without Gateway field configured in %s. "
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek LIST_FOREACH(addresses, address, network->static_addresses) {
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek log_warning("Address section without Address field configured in %s. "
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering r = conf_files_list_strv(&files, ".network", NULL, network_dirs);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek return log_error_errno(r, "Failed to enumerate network files: %m");
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmekvoid network_free(Network *network) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering HASHMAP_FOREACH(netdev, network->stacked_netdevs, i) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering hashmap_remove(network->stacked_netdevs, netdev->ifname);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering while ((fdb_entry = network->static_fdb_entries))
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering hashmap_free(network->addresses_by_section);
105e151299dc1208855380be2b22d0db2d66ebc6Lennart Poettering hashmap_free(network->routes_by_section);
5d27351f8546530cf779847b0b04b0172c09f9d0Tom Gundersen hashmap_free(network->fdb_entries_by_section);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering LIST_REMOVE(networks, network->manager->networks, network);
7778dffff3d8bd7438fe19a248c16203668324c9Daniel Mack hashmap_remove(network->manager->networks_by_name, network->name);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering condition_free_list(network->match_host);
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering condition_free_list(network->match_virt);
78c6a153c47f8d597c827bdcaf8c4e42ac87f738Lennart Poettering condition_free_list(network->match_kernel);
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering condition_free_list(network->match_arch);
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poetteringint network_get_by_name(Manager *manager, const char *name, Network **ret) {
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering network = hashmap_get(manager->networks_by_name, name);
if (device) {
if (parent)
const char *attr;
if (attr)
return -ENOENT;
return -EINVAL;
return -errno;
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
if (!kind_string)
return log_oom();
for (p = kind_string; *p; p++)
*p = tolower(*p);
switch (kind) {
case NETDEV_KIND_BRIDGE:
case NETDEV_KIND_BOND:
case NETDEV_KIND_VLAN:
case NETDEV_KIND_MACVLAN:
case NETDEV_KIND_IPVLAN:
case NETDEV_KIND_VXLAN:
rvalue);
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
char **domain;
log_syntax(unit, LOG_ERR, filename, line, EINVAL, "'localhost' domain names may not be configured, ignoring assignment: %s", *domain);
domain--;
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
log_syntax(unit, LOG_ERR, filename, line, r, "Cannot add VLAN '%s' to network, ignoring: %m", rvalue);
int config_parse_ipv4ll(
const char* unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
int config_parse_dhcp(
const char* unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
s = ADDRESS_FAMILY_NO;
s = ADDRESS_FAMILY_IPV4;
s = ADDRESS_FAMILY_IPV6;
s = ADDRESS_FAMILY_YES;
*dhcp = s;
DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp_client_identifier, dhcp_client_identifier, DCHPClientIdentifier, "Failed to parse client identifier type");
int config_parse_llmnr(
const char* unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
LLMNRSupport s;
log_syntax(unit, LOG_ERR, filename, line, -s, "Failed to parse LLMNR option, ignoring: %s", rvalue);
*llmnr = s;
const char* unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
log_syntax(unit, LOG_ERR, filename, line, r, "IPv6 token can not be the ANY address, ignoring: %s", rvalue);
log_syntax(unit, LOG_ERR, filename, line, EINVAL, "IPv6 token can not be longer than 64 bits, ignoring: %s", rvalue);
const char* unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
log_syntax(unit, LOG_ERR, filename, line, s, "Failed to parse IPForwarding option, ignoring: %s", rvalue);
*fwd = s;
const char* unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
log_syntax(unit, LOG_ERR, filename, line, s, "Failed to parse IPv6 privacy extensions option, ignoring: %s", rvalue);
*ipv6_privacy_extensions = s;
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {