1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 Copyright © 2014 Vinay Kulkarni <kulkarniv@vmware.com>
7 #include <netinet/ip.h>
9 #include "conf-parser.h"
11 #include "dhcp-identifier.h"
12 #include "extract-word.h"
13 #include "hexdecoct.h"
14 #include "networkd-conf.h"
15 #include "networkd-manager.h"
16 #include "networkd-network.h"
17 #include "networkd-speed-meter.h"
18 #include "networkd-dhcp4.h"
19 #include "string-table.h"
21 int manager_parse_config_file(Manager
*m
) {
26 r
= config_parse_many_nulstr(
27 PKGSYSCONFDIR
"/networkd.conf",
28 CONF_PATHS_NULSTR("systemd/networkd.conf.d"),
31 config_item_perf_lookup
, networkd_gperf_lookup
,
38 if (m
->use_speed_meter
&& m
->speed_meter_interval_usec
< SPEED_METER_MINIMUM_TIME_INTERVAL
) {
39 char buf
[FORMAT_TIMESPAN_MAX
];
41 log_warning("SpeedMeterIntervalSec= is too small, using %s.",
42 format_timespan(buf
, sizeof buf
, SPEED_METER_MINIMUM_TIME_INTERVAL
, USEC_PER_SEC
));
43 m
->speed_meter_interval_usec
= SPEED_METER_MINIMUM_TIME_INTERVAL
;
49 static const char* const duid_type_table
[_DUID_TYPE_MAX
] = {
50 [DUID_TYPE_LLT
] = "link-layer-time",
51 [DUID_TYPE_EN
] = "vendor",
52 [DUID_TYPE_LL
] = "link-layer",
53 [DUID_TYPE_UUID
] = "uuid",
55 DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(duid_type
, DUIDType
);
57 int config_parse_duid_type(
62 unsigned section_line
,
69 _cleanup_free_
char *type_string
= NULL
;
70 const char *p
= rvalue
;
80 r
= extract_first_word(&p
, &type_string
, ":", 0);
84 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
85 "Invalid syntax, ignoring: %s", rvalue
);
89 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
90 "Failed to extract DUID type from '%s', ignoring.", rvalue
);
94 type
= duid_type_from_string(type_string
);
96 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
97 "Failed to parse DUID type '%s', ignoring.", type_string
);
104 if (type
!= DUID_TYPE_LLT
) {
105 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
106 "Invalid syntax, ignoring: %s", rvalue
);
110 r
= parse_timestamp(p
, &u
);
112 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
113 "Failed to parse timestamp, ignoring: %s", p
);
125 int config_parse_duid_rawdata(
127 const char *filename
,
130 unsigned section_line
,
138 uint8_t raw_data
[MAX_DUID_LEN
];
146 /* RawData contains DUID in format "NN:NN:NN..." */
147 for (const char *p
= rvalue
;;) {
150 _cleanup_free_
char *cbyte
= NULL
;
152 r
= extract_first_word(&p
, &cbyte
, ":", 0);
156 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to read DUID, ignoring assignment: %s.", rvalue
);
162 if (count
>= MAX_DUID_LEN
) {
163 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Max DUID length exceeded, ignoring assignment: %s.", rvalue
);
168 if (!IN_SET(len
, 1, 2)) {
169 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid length - DUID byte: %s, ignoring assignment: %s.", cbyte
, rvalue
);
172 n1
= unhexchar(cbyte
[0]);
174 n2
= unhexchar(cbyte
[1]);
178 if (n1
< 0 || n2
< 0) {
179 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid DUID byte: %s. Ignoring assignment: %s.", cbyte
, rvalue
);
183 byte
= ((uint8_t) n1
<< (4 * (len
-1))) | (uint8_t) n2
;
184 raw_data
[count
++] = byte
;
187 assert_cc(sizeof(raw_data
) == sizeof(ret
->raw_data
));
188 memcpy(ret
->raw_data
, raw_data
, count
);
189 ret
->raw_data_len
= count
;