]>
Commit | Line | Data |
---|---|---|
1 | /* SPDX-License-Identifier: LGPL-2.1+ */ | |
2 | /*** | |
3 | Copyright © 2014 Vinay Kulkarni <kulkarniv@vmware.com> | |
4 | ***/ | |
5 | ||
6 | #include <ctype.h> | |
7 | ||
8 | #include "conf-parser.h" | |
9 | #include "def.h" | |
10 | #include "dhcp-identifier.h" | |
11 | #include "extract-word.h" | |
12 | #include "hexdecoct.h" | |
13 | #include "networkd-conf.h" | |
14 | #include "networkd-network.h" | |
15 | #include "string-table.h" | |
16 | ||
17 | int manager_parse_config_file(Manager *m) { | |
18 | assert(m); | |
19 | ||
20 | return config_parse_many_nulstr(PKGSYSCONFDIR "/networkd.conf", | |
21 | CONF_PATHS_NULSTR("systemd/networkd.conf.d"), | |
22 | "DHCP\0", | |
23 | config_item_perf_lookup, networkd_gperf_lookup, | |
24 | CONFIG_PARSE_WARN, m); | |
25 | } | |
26 | ||
27 | static const char* const duid_type_table[_DUID_TYPE_MAX] = { | |
28 | [DUID_TYPE_LLT] = "link-layer-time", | |
29 | [DUID_TYPE_EN] = "vendor", | |
30 | [DUID_TYPE_LL] = "link-layer", | |
31 | [DUID_TYPE_UUID] = "uuid", | |
32 | }; | |
33 | DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(duid_type, DUIDType); | |
34 | DEFINE_CONFIG_PARSE_ENUM(config_parse_duid_type, duid_type, DUIDType, "Failed to parse DUID type"); | |
35 | ||
36 | int config_parse_duid_rawdata( | |
37 | const char *unit, | |
38 | const char *filename, | |
39 | unsigned line, | |
40 | const char *section, | |
41 | unsigned section_line, | |
42 | const char *lvalue, | |
43 | int ltype, | |
44 | const char *rvalue, | |
45 | void *data, | |
46 | void *userdata) { | |
47 | ||
48 | DUID *ret = data; | |
49 | uint8_t raw_data[MAX_DUID_LEN]; | |
50 | unsigned count = 0; | |
51 | ||
52 | assert(filename); | |
53 | assert(lvalue); | |
54 | assert(rvalue); | |
55 | assert(ret); | |
56 | ||
57 | /* RawData contains DUID in format "NN:NN:NN..." */ | |
58 | for (;;) { | |
59 | int n1, n2, len, r; | |
60 | uint32_t byte; | |
61 | _cleanup_free_ char *cbyte = NULL; | |
62 | ||
63 | r = extract_first_word(&rvalue, &cbyte, ":", 0); | |
64 | if (r < 0) { | |
65 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to read DUID, ignoring assignment: %s.", rvalue); | |
66 | return 0; | |
67 | } | |
68 | if (r == 0) | |
69 | break; | |
70 | if (count >= MAX_DUID_LEN) { | |
71 | log_syntax(unit, LOG_ERR, filename, line, 0, "Max DUID length exceeded, ignoring assignment: %s.", rvalue); | |
72 | return 0; | |
73 | } | |
74 | ||
75 | len = strlen(cbyte); | |
76 | if (!IN_SET(len, 1, 2)) { | |
77 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid length - DUID byte: %s, ignoring assignment: %s.", cbyte, rvalue); | |
78 | return 0; | |
79 | } | |
80 | n1 = unhexchar(cbyte[0]); | |
81 | if (len == 2) | |
82 | n2 = unhexchar(cbyte[1]); | |
83 | else | |
84 | n2 = 0; | |
85 | ||
86 | if (n1 < 0 || n2 < 0) { | |
87 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid DUID byte: %s. Ignoring assignment: %s.", cbyte, rvalue); | |
88 | return 0; | |
89 | } | |
90 | ||
91 | byte = ((uint8_t) n1 << (4 * (len-1))) | (uint8_t) n2; | |
92 | raw_data[count++] = byte; | |
93 | } | |
94 | ||
95 | assert_cc(sizeof(raw_data) == sizeof(ret->raw_data)); | |
96 | memcpy(ret->raw_data, raw_data, count); | |
97 | ret->raw_data_len = count; | |
98 | return 0; | |
99 | } |