]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/networkd-conf.c
tree-wide: beautify remaining copyright statements
[thirdparty/systemd.git] / src / network / networkd-conf.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
413708d1 2/***
96b2fb93 3 Copyright © 2014 Vinay Kulkarni <kulkarniv@vmware.com>
413708d1
VK
4 ***/
5
6#include <ctype.h>
7
8#include "conf-parser.h"
9#include "def.h"
10#include "dhcp-identifier.h"
23f53b99 11#include "extract-word.h"
b7f71444 12#include "hexdecoct.h"
413708d1 13#include "networkd-conf.h"
23f53b99 14#include "networkd-network.h"
413708d1
VK
15#include "string-table.h"
16
17int manager_parse_config_file(Manager *m) {
18 assert(m);
19
43688c49 20 return config_parse_many_nulstr(PKGSYSCONFDIR "/networkd.conf",
da412854
YW
21 CONF_PATHS_NULSTR("systemd/networkd.conf.d"),
22 "DHCP\0",
23 config_item_perf_lookup, networkd_gperf_lookup,
bcde742e 24 CONFIG_PARSE_WARN, m);
413708d1
VK
25}
26
27static const char* const duid_type_table[_DUID_TYPE_MAX] = {
413708d1
VK
28 [DUID_TYPE_LLT] = "link-layer-time",
29 [DUID_TYPE_EN] = "vendor",
30 [DUID_TYPE_LL] = "link-layer",
8341a5c3 31 [DUID_TYPE_UUID] = "uuid",
413708d1
VK
32};
33DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(duid_type, DUIDType);
34DEFINE_CONFIG_PARSE_ENUM(config_parse_duid_type, duid_type, DUIDType, "Failed to parse DUID type");
35
36int 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) {
076ea6f6 47
8341a5c3
ZJS
48 DUID *ret = data;
49 uint8_t raw_data[MAX_DUID_LEN];
50 unsigned count = 0;
413708d1
VK
51
52 assert(filename);
53 assert(lvalue);
54 assert(rvalue);
8341a5c3 55 assert(ret);
413708d1 56
8341a5c3 57 /* RawData contains DUID in format "NN:NN:NN..." */
b7f71444 58 for (;;) {
8341a5c3 59 int n1, n2, len, r;
076ea6f6 60 uint32_t byte;
82edec54 61 _cleanup_free_ char *cbyte = NULL;
076ea6f6 62
8341a5c3 63 r = extract_first_word(&rvalue, &cbyte, ":", 0);
413708d1 64 if (r < 0) {
076ea6f6
LP
65 log_syntax(unit, LOG_ERR, filename, line, r, "Failed to read DUID, ignoring assignment: %s.", rvalue);
66 return 0;
413708d1
VK
67 }
68 if (r == 0)
69 break;
8341a5c3 70 if (count >= MAX_DUID_LEN) {
076ea6f6
LP
71 log_syntax(unit, LOG_ERR, filename, line, 0, "Max DUID length exceeded, ignoring assignment: %s.", rvalue);
72 return 0;
413708d1
VK
73 }
74
b7f71444 75 len = strlen(cbyte);
4c701096 76 if (!IN_SET(len, 1, 2)) {
076ea6f6
LP
77 log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid length - DUID byte: %s, ignoring assignment: %s.", cbyte, rvalue);
78 return 0;
413708d1 79 }
b7f71444
VK
80 n1 = unhexchar(cbyte[0]);
81 if (len == 2)
82 n2 = unhexchar(cbyte[1]);
076ea6f6
LP
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;
b7f71444 89 }
076ea6f6
LP
90
91 byte = ((uint8_t) n1 << (4 * (len-1))) | (uint8_t) n2;
8341a5c3 92 raw_data[count++] = byte;
b7f71444 93 }
413708d1 94
8341a5c3
ZJS
95 assert_cc(sizeof(raw_data) == sizeof(ret->raw_data));
96 memcpy(ret->raw_data, raw_data, count);
97 ret->raw_data_len = count;
413708d1
VK
98 return 0;
99}