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>
24 #include <arpa/inet.h>
30 #include "conf-parser.h"
32 bool net_match_config(const struct ether_addr *match_mac,
33 const char *match_path,
34 const char *match_driver,
35 const char *match_type,
36 const char *match_name,
39 const char *dev_driver,
41 const char *dev_name) {
43 if (match_mac && (!dev_mac || memcmp(match_mac, ether_aton(dev_mac), ETH_ALEN)))
46 if (match_path && !streq_ptr(match_path, dev_path))
49 if (match_driver && !streq_ptr(match_driver, dev_driver))
52 if (match_type && !streq_ptr(match_type, dev_type))
55 if (match_name && !streq_ptr(match_name, dev_name))
61 int config_parse_ifname(const char *unit,
65 unsigned section_line,
84 if (!ascii_is_valid(n) || strlen(n) >= IFNAMSIZ) {
85 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
86 "Interface name is not ASCII clean or is too long, ignoring assignment: %s", rvalue);
102 int config_parse_ifalias(const char *unit,
103 const char *filename,
106 unsigned section_line,
125 if (!ascii_is_valid(n) || strlen(n) >= IFALIASZ) {
126 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
127 "Interface alias is not ASCII clean or is too long, ignoring assignment: %s", rvalue);
143 int config_parse_hwaddr(const char *unit,
144 const char *filename,
147 unsigned section_line,
153 struct ether_addr **hwaddr = data;
154 struct ether_addr *n;
162 n = new0(struct ether_addr, 1);
166 r = sscanf(rvalue, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
167 &n->ether_addr_octet[0],
168 &n->ether_addr_octet[1],
169 &n->ether_addr_octet[2],
170 &n->ether_addr_octet[3],
171 &n->ether_addr_octet[4],
172 &n->ether_addr_octet[5]);
174 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
175 "Not a valid MAC address, ignoring assignment: %s", rvalue);
186 int net_parse_inaddr(const char *address, unsigned char *family, void *dst) {
194 r = inet_pton(AF_INET, address, dst);
196 *family = AF_INET; /* successfully parsed IPv4 address */
200 /* not an IPv4 address, so let's try IPv6 */
201 r = inet_pton(AF_INET6, address, dst);
203 *family = AF_INET6; /* successfully parsed IPv6 address */