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) {
44 if (!dev_mac || memcmp(match_mac, ether_aton(dev_mac), ETH_ALEN)) {
45 log_debug("Interface MAC address (%s) did not match MACAddress=%s",
46 dev_mac, ether_ntoa(match_mac));
52 if (!streq_ptr(match_path, dev_path)) {
53 log_debug("Interface persistent path (%s) did not match Path=%s",
54 dev_path, match_path);
60 if (!streq_ptr(match_driver, dev_driver)) {
61 log_debug("Interface device driver (%s) did not match Driver=%s",
62 dev_driver, match_driver);
68 if (!streq_ptr(match_type, dev_type)) {
69 log_debug("Interface type (%s) did not match Type=%s",
70 dev_type, match_type);
76 if (!streq_ptr(match_name, dev_name)) {
77 log_debug("Interface name (%s) did not match Name=%s",
78 dev_name, match_name);
86 int config_parse_ifname(const char *unit,
90 unsigned section_line,
109 if (!ascii_is_valid(n) || strlen(n) >= IFNAMSIZ) {
110 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
111 "Interface name is not ASCII clean or is too long, ignoring assignment: %s", rvalue);
127 int config_parse_ifalias(const char *unit,
128 const char *filename,
131 unsigned section_line,
150 if (!ascii_is_valid(n) || strlen(n) >= IFALIASZ) {
151 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
152 "Interface alias is not ASCII clean or is too long, ignoring assignment: %s", rvalue);
168 int config_parse_hwaddr(const char *unit,
169 const char *filename,
172 unsigned section_line,
178 struct ether_addr **hwaddr = data;
179 struct ether_addr *n;
187 n = new0(struct ether_addr, 1);
191 r = sscanf(rvalue, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
192 &n->ether_addr_octet[0],
193 &n->ether_addr_octet[1],
194 &n->ether_addr_octet[2],
195 &n->ether_addr_octet[3],
196 &n->ether_addr_octet[4],
197 &n->ether_addr_octet[5]);
199 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
200 "Not a valid MAC address, ignoring assignment: %s", rvalue);
211 int net_parse_inaddr(const char *address, unsigned char *family, void *dst) {
219 r = inet_pton(AF_INET, address, dst);
221 *family = AF_INET; /* successfully parsed IPv4 address */
225 /* not an IPv4 address, so let's try IPv6 */
226 r = inet_pton(AF_INET6, address, dst);
228 *family = AF_INET6; /* successfully parsed IPv6 address */