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