networkd-network.c revision 4f2e437ad7b04bc0690d1f8202577cbf47acb215
5c79bd79839f1e50bd3c34a0670037f7965ca5a4Patrik Flykt/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
5c79bd79839f1e50bd3c34a0670037f7965ca5a4Patrik Flykt This file is part of systemd.
5c79bd79839f1e50bd3c34a0670037f7965ca5a4Patrik Flykt Copyright 2013 Tom Gundersen <teg@jklm.no>
5c79bd79839f1e50bd3c34a0670037f7965ca5a4Patrik Flykt systemd is free software; you can redistribute it and/or modify it
5c79bd79839f1e50bd3c34a0670037f7965ca5a4Patrik Flykt under the terms of the GNU Lesser General Public License as published by
5c79bd79839f1e50bd3c34a0670037f7965ca5a4Patrik Flykt the Free Software Foundation; either version 2.1 of the License, or
5c79bd79839f1e50bd3c34a0670037f7965ca5a4Patrik Flykt (at your option) any later version.
5c79bd79839f1e50bd3c34a0670037f7965ca5a4Patrik Flykt systemd is distributed in the hope that it will be useful, but
5c79bd79839f1e50bd3c34a0670037f7965ca5a4Patrik Flykt WITHOUT ANY WARRANTY; without even the implied warranty of
5c79bd79839f1e50bd3c34a0670037f7965ca5a4Patrik Flykt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5c79bd79839f1e50bd3c34a0670037f7965ca5a4Patrik Flykt Lesser General Public License for more details.
5c79bd79839f1e50bd3c34a0670037f7965ca5a4Patrik Flykt You should have received a copy of the GNU Lesser General Public License
5c79bd79839f1e50bd3c34a0670037f7965ca5a4Patrik Flykt along with systemd; If not, see <http://www.gnu.org/licenses/>.
c62c4628d9dbc27effd36143c75abe528f561867Patrik Flyktstatic int network_load_one(Manager *manager, const char *filename) {
c62c4628d9dbc27effd36143c75abe528f561867Patrik Flykt _cleanup_network_free_ Network *network = NULL;
be3a09b7ffe62b52658e77ae4d6638d1b0dae654Patrik Flykt log_debug("Skipping empty file: %s", filename);
c62c4628d9dbc27effd36143c75abe528f561867Patrik Flykt network->stacked_netdevs = hashmap_new(&string_hash_ops);
c62c4628d9dbc27effd36143c75abe528f561867Patrik Flykt network->addresses_by_section = hashmap_new(NULL);
851c9f82736c89d423b244a292e153ec7124d309Patrik Flykt network->routes_by_section = hashmap_new(NULL);
c62c4628d9dbc27effd36143c75abe528f561867Patrik Flykt network->fdb_entries_by_section = hashmap_new(NULL);
c62c4628d9dbc27effd36143c75abe528f561867Patrik Flykt network->dhcp_route_metric = DHCP_ROUTE_METRIC;
c62c4628d9dbc27effd36143c75abe528f561867Patrik Flykt network->dhcp_client_identifier = DHCP_CLIENT_ID_DUID;
5c79bd79839f1e50bd3c34a0670037f7965ca5a4Patrik Flykt network->ipv6_privacy_extensions = IPV6_PRIVACY_EXTENSIONS_NO;
10c9ce615d98e125bc520efa94aebaef250a4061David Herrmann "DHCPServer\0"
18d29550b5fbc4b0de334b8212d05decdd131f1bPatrik Flykt "BridgeFDB\0",
18d29550b5fbc4b0de334b8212d05decdd131f1bPatrik Flykt config_item_perf_lookup, network_network_gperf_lookup,
18d29550b5fbc4b0de334b8212d05decdd131f1bPatrik Flykt false, false, true, network);
c62c4628d9dbc27effd36143c75abe528f561867Patrik Flykt /* IPMasquerade=yes implies IPForward=yes */
c62c4628d9dbc27effd36143c75abe528f561867Patrik Flykt LIST_PREPEND(networks, manager->networks, network);
c62c4628d9dbc27effd36143c75abe528f561867Patrik Flykt r = hashmap_ensure_allocated(&manager->networks_by_name, &string_hash_ops);
c62c4628d9dbc27effd36143c75abe528f561867Patrik Flykt r = hashmap_put(manager->networks_by_name, network->name, network);
18d29550b5fbc4b0de334b8212d05decdd131f1bPatrik Flykt LIST_FOREACH(routes, route, network->static_routes) {
5c79bd79839f1e50bd3c34a0670037f7965ca5a4Patrik Flykt log_warning("Route section without Gateway field configured in %s. "
5c79bd79839f1e50bd3c34a0670037f7965ca5a4Patrik Flykt LIST_FOREACH(addresses, address, network->static_addresses) {
18d29550b5fbc4b0de334b8212d05decdd131f1bPatrik Flykt log_warning("Address section without Address field configured in %s. "
e53fc357a9bb9d0a5362ccc4246d598cb0febd5eLennart Poettering r = conf_files_list_strv(&files, ".network", NULL, network_dirs);
e66040417b52be98d41ba1230f25dea65147e8eePatrik Flykt return log_error_errno(r, "Failed to enumerate network files: %m");
5c79bd79839f1e50bd3c34a0670037f7965ca5a4Patrik Flykt HASHMAP_FOREACH(netdev, network->stacked_netdevs, i) {
a13c50e7a33e2b8e0481f725c6272142e6f71751Tom Gundersen hashmap_remove(network->stacked_netdevs, netdev->ifname);
5c79bd79839f1e50bd3c34a0670037f7965ca5a4Patrik Flykt while ((fdb_entry = network->static_fdb_entries))
be3a09b7ffe62b52658e77ae4d6638d1b0dae654Patrik Flykt LIST_REMOVE(networks, network->manager->networks, network);
be3a09b7ffe62b52658e77ae4d6638d1b0dae654Patrik Flykt hashmap_remove(network->manager->networks_by_name, network->name);
be3a09b7ffe62b52658e77ae4d6638d1b0dae654Patrik Flyktint network_get_by_name(Manager *manager, const char *name, Network **ret) {
be3a09b7ffe62b52658e77ae4d6638d1b0dae654Patrik Flykt 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_MACVTAP:
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");
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 IPv6 privacy extensions option, ignoring: %s", rvalue);
*ipv6_privacy_extensions = 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) {
r = config_parse_string(unit, filename, line, section, section_line, lvalue, ltype, rvalue, &hn, userdata);
log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Hostname is not valid, ignoring assignment: %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) {
r = config_parse_string(unit, filename, line, section, section_line, lvalue, ltype, rvalue, &tz, userdata);
log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Timezone is not valid, ignoring assignment: %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) {
const char *p = rvalue;
struct in_addr a, *m;
log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse DNS server address, ignoring: %s", w);
return log_oom();
m[n->n_dhcp_server_dns++] = a;
n->dhcp_server_dns = m;
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) {
const char *p = rvalue;
struct in_addr a, *m;
log_syntax(unit, LOG_ERR, filename, r, line, "Failed to parse NTP server address, ignoring: %s", w);
return log_oom();
m[n->n_dhcp_server_ntp++] = a;
n->dhcp_server_ntp = m;