]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-conf.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / network / networkd-conf.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 This file is part of systemd.
4
5 Copyright 2014 Vinay Kulkarni <kulkarniv@vmware.com>
6
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19 ***/
20
21 #include <ctype.h>
22
23 #include "conf-parser.h"
24 #include "def.h"
25 #include "dhcp-identifier.h"
26 #include "extract-word.h"
27 #include "hexdecoct.h"
28 #include "networkd-conf.h"
29 #include "networkd-network.h"
30 #include "string-table.h"
31
32 int manager_parse_config_file(Manager *m) {
33 assert(m);
34
35 return config_parse_many_nulstr(PKGSYSCONFDIR "/networkd.conf",
36 CONF_PATHS_NULSTR("systemd/networkd.conf.d"),
37 "DHCP\0",
38 config_item_perf_lookup, networkd_gperf_lookup,
39 CONFIG_PARSE_WARN, m);
40 }
41
42 static const char* const duid_type_table[_DUID_TYPE_MAX] = {
43 [DUID_TYPE_LLT] = "link-layer-time",
44 [DUID_TYPE_EN] = "vendor",
45 [DUID_TYPE_LL] = "link-layer",
46 [DUID_TYPE_UUID] = "uuid",
47 };
48 DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(duid_type, DUIDType);
49 DEFINE_CONFIG_PARSE_ENUM(config_parse_duid_type, duid_type, DUIDType, "Failed to parse DUID type");
50
51 int config_parse_duid_rawdata(
52 const char *unit,
53 const char *filename,
54 unsigned line,
55 const char *section,
56 unsigned section_line,
57 const char *lvalue,
58 int ltype,
59 const char *rvalue,
60 void *data,
61 void *userdata) {
62
63 DUID *ret = data;
64 uint8_t raw_data[MAX_DUID_LEN];
65 unsigned count = 0;
66
67 assert(filename);
68 assert(lvalue);
69 assert(rvalue);
70 assert(ret);
71
72 /* RawData contains DUID in format "NN:NN:NN..." */
73 for (;;) {
74 int n1, n2, len, r;
75 uint32_t byte;
76 _cleanup_free_ char *cbyte = NULL;
77
78 r = extract_first_word(&rvalue, &cbyte, ":", 0);
79 if (r < 0) {
80 log_syntax(unit, LOG_ERR, filename, line, r, "Failed to read DUID, ignoring assignment: %s.", rvalue);
81 return 0;
82 }
83 if (r == 0)
84 break;
85 if (count >= MAX_DUID_LEN) {
86 log_syntax(unit, LOG_ERR, filename, line, 0, "Max DUID length exceeded, ignoring assignment: %s.", rvalue);
87 return 0;
88 }
89
90 len = strlen(cbyte);
91 if (!IN_SET(len, 1, 2)) {
92 log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid length - DUID byte: %s, ignoring assignment: %s.", cbyte, rvalue);
93 return 0;
94 }
95 n1 = unhexchar(cbyte[0]);
96 if (len == 2)
97 n2 = unhexchar(cbyte[1]);
98 else
99 n2 = 0;
100
101 if (n1 < 0 || n2 < 0) {
102 log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid DUID byte: %s. Ignoring assignment: %s.", cbyte, rvalue);
103 return 0;
104 }
105
106 byte = ((uint8_t) n1 << (4 * (len-1))) | (uint8_t) n2;
107 raw_data[count++] = byte;
108 }
109
110 assert_cc(sizeof(raw_data) == sizeof(ret->raw_data));
111 memcpy(ret->raw_data, raw_data, count);
112 ret->raw_data_len = count;
113 return 0;
114 }