Line data Source code
1 : /* SPDX-License-Identifier: LGPL-2.1+ */
2 :
3 : #include "networkd-dhcp-common.h"
4 : #include "networkd-network.h"
5 : #include "parse-util.h"
6 : #include "string-table.h"
7 : #include "strv.h"
8 :
9 1 : int config_parse_dhcp(
10 : const char* unit,
11 : const char *filename,
12 : unsigned line,
13 : const char *section,
14 : unsigned section_line,
15 : const char *lvalue,
16 : int ltype,
17 : const char *rvalue,
18 : void *data,
19 : void *userdata) {
20 :
21 1 : AddressFamily *dhcp = data, s;
22 :
23 1 : assert(filename);
24 1 : assert(lvalue);
25 1 : assert(rvalue);
26 1 : assert(data);
27 :
28 : /* Note that this is mostly like
29 : * config_parse_address_family(), except that it
30 : * understands some old names for the enum values */
31 :
32 1 : s = address_family_from_string(rvalue);
33 1 : if (s < 0) {
34 :
35 : /* Previously, we had a slightly different enum here,
36 : * support its values for compatibility. */
37 :
38 0 : if (streq(rvalue, "none"))
39 0 : s = ADDRESS_FAMILY_NO;
40 0 : else if (streq(rvalue, "v4"))
41 0 : s = ADDRESS_FAMILY_IPV4;
42 0 : else if (streq(rvalue, "v6"))
43 0 : s = ADDRESS_FAMILY_IPV6;
44 0 : else if (streq(rvalue, "both"))
45 0 : s = ADDRESS_FAMILY_YES;
46 : else {
47 0 : log_syntax(unit, LOG_ERR, filename, line, 0,
48 : "Failed to parse DHCP option, ignoring: %s", rvalue);
49 0 : return 0;
50 : }
51 :
52 0 : log_syntax(unit, LOG_WARNING, filename, line, 0,
53 : "DHCP=%s is deprecated, please use DHCP=%s instead.",
54 : rvalue, address_family_to_string(s));
55 : }
56 :
57 1 : *dhcp = s;
58 1 : return 0;
59 : }
60 :
61 0 : int config_parse_dhcp_use_dns(
62 : const char* unit,
63 : const char *filename,
64 : unsigned line,
65 : const char *section,
66 : unsigned section_line,
67 : const char *lvalue,
68 : int ltype,
69 : const char *rvalue,
70 : void *data,
71 : void *userdata) {
72 :
73 0 : Network *network = data;
74 : int r;
75 :
76 0 : assert(filename);
77 0 : assert(lvalue);
78 0 : assert(rvalue);
79 0 : assert(data);
80 :
81 0 : r = parse_boolean(rvalue);
82 0 : if (r < 0) {
83 0 : log_syntax(unit, LOG_ERR, filename, line, r,
84 : "Failed to parse UseDNS=%s, ignoring assignment: %m", rvalue);
85 0 : return 0;
86 : }
87 :
88 0 : network->dhcp_use_dns = r;
89 0 : network->dhcp6_use_dns = r;
90 :
91 0 : return 0;
92 : }
93 :
94 0 : int config_parse_dhcp_use_ntp(
95 : const char* unit,
96 : const char *filename,
97 : unsigned line,
98 : const char *section,
99 : unsigned section_line,
100 : const char *lvalue,
101 : int ltype,
102 : const char *rvalue,
103 : void *data,
104 : void *userdata) {
105 :
106 0 : Network *network = data;
107 : int r;
108 :
109 0 : assert(filename);
110 0 : assert(lvalue);
111 0 : assert(rvalue);
112 0 : assert(data);
113 :
114 0 : r = parse_boolean(rvalue);
115 0 : if (r < 0) {
116 0 : log_syntax(unit, LOG_ERR, filename, line, r,
117 : "Failed to parse UseNTP=%s, ignoring assignment: %m", rvalue);
118 0 : return 0;
119 : }
120 :
121 0 : network->dhcp_use_ntp = r;
122 0 : network->dhcp6_use_ntp = r;
123 :
124 0 : return 0;
125 : }
126 :
127 0 : int config_parse_section_route_table(
128 : const char *unit,
129 : const char *filename,
130 : unsigned line,
131 : const char *section,
132 : unsigned section_line,
133 : const char *lvalue,
134 : int ltype,
135 : const char *rvalue,
136 : void *data,
137 : void *userdata) {
138 :
139 0 : Network *network = data;
140 : uint32_t rt;
141 : int r;
142 :
143 0 : assert(filename);
144 0 : assert(lvalue);
145 0 : assert(rvalue);
146 0 : assert(data);
147 :
148 0 : r = safe_atou32(rvalue, &rt);
149 0 : if (r < 0) {
150 0 : log_syntax(unit, LOG_ERR, filename, line, r,
151 : "Failed to parse RouteTable=%s, ignoring assignment: %m", rvalue);
152 0 : return 0;
153 : }
154 :
155 0 : if (STRPTR_IN_SET(section, "DHCP", "DHCPv4")) {
156 0 : network->dhcp_route_table = rt;
157 0 : network->dhcp_route_table_set = true;
158 : } else { /* section is IPv6AcceptRA */
159 0 : network->ipv6_accept_ra_route_table = rt;
160 0 : network->ipv6_accept_ra_route_table_set = true;
161 : }
162 :
163 0 : return 0;
164 : }
165 :
166 0 : int config_parse_iaid(const char *unit,
167 : const char *filename,
168 : unsigned line,
169 : const char *section,
170 : unsigned section_line,
171 : const char *lvalue,
172 : int ltype,
173 : const char *rvalue,
174 : void *data,
175 : void *userdata) {
176 0 : Network *network = data;
177 : uint32_t iaid;
178 : int r;
179 :
180 0 : assert(filename);
181 0 : assert(lvalue);
182 0 : assert(rvalue);
183 0 : assert(network);
184 :
185 0 : r = safe_atou32(rvalue, &iaid);
186 0 : if (r < 0) {
187 0 : log_syntax(unit, LOG_ERR, filename, line, r,
188 : "Unable to read IAID, ignoring assignment: %s", rvalue);
189 0 : return 0;
190 : }
191 :
192 0 : network->iaid = iaid;
193 0 : network->iaid_set = true;
194 :
195 0 : return 0;
196 : }
197 :
198 0 : DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp_use_domains, dhcp_use_domains, DHCPUseDomains,
199 : "Failed to parse DHCP use domains setting");
200 :
201 : static const char* const dhcp_use_domains_table[_DHCP_USE_DOMAINS_MAX] = {
202 : [DHCP_USE_DOMAINS_NO] = "no",
203 : [DHCP_USE_DOMAINS_ROUTE] = "route",
204 : [DHCP_USE_DOMAINS_YES] = "yes",
205 : };
206 :
207 10 : DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(dhcp_use_domains, DHCPUseDomains, DHCP_USE_DOMAINS_YES);
|