1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright (C) 2013 Tom Gundersen <teg@jklm.no>
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include <netinet/ether.h>
25 #include "link-config.h"
29 #include "conf-parser.h"
31 static const char* const mac_policy_table[] = {
32 [MACPOLICY_PERSISTENT] = "persistent",
33 [MACPOLICY_RANDOM] = "random"
36 DEFINE_STRING_TABLE_LOOKUP(mac_policy, MACPolicy);
37 DEFINE_CONFIG_PARSE_ENUM(config_parse_mac_policy, mac_policy, MACPolicy, "Failed to parse MAC address policy");
39 static const char* const name_policy_table[] = {
40 [NAMEPOLICY_ONBOARD] = "onboard",
41 [NAMEPOLICY_SLOT] = "slot",
42 [NAMEPOLICY_PATH] = "path",
43 [NAMEPOLICY_MAC] = "mac"
46 DEFINE_STRING_TABLE_LOOKUP(name_policy, NamePolicy);
47 DEFINE_CONFIG_PARSE_ENUMV(config_parse_name_policy, name_policy, NamePolicy, _NAMEPOLICY_INVALID, "Failed to parse interface name policy");
49 int config_parse_ifname(const char *unit,
71 if (!ascii_is_valid(n) || strlen(n) >= IFNAMSIZ) {
72 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
73 "Interface name is not ASCII clean or is too long, ignoring assignment: %s", rvalue);
89 int config_parse_hwaddr(const char *unit,
98 struct ether_addr **hwaddr = data;
107 n = new0(struct ether_addr, 1);
111 r = sscanf(rvalue, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
112 &n->ether_addr_octet[0],
113 &n->ether_addr_octet[1],
114 &n->ether_addr_octet[2],
115 &n->ether_addr_octet[3],
116 &n->ether_addr_octet[4],
117 &n->ether_addr_octet[5]);
119 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
120 "Not a valid MAC address, ignoring assignment: %s", rvalue);