networkd-network.c revision 1af2536acf8aecc3eb940d04268a419c956ee10a
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Tom Gundersen <teg@jklm.no>
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <ctype.h>
#include "path-util.h"
#include "conf-files.h"
#include "conf-parser.h"
#include "util.h"
#include "networkd.h"
#include "networkd-netdev.h"
#include "networkd-link.h"
#include "network-internal.h"
int r;
if (!file) {
return 0;
else
return -errno;
}
return 0;
}
if (!network)
return log_oom();
if (!network->stacked_netdevs)
return log_oom();
if (!network->addresses_by_section)
return log_oom();
if (!network->routes_by_section)
return log_oom();
if (!network->fdb_entries_by_section)
return log_oom();
return log_oom();
network->dhcp_hostname = true;
network->dhcp_routes = true;
network->dhcp_sendhost = true;
"Match\0"
"Link\0"
"Network\0"
"Address\0"
"Route\0"
"DHCP\0"
"DHCPv4\0"
"Bridge\0"
"BridgeFDB\0",
false, false, true, network);
if (r < 0)
return r;
/* IPMasquerade=yes implies IPForward=yes */
if (network->ip_masquerade)
log_warning("Route section without Gateway field configured in %s. "
"Ignoring", filename);
return 0;
}
}
log_warning("Address section without Address field configured in %s. "
"Ignoring", filename);
return 0;
}
}
return 0;
}
char **f;
int r;
if (r < 0)
return log_error_errno(r, "Failed to enumerate network files: %m");
STRV_FOREACH_BACKWARDS(f, files) {
r = network_load_one(manager, *f);
if (r < 0)
return r;
}
return 0;
}
Iterator i;
if (!network)
return;
}
}
ifname)) {
if (network->match_name) {
const char *attr;
if (attr)
if (name_assign_type == NET_NAME_ENUM)
log_warning("%-*s: found matching network '%s', based on potentially unpredictable ifname",
else
} else
return 0;
}
}
return -ENOENT;
}
int r;
if (network->ipv4ll_route) {
if (r < 0)
return r;
if (r == 0)
return -EINVAL;
if (r < 0)
return -errno;
}
if (r < 0)
return r;
}
return 0;
}
int config_parse_netdev(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) {
char *p;
int r;
if (!kind_string)
return log_oom();
/* the keys are CamelCase versions of the kind */
for (p = kind_string; *p; p++)
*p = tolower(*p);
if (kind == _NETDEV_KIND_INVALID) {
"Invalid NetDev kind: %s", lvalue);
return 0;
}
if (r < 0) {
return 0;
}
return 0;
}
switch (kind) {
case NETDEV_KIND_BRIDGE:
break;
case NETDEV_KIND_BOND:
break;
case NETDEV_KIND_VLAN:
case NETDEV_KIND_MACVLAN:
case NETDEV_KIND_IPVLAN:
case NETDEV_KIND_VXLAN:
if (r < 0) {
"Can not add VLAN '%s' to network: %s",
return 0;
}
break;
default:
assert_not_reached("Can not parse NetDev");
}
return 0;
}
int config_parse_domains(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) {
char **domain;
int r;
if (r < 0)
return r;
if (is_localhost(*domain))
log_syntax(unit, LOG_ERR, filename, line, EINVAL, "'localhost' domain names may not be configured, ignoring assignment: %s", *domain);
else if (!hostname_is_valid(*domain)) {
log_syntax(unit, LOG_ERR, filename, line, EINVAL, "domain name is not valid, ignoring assignment: %s", *domain);
} else
continue;
/* We removed one entry, make sure we don't skip the next one */
domain--;
}
return 0;
}
int config_parse_tunnel(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 r;
if (r < 0) {
"Tunnel is invalid, ignoring assignment: %s", rvalue);
return 0;
}
"NetDev is not a tunnel, ignoring assignment: %s", rvalue);
return 0;
}
if (r < 0) {
"Can not add VLAN '%s' to network: %s",
return 0;
}
return 0;
}
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) {
/* Note that this is mostly like
* config_parse_address_family_boolean(), except that it
* understands some old names for the enum values */
if (s < 0) {
/* Previously, we had a slightly different enum here,
* support its values for compatbility. */
s = ADDRESS_FAMILY_NO;
s = ADDRESS_FAMILY_IPV4;
s = ADDRESS_FAMILY_IPV6;
s = ADDRESS_FAMILY_YES;
else {
return 0;
}
}
*dhcp = s;
return 0;
}
static const char* const llmnr_support_table[_LLMNR_SUPPORT_MAX] = {
[LLMNR_SUPPORT_NO] = "no",
[LLMNR_SUPPORT_YES] = "yes",
[LLMNR_SUPPORT_RESOLVE] = "resolve",
};
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) {
int k;
/* Our enum shall be a superset of booleans, hence first try
* to parse as boolean, and then as enum */
k = parse_boolean(rvalue);
if (k > 0)
else if (k == 0)
else {
LLMNRSupport s;
if (s < 0){
log_syntax(unit, LOG_ERR, filename, line, -s, "Failed to parse LLMNR option, ignoring: %s", rvalue);
return 0;
}
*llmnr = s;
}
return 0;
}