1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2014 Vinay Kulkarni <kulkarniv@vmware.com>
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 #include "conf-parser.h"
26 #include "dhcp-identifier.h"
27 #include "networkd-conf.h"
28 #include "string-table.h"
30 int manager_parse_config_file(Manager
*m
) {
33 return config_parse_many(PKGSYSCONFDIR
"/networkd.conf",
34 CONF_PATHS_NULSTR("systemd/networkd.conf.d"),
36 config_item_perf_lookup
, networkd_gperf_lookup
,
40 static const char* const duid_type_table
[_DUID_TYPE_MAX
] = {
41 [DUID_TYPE_RAW
] = "raw",
42 [DUID_TYPE_LLT
] = "link-layer-time",
43 [DUID_TYPE_EN
] = "vendor",
44 [DUID_TYPE_LL
] = "link-layer",
45 [DUID_TYPE_UUID
] = "uuid"
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");
50 int config_parse_duid_rawdata(
55 unsigned section_line
,
64 const char *pduid
= rvalue
;
65 size_t count
= 0, duid_index
= 0;
69 uint16_t *dhcp_duid_type
;
70 size_t *dhcp_duid_len
;
78 if (ltype
== DUID_CONFIG_SOURCE_GLOBAL
) {
80 duid_type
= &m
->duid_type
;
81 dhcp_duid_type
= &m
->dhcp_duid_type
;
82 dhcp_duid_len
= &m
->dhcp_duid_len
;
83 dhcp_duid
= m
->dhcp_duid
;
85 /* DUID_CONFIG_SOURCE_NETWORK */
87 duid_type
= &n
->duid_type
;
88 dhcp_duid_type
= &n
->dhcp_duid_type
;
89 dhcp_duid_len
= &n
->dhcp_duid_len
;
90 dhcp_duid
= n
->dhcp_duid
;
93 if (*duid_type
== _DUID_TYPE_INVALID
)
94 *duid_type
= DUID_TYPE_RAW
;
98 /* RawData contains DUID-LLT link-layer address (offset 6) */
102 /* RawData contains DUID-EN identifier (offset 4) */
106 /* RawData contains DUID-LL link-layer address (offset 2) */
110 /* RawData specifies UUID (offset 0) - fall thru */
112 /* First two bytes of RawData is DUID Type - fall thru */
117 if (*duid_type
!= DUID_TYPE_RAW
)
118 *dhcp_duid_type
= (uint16_t)(*duid_type
);
120 /* RawData contains DUID in format " NN:NN:NN... " */
122 r
= extract_first_word(&pduid
, &cbyte
, ":", 0);
124 log_error("Failed to read DUID.");
129 if (duid_index
>= MAX_DUID_LEN
) {
130 log_error("DUID length exceeds maximum length.");
135 byte
= strtol(cbyte
, &pnext
, 16);
136 if ((errno
== ERANGE
&& (byte
== LONG_MAX
|| byte
== LONG_MIN
))
137 || (errno
!= 0 && byte
== 0) || (cbyte
== pnext
)) {
138 log_error("Invalid DUID byte: %s.", cbyte
);
142 /* If DUID_TYPE_RAW, first two bytes hold DHCP DUID type code */
143 if ((*duid_type
== DUID_TYPE_RAW
) && (count
< 2)) {
144 *dhcp_duid_type
|= (byte
<< (8 * (1 - count
)));
149 dhcp_duid
[duid_index
++] = byte
;
152 *dhcp_duid_len
= duid_index
;