networkd-network.c revision 9011ce771f149ba45e8ffdb2ae4f0950cdbc6b8b
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik This file is part of systemd.
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik Copyright 2013 Tom Gundersen <teg@jklm.no>
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik systemd is free software; you can redistribute it and/or modify it
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik under the terms of the GNU Lesser General Public License as published by
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik the Free Software Foundation; either version 2.1 of the License, or
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik (at your option) any later version.
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik systemd is distributed in the hope that it will be useful, but
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik WITHOUT ANY WARRANTY; without even the implied warranty of
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik Lesser General Public License for more details.
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik You should have received a copy of the GNU Lesser General Public License
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik along with systemd; If not, see <http://www.gnu.org/licenses/>.
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvikstatic int network_load_one(Manager *manager, const char *filename) {
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik _cleanup_network_free_ Network *network = NULL;
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik log_debug("Skipping empty file: %s", filename);
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik network->stacked_netdevs = hashmap_new(&string_hash_ops);
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik network->addresses_by_section = hashmap_new(NULL);
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik network->routes_by_section = hashmap_new(NULL);
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik network->fdb_entries_by_section = hashmap_new(NULL);
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik network->dhcp_route_metric = DHCP_ROUTE_METRIC;
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik network->dhcp_client_identifier = DHCP_CLIENT_ID_DUID;
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik "BridgeFDB\0",
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik config_item_perf_lookup, network_network_gperf_lookup,
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik false, false, true, network);
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik /* IPMasquerade=yes implies IPForward=yes */
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik LIST_PREPEND(networks, manager->networks, network);
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik r = hashmap_ensure_allocated(&manager->networks_by_name, &string_hash_ops);
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik r = hashmap_put(manager->networks_by_name, network->name, network);
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik LIST_FOREACH(routes, route, network->static_routes) {
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik log_warning("Route section without Gateway field configured in %s. "
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik LIST_FOREACH(addresses, address, network->static_addresses) {
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik log_warning("Address section without Address field configured in %s. "
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik r = conf_files_list_strv(&files, ".network", NULL, network_dirs);
8d22687fbdc540bd0b4d05fd90d87fb6037f4b9fJorgen Austvik return log_error_errno(r, "Failed to enumerate network files: %m");
381a9b85cf2c73401fc1bff06c2e0d86389a5e88Jorgen Austvik HASHMAP_FOREACH(netdev, network->stacked_netdevs, i) {
381a9b85cf2c73401fc1bff06c2e0d86389a5e88Jorgen Austvik hashmap_remove(network->stacked_netdevs, netdev->ifname);
381a9b85cf2c73401fc1bff06c2e0d86389a5e88Jorgen Austvik while ((address = network->static_addresses))
71e31fc573ba527f0d2be7929c2cb98037c860ecKnut Anders Hatlen while ((fdb_entry = network->static_fdb_entries))
381a9b85cf2c73401fc1bff06c2e0d86389a5e88Jorgen Austvik hashmap_free(network->fdb_entries_by_section);
71e31fc573ba527f0d2be7929c2cb98037c860ecKnut Anders Hatlen LIST_REMOVE(networks, network->manager->networks, network);
381a9b85cf2c73401fc1bff06c2e0d86389a5e88Jorgen Austvik hashmap_remove(network->manager->networks_by_name, network->name);
381a9b85cf2c73401fc1bff06c2e0d86389a5e88Jorgen Austvikint network_get_by_name(Manager *manager, const char *name, Network **ret) {
71e31fc573ba527f0d2be7929c2cb98037c860ecKnut Anders Hatlen network = hashmap_get(manager->networks_by_name, name);
381a9b85cf2c73401fc1bff06c2e0d86389a5e88Jorgen Austvikint network_get(Manager *manager, struct udev_device *device,
381a9b85cf2c73401fc1bff06c2e0d86389a5e88Jorgen Austvik const char *ifname, const struct ether_addr *address,
381a9b85cf2c73401fc1bff06c2e0d86389a5e88Jorgen Austvik const char *path, *parent_driver, *driver, *devtype;
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);
log_syntax(unit, LOG_ERR, filename, line, EINVAL, "domain name is not valid, 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);