File: | build-scan/../src/network/networkd-network.c |
Warning: | line 147, column 24 Potential leak of memory pointed to by 'network' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* SPDX-License-Identifier: LGPL-2.1+ */ | |||
2 | ||||
3 | #include <ctype.h> | |||
4 | #include <net/if.h> | |||
5 | ||||
6 | #include "alloc-util.h" | |||
7 | #include "conf-files.h" | |||
8 | #include "conf-parser.h" | |||
9 | #include "dns-domain.h" | |||
10 | #include "fd-util.h" | |||
11 | #include "hostname-util.h" | |||
12 | #include "in-addr-util.h" | |||
13 | #include "network-internal.h" | |||
14 | #include "networkd-manager.h" | |||
15 | #include "networkd-network.h" | |||
16 | #include "parse-util.h" | |||
17 | #include "set.h" | |||
18 | #include "stat-util.h" | |||
19 | #include "string-table.h" | |||
20 | #include "string-util.h" | |||
21 | #include "strv.h" | |||
22 | #include "util.h" | |||
23 | ||||
24 | static void network_config_hash_func(const void *p, struct siphash *state) { | |||
25 | const NetworkConfigSection *c = p; | |||
26 | ||||
27 | siphash24_compress(c->filename, strlen(c->filename), state); | |||
28 | siphash24_compress(&c->line, sizeof(c->line), state); | |||
29 | } | |||
30 | ||||
31 | static int network_config_compare_func(const void *a, const void *b) { | |||
32 | const NetworkConfigSection *x = a, *y = b; | |||
33 | int r; | |||
34 | ||||
35 | r = strcmp(x->filename, y->filename); | |||
36 | if (r != 0) | |||
37 | return r; | |||
38 | ||||
39 | return y->line - x->line; | |||
40 | } | |||
41 | ||||
42 | const struct hash_ops network_config_hash_ops = { | |||
43 | .hash = network_config_hash_func, | |||
44 | .compare = network_config_compare_func, | |||
45 | }; | |||
46 | ||||
47 | int network_config_section_new(const char *filename, unsigned line, NetworkConfigSection **s) { | |||
48 | NetworkConfigSection *cs; | |||
49 | ||||
50 | cs = malloc0(offsetof(NetworkConfigSection, filename) + strlen(filename) + 1)(calloc(1, (__builtin_offsetof(NetworkConfigSection, filename ) + strlen(filename) + 1))); | |||
51 | if (!cs) | |||
52 | return -ENOMEM12; | |||
53 | ||||
54 | strcpy(cs->filename, filename); | |||
55 | cs->line = line; | |||
56 | ||||
57 | *s = TAKE_PTR(cs)({ typeof(cs) _ptr_ = (cs); (cs) = ((void*)0); _ptr_; }); | |||
58 | ||||
59 | return 0; | |||
60 | } | |||
61 | ||||
62 | void network_config_section_free(NetworkConfigSection *cs) { | |||
63 | free(cs); | |||
64 | } | |||
65 | ||||
66 | /* Set defaults following RFC7844 */ | |||
67 | void network_apply_anonymize_if_set(Network *network) { | |||
68 | if (!network->dhcp_anonymize) | |||
69 | return; | |||
70 | /* RFC7844 3.7 | |||
71 | SHOULD NOT send the Host Name option */ | |||
72 | network->dhcp_send_hostname = false0; | |||
73 | /* RFC7844 section 3.: | |||
74 | MAY contain the Client Identifier option | |||
75 | Section 3.5: | |||
76 | clients MUST use client identifiers based solely | |||
77 | on the link-layer address */ | |||
78 | /* NOTE: Using MAC, as it does not reveal extra information, | |||
79 | * and some servers might not answer if this option is not sent */ | |||
80 | network->dhcp_client_identifier = DHCP_CLIENT_ID_MAC; | |||
81 | /* RFC 7844 3.10: | |||
82 | SHOULD NOT use the Vendor Class Identifier option */ | |||
83 | /* NOTE: it was not initiallized to any value in network_load_one. */ | |||
84 | network->dhcp_vendor_class_identifier = false0; | |||
85 | /* RFC7844 section 3.6.: | |||
86 | The client intending to protect its privacy SHOULD only request a | |||
87 | minimal number of options in the PRL and SHOULD also randomly shuffle | |||
88 | the ordering of option codes in the PRL. If this random ordering | |||
89 | cannot be implemented, the client MAY order the option codes in the | |||
90 | PRL by option code number (lowest to highest). | |||
91 | */ | |||
92 | /* NOTE: dhcp_use_mtu is false by default, | |||
93 | * though it was not initiallized to any value in network_load_one. | |||
94 | * Maybe there should be another var called *send*? | |||
95 | * (to use the MTU sent by the server but to do not send | |||
96 | * the option in the PRL). */ | |||
97 | network->dhcp_use_mtu = false0; | |||
98 | /* NOTE: when Anonymize=yes, the PRL route options are sent by default, | |||
99 | * but this is needed to use them. */ | |||
100 | network->dhcp_use_routes = true1; | |||
101 | /* RFC7844 section 3.6. | |||
102 | * same comments as previous option */ | |||
103 | network->dhcp_use_timezone = false0; | |||
104 | } | |||
105 | ||||
106 | static int network_load_one(Manager *manager, const char *filename) { | |||
107 | _cleanup_(network_freep)__attribute__((cleanup(network_freep))) Network *network = NULL((void*)0); | |||
108 | _cleanup_fclose___attribute__((cleanup(fclosep))) FILE *file = NULL((void*)0); | |||
109 | char *d; | |||
110 | const char *dropin_dirname; | |||
111 | Route *route; | |||
112 | Address *address; | |||
113 | int r; | |||
114 | ||||
115 | assert(manager)do { if ((__builtin_expect(!!(!(manager)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("manager"), "../src/network/networkd-network.c" , 115, __PRETTY_FUNCTION__); } while (0); | |||
| ||||
116 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/network/networkd-network.c" , 116, __PRETTY_FUNCTION__); } while (0); | |||
117 | ||||
118 | file = fopen(filename, "re"); | |||
119 | if (!file) { | |||
120 | if (errno(*__errno_location ()) == ENOENT2) | |||
121 | return 0; | |||
122 | ||||
123 | return -errno(*__errno_location ()); | |||
124 | } | |||
125 | ||||
126 | if (null_or_empty_fd(fileno(file))) { | |||
127 | log_debug("Skipping empty file: %s", filename)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/network/networkd-network.c", 127, __func__, "Skipping empty file: %s" , filename) : -abs(_e); }); | |||
128 | return 0; | |||
129 | } | |||
130 | ||||
131 | network = new0(Network, 1)((Network*) calloc((1), sizeof(Network))); | |||
132 | if (!network) | |||
133 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 133, __func__); | |||
134 | ||||
135 | network->manager = manager; | |||
136 | ||||
137 | LIST_HEAD_INIT(network->static_addresses)do { (network->static_addresses) = ((void*)0); } while (0); | |||
138 | LIST_HEAD_INIT(network->static_routes)do { (network->static_routes) = ((void*)0); } while (0); | |||
139 | LIST_HEAD_INIT(network->static_fdb_entries)do { (network->static_fdb_entries) = ((void*)0); } while ( 0); | |||
140 | LIST_HEAD_INIT(network->ipv6_proxy_ndp_addresses)do { (network->ipv6_proxy_ndp_addresses) = ((void*)0); } while (0); | |||
141 | LIST_HEAD_INIT(network->address_labels)do { (network->address_labels) = ((void*)0); } while (0); | |||
142 | LIST_HEAD_INIT(network->static_prefixes)do { (network->static_prefixes) = ((void*)0); } while (0); | |||
143 | LIST_HEAD_INIT(network->rules)do { (network->rules) = ((void*)0); } while (0); | |||
144 | ||||
145 | network->stacked_netdevs = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops ); | |||
146 | if (!network->stacked_netdevs) | |||
147 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 147, __func__); | |||
| ||||
148 | ||||
149 | network->addresses_by_section = hashmap_new(&network_config_hash_ops)internal_hashmap_new(&network_config_hash_ops ); | |||
150 | if (!network->addresses_by_section) | |||
151 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 151, __func__); | |||
152 | ||||
153 | network->routes_by_section = hashmap_new(&network_config_hash_ops)internal_hashmap_new(&network_config_hash_ops ); | |||
154 | if (!network->routes_by_section) | |||
155 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 155, __func__); | |||
156 | ||||
157 | network->fdb_entries_by_section = hashmap_new(NULL)internal_hashmap_new(((void*)0) ); | |||
158 | if (!network->fdb_entries_by_section) | |||
159 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 159, __func__); | |||
160 | ||||
161 | network->address_labels_by_section = hashmap_new(&network_config_hash_ops)internal_hashmap_new(&network_config_hash_ops ); | |||
162 | if (!network->address_labels_by_section) | |||
163 | log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 163, __func__); | |||
164 | ||||
165 | network->prefixes_by_section = hashmap_new(&network_config_hash_ops)internal_hashmap_new(&network_config_hash_ops ); | |||
166 | if (!network->prefixes_by_section) | |||
167 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 167, __func__); | |||
168 | ||||
169 | network->rules_by_section = hashmap_new(&network_config_hash_ops)internal_hashmap_new(&network_config_hash_ops ); | |||
170 | if (!network->rules_by_section) | |||
171 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 171, __func__); | |||
172 | ||||
173 | network->filename = strdup(filename); | |||
174 | if (!network->filename) | |||
175 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 175, __func__); | |||
176 | ||||
177 | network->name = strdup(basename(filename)); | |||
178 | if (!network->name) | |||
179 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 179, __func__); | |||
180 | ||||
181 | d = strrchr(network->name, '.'); | |||
182 | if (!d) | |||
183 | return -EINVAL22; | |||
184 | ||||
185 | assert(streq(d, ".network"))do { if ((__builtin_expect(!!(!((strcmp((d),(".network")) == 0 ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(d, \".network\")" ), "../src/network/networkd-network.c", 185, __PRETTY_FUNCTION__ ); } while (0); | |||
186 | ||||
187 | *d = '\0'; | |||
188 | ||||
189 | network->required_for_online = true1; | |||
190 | network->dhcp = ADDRESS_FAMILY_NO; | |||
191 | network->dhcp_use_ntp = true1; | |||
192 | network->dhcp_use_dns = true1; | |||
193 | network->dhcp_use_hostname = true1; | |||
194 | network->dhcp_use_routes = true1; | |||
195 | /* NOTE: this var might be overwriten by network_apply_anonymize_if_set */ | |||
196 | network->dhcp_send_hostname = true1; | |||
197 | /* To enable/disable RFC7844 Anonymity Profiles */ | |||
198 | network->dhcp_anonymize = false0; | |||
199 | network->dhcp_route_metric = DHCP_ROUTE_METRIC1024; | |||
200 | /* NOTE: this var might be overwrite by network_apply_anonymize_if_set */ | |||
201 | network->dhcp_client_identifier = DHCP_CLIENT_ID_DUID; | |||
202 | network->dhcp_route_table = RT_TABLE_MAIN; | |||
203 | network->dhcp_route_table_set = false0; | |||
204 | /* NOTE: the following vars were not set to any default, | |||
205 | * even if they are commented in the man? | |||
206 | * These vars might be overwriten by network_apply_anonymize_if_set */ | |||
207 | network->dhcp_vendor_class_identifier = false0; | |||
208 | /* NOTE: from man: UseMTU=... Defaults to false*/ | |||
209 | network->dhcp_use_mtu = false0; | |||
210 | /* NOTE: from man: UseTimezone=... Defaults to "no".*/ | |||
211 | network->dhcp_use_timezone = false0; | |||
212 | network->rapid_commit = true1; | |||
213 | ||||
214 | network->dhcp_server_emit_dns = true1; | |||
215 | network->dhcp_server_emit_ntp = true1; | |||
216 | network->dhcp_server_emit_router = true1; | |||
217 | network->dhcp_server_emit_timezone = true1; | |||
218 | ||||
219 | network->router_emit_dns = true1; | |||
220 | network->router_emit_domains = true1; | |||
221 | ||||
222 | network->use_bpdu = -1; | |||
223 | network->hairpin = -1; | |||
224 | network->fast_leave = -1; | |||
225 | network->allow_port_to_be_root = -1; | |||
226 | network->unicast_flood = -1; | |||
227 | network->priority = LINK_BRIDGE_PORT_PRIORITY_INVALID128; | |||
228 | ||||
229 | network->lldp_mode = LLDP_MODE_ROUTERS_ONLY; | |||
230 | ||||
231 | network->llmnr = RESOLVE_SUPPORT_YES; | |||
232 | network->mdns = RESOLVE_SUPPORT_NO; | |||
233 | network->dnssec_mode = _DNSSEC_MODE_INVALID; | |||
234 | network->dns_over_tls_mode = _DNS_OVER_TLS_MODE_INVALID; | |||
235 | ||||
236 | network->link_local = ADDRESS_FAMILY_IPV6; | |||
237 | ||||
238 | network->ipv6_privacy_extensions = IPV6_PRIVACY_EXTENSIONS_NO; | |||
239 | network->ipv6_accept_ra = -1; | |||
240 | network->ipv6_dad_transmits = -1; | |||
241 | network->ipv6_hop_limit = -1; | |||
242 | network->ipv6_proxy_ndp = -1; | |||
243 | network->duid.type = _DUID_TYPE_INVALID; | |||
244 | network->proxy_arp = -1; | |||
245 | network->arp = -1; | |||
246 | network->multicast = -1; | |||
247 | network->allmulticast = -1; | |||
248 | network->ipv6_accept_ra_use_dns = true1; | |||
249 | network->ipv6_accept_ra_route_table = RT_TABLE_MAIN; | |||
250 | network->ipv6_mtu = 0; | |||
251 | ||||
252 | dropin_dirname = strjoina(network->name, ".network.d")({ const char *_appendees_[] = { network->name, ".network.d" }; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p (typeof(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
253 | ||||
254 | r = config_parse_many(filename, network_dirs, dropin_dirname, | |||
255 | "Match\0" | |||
256 | "Link\0" | |||
257 | "Network\0" | |||
258 | "Address\0" | |||
259 | "IPv6AddressLabel\0" | |||
260 | "RoutingPolicyRule\0" | |||
261 | "Route\0" | |||
262 | "DHCP\0" | |||
263 | "DHCPv4\0" /* compat */ | |||
264 | "DHCPServer\0" | |||
265 | "IPv6AcceptRA\0" | |||
266 | "IPv6NDPProxyAddress\0" | |||
267 | "Bridge\0" | |||
268 | "BridgeFDB\0" | |||
269 | "BridgeVLAN\0" | |||
270 | "IPv6PrefixDelegation\0" | |||
271 | "IPv6Prefix\0" | |||
272 | "CAN\0", | |||
273 | config_item_perf_lookup, network_network_gperf_lookup, | |||
274 | CONFIG_PARSE_WARN, network); | |||
275 | if (r < 0) | |||
276 | return r; | |||
277 | ||||
278 | network_apply_anonymize_if_set(network); | |||
279 | ||||
280 | /* IPMasquerade=yes implies IPForward=yes */ | |||
281 | if (network->ip_masquerade) | |||
282 | network->ip_forward |= ADDRESS_FAMILY_IPV4; | |||
283 | ||||
284 | LIST_PREPEND(networks, manager->networks, network)do { typeof(*(manager->networks)) **_head = &(manager-> networks), *_item = (network); do { if ((__builtin_expect(!!( !(_item)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("_item" ), "../src/network/networkd-network.c", 284, __PRETTY_FUNCTION__ ); } while (0); if ((_item->networks_next = *_head)) _item ->networks_next->networks_prev = _item; _item->networks_prev = ((void*)0); *_head = _item; } while (0); | |||
285 | ||||
286 | r = hashmap_ensure_allocated(&manager->networks_by_name, &string_hash_ops)internal_hashmap_ensure_allocated(&manager->networks_by_name , &string_hash_ops ); | |||
287 | if (r < 0) | |||
288 | return r; | |||
289 | ||||
290 | r = hashmap_put(manager->networks_by_name, network->name, network); | |||
291 | if (r < 0) | |||
292 | return r; | |||
293 | ||||
294 | LIST_FOREACH(routes, route, network->static_routes)for ((route) = (network->static_routes); (route); (route) = (route)->routes_next) { | |||
295 | if (!route->family) { | |||
296 | log_warning("Route section without Gateway field configured in %s. "({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/network/networkd-network.c", 297, __func__, "Route section without Gateway field configured in %s. " "Ignoring", filename) : -abs(_e); }) | |||
297 | "Ignoring", filename)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/network/networkd-network.c", 297, __func__, "Route section without Gateway field configured in %s. " "Ignoring", filename) : -abs(_e); }); | |||
298 | return 0; | |||
299 | } | |||
300 | } | |||
301 | ||||
302 | LIST_FOREACH(addresses, address, network->static_addresses)for ((address) = (network->static_addresses); (address); ( address) = (address)->addresses_next) { | |||
303 | if (!address->family) { | |||
304 | log_warning("Address section without Address field configured in %s. "({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/network/networkd-network.c", 305, __func__, "Address section without Address field configured in %s. " "Ignoring", filename) : -abs(_e); }) | |||
305 | "Ignoring", filename)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/network/networkd-network.c", 305, __func__, "Address section without Address field configured in %s. " "Ignoring", filename) : -abs(_e); }); | |||
306 | return 0; | |||
307 | } | |||
308 | } | |||
309 | ||||
310 | network = NULL((void*)0); | |||
311 | ||||
312 | return 0; | |||
313 | } | |||
314 | ||||
315 | int network_load(Manager *manager) { | |||
316 | Network *network; | |||
317 | _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **files = NULL((void*)0); | |||
318 | char **f; | |||
319 | int r; | |||
320 | ||||
321 | assert(manager)do { if ((__builtin_expect(!!(!(manager)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("manager"), "../src/network/networkd-network.c" , 321, __PRETTY_FUNCTION__); } while (0); | |||
322 | ||||
323 | while ((network = manager->networks)) | |||
324 | network_free(network); | |||
325 | ||||
326 | r = conf_files_list_strv(&files, ".network", NULL((void*)0), 0, network_dirs); | |||
327 | if (r < 0) | |||
328 | return log_error_errno(r, "Failed to enumerate network files: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/network/networkd-network.c", 328, __func__, "Failed to enumerate network files: %m" ) : -abs(_e); }); | |||
329 | ||||
330 | STRV_FOREACH_BACKWARDS(f, files)for (f = ({ char **_l = files; _l ? _l + strv_length(_l) - 1U : ((void*)0); }); (files) && ((f) >= (files)); (f )--) { | |||
331 | r = network_load_one(manager, *f); | |||
332 | if (r < 0) | |||
333 | return r; | |||
334 | } | |||
335 | ||||
336 | return 0; | |||
337 | } | |||
338 | ||||
339 | void network_free(Network *network) { | |||
340 | IPv6ProxyNDPAddress *ipv6_proxy_ndp_address; | |||
341 | RoutingPolicyRule *rule; | |||
342 | FdbEntry *fdb_entry; | |||
343 | AddressLabel *label; | |||
344 | Prefix *prefix; | |||
345 | Address *address; | |||
346 | NetDev *netdev; | |||
347 | Route *route; | |||
348 | Iterator i; | |||
349 | ||||
350 | if (!network) | |||
351 | return; | |||
352 | ||||
353 | free(network->filename); | |||
354 | ||||
355 | set_free_free(network->match_mac); | |||
356 | strv_free(network->match_path); | |||
357 | strv_free(network->match_driver); | |||
358 | strv_free(network->match_type); | |||
359 | strv_free(network->match_name); | |||
360 | ||||
361 | free(network->description); | |||
362 | free(network->dhcp_vendor_class_identifier); | |||
363 | strv_free(network->dhcp_user_class); | |||
364 | free(network->dhcp_hostname); | |||
365 | ||||
366 | free(network->mac); | |||
367 | ||||
368 | strv_free(network->ntp); | |||
369 | free(network->dns); | |||
370 | strv_free(network->search_domains); | |||
371 | strv_free(network->route_domains); | |||
372 | strv_free(network->bind_carrier); | |||
373 | ||||
374 | netdev_unref(network->bridge); | |||
375 | netdev_unref(network->bond); | |||
376 | netdev_unref(network->vrf); | |||
377 | ||||
378 | HASHMAP_FOREACH(netdev, network->stacked_netdevs, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), . next_key = ((void*)0) }); hashmap_iterate((network->stacked_netdevs ), &(i), (void**)&(netdev), ((void*)0)); ) { | |||
379 | hashmap_remove(network->stacked_netdevs, netdev->ifname); | |||
380 | netdev_unref(netdev); | |||
381 | } | |||
382 | hashmap_free(network->stacked_netdevs); | |||
383 | ||||
384 | while ((route = network->static_routes)) | |||
385 | route_free(route); | |||
386 | ||||
387 | while ((address = network->static_addresses)) | |||
388 | address_free(address); | |||
389 | ||||
390 | while ((fdb_entry = network->static_fdb_entries)) | |||
391 | fdb_entry_free(fdb_entry); | |||
392 | ||||
393 | while ((ipv6_proxy_ndp_address = network->ipv6_proxy_ndp_addresses)) | |||
394 | ipv6_proxy_ndp_address_free(ipv6_proxy_ndp_address); | |||
395 | ||||
396 | while ((label = network->address_labels)) | |||
397 | address_label_free(label); | |||
398 | ||||
399 | while ((prefix = network->static_prefixes)) | |||
400 | prefix_free(prefix); | |||
401 | ||||
402 | while ((rule = network->rules)) | |||
403 | routing_policy_rule_free(rule); | |||
404 | ||||
405 | hashmap_free(network->addresses_by_section); | |||
406 | hashmap_free(network->routes_by_section); | |||
407 | hashmap_free(network->fdb_entries_by_section); | |||
408 | hashmap_free(network->address_labels_by_section); | |||
409 | hashmap_free(network->prefixes_by_section); | |||
410 | hashmap_free(network->rules_by_section); | |||
411 | ||||
412 | if (network->manager) { | |||
413 | if (network->manager->networks) | |||
414 | LIST_REMOVE(networks, network->manager->networks, network)do { typeof(*(network->manager->networks)) **_head = & (network->manager->networks), *_item = (network); do { if ((__builtin_expect(!!(!(_item)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("_item"), "../src/network/networkd-network.c" , 414, __PRETTY_FUNCTION__); } while (0); if (_item->networks_next ) _item->networks_next->networks_prev = _item->networks_prev ; if (_item->networks_prev) _item->networks_prev->networks_next = _item->networks_next; else { do { if ((__builtin_expect (!!(!(*_head == _item)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("*_head == _item"), "../src/network/networkd-network.c", 414 , __PRETTY_FUNCTION__); } while (0); *_head = _item->networks_next ; } _item->networks_next = _item->networks_prev = ((void *)0); } while (0); | |||
415 | ||||
416 | if (network->manager->networks_by_name) | |||
417 | hashmap_remove(network->manager->networks_by_name, network->name); | |||
418 | } | |||
419 | ||||
420 | free(network->name); | |||
421 | ||||
422 | condition_free_list(network->match_host); | |||
423 | condition_free_list(network->match_virt); | |||
424 | condition_free_list(network->match_kernel_cmdline); | |||
425 | condition_free_list(network->match_kernel_version); | |||
426 | condition_free_list(network->match_arch); | |||
427 | ||||
428 | free(network->dhcp_server_timezone); | |||
429 | free(network->dhcp_server_dns); | |||
430 | free(network->dhcp_server_ntp); | |||
431 | ||||
432 | set_free_free(network->dnssec_negative_trust_anchors); | |||
433 | ||||
434 | free(network); | |||
435 | } | |||
436 | ||||
437 | int network_get_by_name(Manager *manager, const char *name, Network **ret) { | |||
438 | Network *network; | |||
439 | ||||
440 | assert(manager)do { if ((__builtin_expect(!!(!(manager)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("manager"), "../src/network/networkd-network.c" , 440, __PRETTY_FUNCTION__); } while (0); | |||
441 | assert(name)do { if ((__builtin_expect(!!(!(name)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("name"), "../src/network/networkd-network.c" , 441, __PRETTY_FUNCTION__); } while (0); | |||
442 | assert(ret)do { if ((__builtin_expect(!!(!(ret)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ret"), "../src/network/networkd-network.c" , 442, __PRETTY_FUNCTION__); } while (0); | |||
443 | ||||
444 | network = hashmap_get(manager->networks_by_name, name); | |||
445 | if (!network) | |||
446 | return -ENOENT2; | |||
447 | ||||
448 | *ret = network; | |||
449 | ||||
450 | return 0; | |||
451 | } | |||
452 | ||||
453 | int network_get(Manager *manager, struct udev_device *device, | |||
454 | const char *ifname, const struct ether_addr *address, | |||
455 | Network **ret) { | |||
456 | Network *network; | |||
457 | struct udev_device *parent; | |||
458 | const char *path = NULL((void*)0), *parent_driver = NULL((void*)0), *driver = NULL((void*)0), *devtype = NULL((void*)0); | |||
459 | ||||
460 | assert(manager)do { if ((__builtin_expect(!!(!(manager)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("manager"), "../src/network/networkd-network.c" , 460, __PRETTY_FUNCTION__); } while (0); | |||
461 | assert(ret)do { if ((__builtin_expect(!!(!(ret)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ret"), "../src/network/networkd-network.c" , 461, __PRETTY_FUNCTION__); } while (0); | |||
462 | ||||
463 | if (device) { | |||
464 | path = udev_device_get_property_value(device, "ID_PATH"); | |||
465 | ||||
466 | parent = udev_device_get_parent(device); | |||
467 | if (parent) | |||
468 | parent_driver = udev_device_get_driver(parent); | |||
469 | ||||
470 | driver = udev_device_get_property_value(device, "ID_NET_DRIVER"); | |||
471 | ||||
472 | devtype = udev_device_get_devtype(device); | |||
473 | } | |||
474 | ||||
475 | LIST_FOREACH(networks, network, manager->networks)for ((network) = (manager->networks); (network); (network) = (network)->networks_next) { | |||
476 | if (net_match_config(network->match_mac, network->match_path, | |||
477 | network->match_driver, network->match_type, | |||
478 | network->match_name, network->match_host, | |||
479 | network->match_virt, network->match_kernel_cmdline, | |||
480 | network->match_kernel_version, network->match_arch, | |||
481 | address, path, parent_driver, driver, | |||
482 | devtype, ifname)) { | |||
483 | if (network->match_name && device) { | |||
484 | const char *attr; | |||
485 | uint8_t name_assign_type = NET_NAME_UNKNOWN0; | |||
486 | ||||
487 | attr = udev_device_get_sysattr_value(device, "name_assign_type"); | |||
488 | if (attr) | |||
489 | (void) safe_atou8(attr, &name_assign_type); | |||
490 | ||||
491 | if (name_assign_type == NET_NAME_ENUM1) | |||
492 | log_warning("%s: found matching network '%s', based on potentially unpredictable ifname",({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/network/networkd-network.c", 493, __func__, "%s: found matching network '%s', based on potentially unpredictable ifname" , ifname, network->filename) : -abs(_e); }) | |||
493 | ifname, network->filename)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/network/networkd-network.c", 493, __func__, "%s: found matching network '%s', based on potentially unpredictable ifname" , ifname, network->filename) : -abs(_e); }); | |||
494 | else | |||
495 | log_debug("%s: found matching network '%s'", ifname, network->filename)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/network/networkd-network.c", 495, __func__, "%s: found matching network '%s'" , ifname, network->filename) : -abs(_e); }); | |||
496 | } else | |||
497 | log_debug("%s: found matching network '%s'", ifname, network->filename)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/network/networkd-network.c", 497, __func__, "%s: found matching network '%s'" , ifname, network->filename) : -abs(_e); }); | |||
498 | ||||
499 | *ret = network; | |||
500 | return 0; | |||
501 | } | |||
502 | } | |||
503 | ||||
504 | *ret = NULL((void*)0); | |||
505 | ||||
506 | return -ENOENT2; | |||
507 | } | |||
508 | ||||
509 | int network_apply(Network *network, Link *link) { | |||
510 | int r; | |||
511 | ||||
512 | assert(network)do { if ((__builtin_expect(!!(!(network)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("network"), "../src/network/networkd-network.c" , 512, __PRETTY_FUNCTION__); } while (0); | |||
513 | assert(link)do { if ((__builtin_expect(!!(!(link)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("link"), "../src/network/networkd-network.c" , 513, __PRETTY_FUNCTION__); } while (0); | |||
514 | ||||
515 | link->network = network; | |||
516 | ||||
517 | if (network->ipv4ll_route) { | |||
518 | Route *route; | |||
519 | ||||
520 | r = route_new_static(network, NULL((void*)0), 0, &route); | |||
521 | if (r < 0) | |||
522 | return r; | |||
523 | ||||
524 | r = inet_pton(AF_INET2, "169.254.0.0", &route->dst.in); | |||
525 | if (r == 0) | |||
526 | return -EINVAL22; | |||
527 | if (r < 0) | |||
528 | return -errno(*__errno_location ()); | |||
529 | ||||
530 | route->family = AF_INET2; | |||
531 | route->dst_prefixlen = 16; | |||
532 | route->scope = RT_SCOPE_LINK; | |||
533 | route->priority = IPV4LL_ROUTE_METRIC2048; | |||
534 | route->protocol = RTPROT_STATIC4; | |||
535 | } | |||
536 | ||||
537 | if (network->n_dns > 0 || | |||
538 | !strv_isempty(network->ntp) || | |||
539 | !strv_isempty(network->search_domains) || | |||
540 | !strv_isempty(network->route_domains)) | |||
541 | link_dirty(link); | |||
542 | ||||
543 | return 0; | |||
544 | } | |||
545 | ||||
546 | bool_Bool network_has_static_ipv6_addresses(Network *network) { | |||
547 | Address *address; | |||
548 | ||||
549 | assert(network)do { if ((__builtin_expect(!!(!(network)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("network"), "../src/network/networkd-network.c" , 549, __PRETTY_FUNCTION__); } while (0); | |||
550 | ||||
551 | LIST_FOREACH(addresses, address, network->static_addresses)for ((address) = (network->static_addresses); (address); ( address) = (address)->addresses_next) { | |||
552 | if (address->family == AF_INET610) | |||
553 | return true1; | |||
554 | } | |||
555 | ||||
556 | return false0; | |||
557 | } | |||
558 | ||||
559 | int config_parse_netdev(const char *unit, | |||
560 | const char *filename, | |||
561 | unsigned line, | |||
562 | const char *section, | |||
563 | unsigned section_line, | |||
564 | const char *lvalue, | |||
565 | int ltype, | |||
566 | const char *rvalue, | |||
567 | void *data, | |||
568 | void *userdata) { | |||
569 | Network *network = userdata; | |||
570 | _cleanup_free___attribute__((cleanup(freep))) char *kind_string = NULL((void*)0); | |||
571 | char *p; | |||
572 | NetDev *netdev; | |||
573 | NetDevKind kind; | |||
574 | int r; | |||
575 | ||||
576 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/network/networkd-network.c" , 576, __PRETTY_FUNCTION__); } while (0); | |||
577 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/network/networkd-network.c" , 577, __PRETTY_FUNCTION__); } while (0); | |||
578 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/network/networkd-network.c" , 578, __PRETTY_FUNCTION__); } while (0); | |||
579 | assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/network/networkd-network.c" , 579, __PRETTY_FUNCTION__); } while (0); | |||
580 | ||||
581 | kind_string = strdup(lvalue); | |||
582 | if (!kind_string) | |||
583 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 583, __func__); | |||
584 | ||||
585 | /* the keys are CamelCase versions of the kind */ | |||
586 | for (p = kind_string; *p; p++) | |||
587 | *p = tolower(*p); | |||
588 | ||||
589 | kind = netdev_kind_from_string(kind_string); | |||
590 | if (kind == _NETDEV_KIND_INVALID) { | |||
591 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid NetDev kind: %s", lvalue)({ int _level = (3), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 591 , __func__, "Invalid NetDev kind: %s", lvalue) : -abs(_e); }); | |||
592 | return 0; | |||
593 | } | |||
594 | ||||
595 | r = netdev_get(network->manager, rvalue, &netdev); | |||
596 | if (r < 0) { | |||
597 | log_syntax(unit, LOG_ERR, filename, line, r, "%s could not be found, ignoring assignment: %s", lvalue, rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 597 , __func__, "%s could not be found, ignoring assignment: %s", lvalue, rvalue) : -abs(_e); }); | |||
598 | return 0; | |||
599 | } | |||
600 | ||||
601 | if (netdev->kind != kind) { | |||
602 | log_syntax(unit, LOG_ERR, filename, line, 0, "NetDev is not a %s, ignoring assignment: %s", lvalue, rvalue)({ int _level = (3), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 602 , __func__, "NetDev is not a %s, ignoring assignment: %s", lvalue , rvalue) : -abs(_e); }); | |||
603 | return 0; | |||
604 | } | |||
605 | ||||
606 | switch (kind) { | |||
607 | case NETDEV_KIND_BRIDGE: | |||
608 | network->bridge = netdev; | |||
609 | ||||
610 | break; | |||
611 | case NETDEV_KIND_BOND: | |||
612 | network->bond = netdev; | |||
613 | ||||
614 | break; | |||
615 | case NETDEV_KIND_VRF: | |||
616 | network->vrf = netdev; | |||
617 | ||||
618 | break; | |||
619 | case NETDEV_KIND_VLAN: | |||
620 | case NETDEV_KIND_MACVLAN: | |||
621 | case NETDEV_KIND_MACVTAP: | |||
622 | case NETDEV_KIND_IPVLAN: | |||
623 | case NETDEV_KIND_VXLAN: | |||
624 | case NETDEV_KIND_VCAN: | |||
625 | r = hashmap_put(network->stacked_netdevs, netdev->ifname, netdev); | |||
626 | if (r < 0) { | |||
627 | log_syntax(unit, LOG_ERR, filename, line, r, "Cannot add NetDev '%s' to network: %m", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 627 , __func__, "Cannot add NetDev '%s' to network: %m", rvalue) : -abs(_e); }); | |||
628 | return 0; | |||
629 | } | |||
630 | ||||
631 | break; | |||
632 | default: | |||
633 | assert_not_reached("Cannot parse NetDev")do { log_assert_failed_unreachable_realm(LOG_REALM_SYSTEMD, ( "Cannot parse NetDev"), "../src/network/networkd-network.c", 633 , __PRETTY_FUNCTION__); } while (0); | |||
634 | } | |||
635 | ||||
636 | netdev_ref(netdev); | |||
637 | ||||
638 | return 0; | |||
639 | } | |||
640 | ||||
641 | int config_parse_domains( | |||
642 | const char *unit, | |||
643 | const char *filename, | |||
644 | unsigned line, | |||
645 | const char *section, | |||
646 | unsigned section_line, | |||
647 | const char *lvalue, | |||
648 | int ltype, | |||
649 | const char *rvalue, | |||
650 | void *data, | |||
651 | void *userdata) { | |||
652 | ||||
653 | const char *p; | |||
654 | Network *n = data; | |||
655 | int r; | |||
656 | ||||
657 | assert(n)do { if ((__builtin_expect(!!(!(n)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("n"), "../src/network/networkd-network.c" , 657, __PRETTY_FUNCTION__); } while (0); | |||
658 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/network/networkd-network.c" , 658, __PRETTY_FUNCTION__); } while (0); | |||
659 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/network/networkd-network.c" , 659, __PRETTY_FUNCTION__); } while (0); | |||
660 | ||||
661 | if (isempty(rvalue)) { | |||
662 | n->search_domains = strv_free(n->search_domains); | |||
663 | n->route_domains = strv_free(n->route_domains); | |||
664 | return 0; | |||
665 | } | |||
666 | ||||
667 | p = rvalue; | |||
668 | for (;;) { | |||
669 | _cleanup_free___attribute__((cleanup(freep))) char *w = NULL((void*)0), *normalized = NULL((void*)0); | |||
670 | const char *domain; | |||
671 | bool_Bool is_route; | |||
672 | ||||
673 | r = extract_first_word(&p, &w, NULL((void*)0), 0); | |||
674 | if (r < 0) { | |||
675 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to extract search or route domain, ignoring: %s", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 675 , __func__, "Failed to extract search or route domain, ignoring: %s" , rvalue) : -abs(_e); }); | |||
676 | break; | |||
677 | } | |||
678 | if (r == 0) | |||
679 | break; | |||
680 | ||||
681 | is_route = w[0] == '~'; | |||
682 | domain = is_route ? w + 1 : w; | |||
683 | ||||
684 | if (dns_name_is_root(domain) || streq(domain, "*")(strcmp((domain),("*")) == 0)) { | |||
685 | /* If the root domain appears as is, or the special token "*" is found, we'll consider this as | |||
686 | * routing domain, unconditionally. */ | |||
687 | is_route = true1; | |||
688 | domain = "."; /* make sure we don't allow empty strings, thus write the root domain as "." */ | |||
689 | ||||
690 | } else { | |||
691 | r = dns_name_normalize(domain, &normalized); | |||
692 | if (r < 0) { | |||
693 | log_syntax(unit, LOG_ERR, filename, line, r, "'%s' is not a valid domain name, ignoring.", domain)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 693 , __func__, "'%s' is not a valid domain name, ignoring.", domain ) : -abs(_e); }); | |||
694 | continue; | |||
695 | } | |||
696 | ||||
697 | domain = normalized; | |||
698 | ||||
699 | if (is_localhost(domain)) { | |||
700 | log_syntax(unit, LOG_ERR, filename, line, 0, "'localhost' domain names may not be configure as search or route domains, ignoring assignment: %s", domain)({ int _level = (3), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 700 , __func__, "'localhost' domain names may not be configure as search or route domains, ignoring assignment: %s" , domain) : -abs(_e); }); | |||
701 | continue; | |||
702 | } | |||
703 | } | |||
704 | ||||
705 | if (is_route) { | |||
706 | r = strv_extend(&n->route_domains, domain); | |||
707 | if (r < 0) | |||
708 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 708, __func__); | |||
709 | ||||
710 | } else { | |||
711 | r = strv_extend(&n->search_domains, domain); | |||
712 | if (r < 0) | |||
713 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 713, __func__); | |||
714 | } | |||
715 | } | |||
716 | ||||
717 | strv_uniq(n->route_domains); | |||
718 | strv_uniq(n->search_domains); | |||
719 | ||||
720 | return 0; | |||
721 | } | |||
722 | ||||
723 | int config_parse_tunnel(const char *unit, | |||
724 | const char *filename, | |||
725 | unsigned line, | |||
726 | const char *section, | |||
727 | unsigned section_line, | |||
728 | const char *lvalue, | |||
729 | int ltype, | |||
730 | const char *rvalue, | |||
731 | void *data, | |||
732 | void *userdata) { | |||
733 | Network *network = userdata; | |||
734 | NetDev *netdev; | |||
735 | int r; | |||
736 | ||||
737 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/network/networkd-network.c" , 737, __PRETTY_FUNCTION__); } while (0); | |||
738 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/network/networkd-network.c" , 738, __PRETTY_FUNCTION__); } while (0); | |||
739 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/network/networkd-network.c" , 739, __PRETTY_FUNCTION__); } while (0); | |||
740 | assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/network/networkd-network.c" , 740, __PRETTY_FUNCTION__); } while (0); | |||
741 | ||||
742 | r = netdev_get(network->manager, rvalue, &netdev); | |||
743 | if (r < 0) { | |||
744 | log_syntax(unit, LOG_ERR, filename, line, r, "Tunnel is invalid, ignoring assignment: %s", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 744 , __func__, "Tunnel is invalid, ignoring assignment: %s", rvalue ) : -abs(_e); }); | |||
745 | return 0; | |||
746 | } | |||
747 | ||||
748 | if (!IN_SET(netdev->kind,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended [20 - sizeof((int[]){NETDEV_KIND_IPIP, NETDEV_KIND_SIT, NETDEV_KIND_GRE , NETDEV_KIND_GRETAP, NETDEV_KIND_IP6GRE, NETDEV_KIND_IP6GRETAP , NETDEV_KIND_VTI, NETDEV_KIND_VTI6, NETDEV_KIND_IP6TNL})/sizeof (int)]; switch(netdev->kind) { case NETDEV_KIND_IPIP: case NETDEV_KIND_SIT: case NETDEV_KIND_GRE: case NETDEV_KIND_GRETAP : case NETDEV_KIND_IP6GRE: case NETDEV_KIND_IP6GRETAP: case NETDEV_KIND_VTI : case NETDEV_KIND_VTI6: case NETDEV_KIND_IP6TNL: _found = 1; break; default: break; } _found; }) | |||
749 | NETDEV_KIND_IPIP,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended [20 - sizeof((int[]){NETDEV_KIND_IPIP, NETDEV_KIND_SIT, NETDEV_KIND_GRE , NETDEV_KIND_GRETAP, NETDEV_KIND_IP6GRE, NETDEV_KIND_IP6GRETAP , NETDEV_KIND_VTI, NETDEV_KIND_VTI6, NETDEV_KIND_IP6TNL})/sizeof (int)]; switch(netdev->kind) { case NETDEV_KIND_IPIP: case NETDEV_KIND_SIT: case NETDEV_KIND_GRE: case NETDEV_KIND_GRETAP : case NETDEV_KIND_IP6GRE: case NETDEV_KIND_IP6GRETAP: case NETDEV_KIND_VTI : case NETDEV_KIND_VTI6: case NETDEV_KIND_IP6TNL: _found = 1; break; default: break; } _found; }) | |||
750 | NETDEV_KIND_SIT,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended [20 - sizeof((int[]){NETDEV_KIND_IPIP, NETDEV_KIND_SIT, NETDEV_KIND_GRE , NETDEV_KIND_GRETAP, NETDEV_KIND_IP6GRE, NETDEV_KIND_IP6GRETAP , NETDEV_KIND_VTI, NETDEV_KIND_VTI6, NETDEV_KIND_IP6TNL})/sizeof (int)]; switch(netdev->kind) { case NETDEV_KIND_IPIP: case NETDEV_KIND_SIT: case NETDEV_KIND_GRE: case NETDEV_KIND_GRETAP : case NETDEV_KIND_IP6GRE: case NETDEV_KIND_IP6GRETAP: case NETDEV_KIND_VTI : case NETDEV_KIND_VTI6: case NETDEV_KIND_IP6TNL: _found = 1; break; default: break; } _found; }) | |||
751 | NETDEV_KIND_GRE,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended [20 - sizeof((int[]){NETDEV_KIND_IPIP, NETDEV_KIND_SIT, NETDEV_KIND_GRE , NETDEV_KIND_GRETAP, NETDEV_KIND_IP6GRE, NETDEV_KIND_IP6GRETAP , NETDEV_KIND_VTI, NETDEV_KIND_VTI6, NETDEV_KIND_IP6TNL})/sizeof (int)]; switch(netdev->kind) { case NETDEV_KIND_IPIP: case NETDEV_KIND_SIT: case NETDEV_KIND_GRE: case NETDEV_KIND_GRETAP : case NETDEV_KIND_IP6GRE: case NETDEV_KIND_IP6GRETAP: case NETDEV_KIND_VTI : case NETDEV_KIND_VTI6: case NETDEV_KIND_IP6TNL: _found = 1; break; default: break; } _found; }) | |||
752 | NETDEV_KIND_GRETAP,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended [20 - sizeof((int[]){NETDEV_KIND_IPIP, NETDEV_KIND_SIT, NETDEV_KIND_GRE , NETDEV_KIND_GRETAP, NETDEV_KIND_IP6GRE, NETDEV_KIND_IP6GRETAP , NETDEV_KIND_VTI, NETDEV_KIND_VTI6, NETDEV_KIND_IP6TNL})/sizeof (int)]; switch(netdev->kind) { case NETDEV_KIND_IPIP: case NETDEV_KIND_SIT: case NETDEV_KIND_GRE: case NETDEV_KIND_GRETAP : case NETDEV_KIND_IP6GRE: case NETDEV_KIND_IP6GRETAP: case NETDEV_KIND_VTI : case NETDEV_KIND_VTI6: case NETDEV_KIND_IP6TNL: _found = 1; break; default: break; } _found; }) | |||
753 | NETDEV_KIND_IP6GRE,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended [20 - sizeof((int[]){NETDEV_KIND_IPIP, NETDEV_KIND_SIT, NETDEV_KIND_GRE , NETDEV_KIND_GRETAP, NETDEV_KIND_IP6GRE, NETDEV_KIND_IP6GRETAP , NETDEV_KIND_VTI, NETDEV_KIND_VTI6, NETDEV_KIND_IP6TNL})/sizeof (int)]; switch(netdev->kind) { case NETDEV_KIND_IPIP: case NETDEV_KIND_SIT: case NETDEV_KIND_GRE: case NETDEV_KIND_GRETAP : case NETDEV_KIND_IP6GRE: case NETDEV_KIND_IP6GRETAP: case NETDEV_KIND_VTI : case NETDEV_KIND_VTI6: case NETDEV_KIND_IP6TNL: _found = 1; break; default: break; } _found; }) | |||
754 | NETDEV_KIND_IP6GRETAP,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended [20 - sizeof((int[]){NETDEV_KIND_IPIP, NETDEV_KIND_SIT, NETDEV_KIND_GRE , NETDEV_KIND_GRETAP, NETDEV_KIND_IP6GRE, NETDEV_KIND_IP6GRETAP , NETDEV_KIND_VTI, NETDEV_KIND_VTI6, NETDEV_KIND_IP6TNL})/sizeof (int)]; switch(netdev->kind) { case NETDEV_KIND_IPIP: case NETDEV_KIND_SIT: case NETDEV_KIND_GRE: case NETDEV_KIND_GRETAP : case NETDEV_KIND_IP6GRE: case NETDEV_KIND_IP6GRETAP: case NETDEV_KIND_VTI : case NETDEV_KIND_VTI6: case NETDEV_KIND_IP6TNL: _found = 1; break; default: break; } _found; }) | |||
755 | NETDEV_KIND_VTI,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended [20 - sizeof((int[]){NETDEV_KIND_IPIP, NETDEV_KIND_SIT, NETDEV_KIND_GRE , NETDEV_KIND_GRETAP, NETDEV_KIND_IP6GRE, NETDEV_KIND_IP6GRETAP , NETDEV_KIND_VTI, NETDEV_KIND_VTI6, NETDEV_KIND_IP6TNL})/sizeof (int)]; switch(netdev->kind) { case NETDEV_KIND_IPIP: case NETDEV_KIND_SIT: case NETDEV_KIND_GRE: case NETDEV_KIND_GRETAP : case NETDEV_KIND_IP6GRE: case NETDEV_KIND_IP6GRETAP: case NETDEV_KIND_VTI : case NETDEV_KIND_VTI6: case NETDEV_KIND_IP6TNL: _found = 1; break; default: break; } _found; }) | |||
756 | NETDEV_KIND_VTI6,({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended [20 - sizeof((int[]){NETDEV_KIND_IPIP, NETDEV_KIND_SIT, NETDEV_KIND_GRE , NETDEV_KIND_GRETAP, NETDEV_KIND_IP6GRE, NETDEV_KIND_IP6GRETAP , NETDEV_KIND_VTI, NETDEV_KIND_VTI6, NETDEV_KIND_IP6TNL})/sizeof (int)]; switch(netdev->kind) { case NETDEV_KIND_IPIP: case NETDEV_KIND_SIT: case NETDEV_KIND_GRE: case NETDEV_KIND_GRETAP : case NETDEV_KIND_IP6GRE: case NETDEV_KIND_IP6GRETAP: case NETDEV_KIND_VTI : case NETDEV_KIND_VTI6: case NETDEV_KIND_IP6TNL: _found = 1; break; default: break; } _found; }) | |||
757 | NETDEV_KIND_IP6TNL)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended [20 - sizeof((int[]){NETDEV_KIND_IPIP, NETDEV_KIND_SIT, NETDEV_KIND_GRE , NETDEV_KIND_GRETAP, NETDEV_KIND_IP6GRE, NETDEV_KIND_IP6GRETAP , NETDEV_KIND_VTI, NETDEV_KIND_VTI6, NETDEV_KIND_IP6TNL})/sizeof (int)]; switch(netdev->kind) { case NETDEV_KIND_IPIP: case NETDEV_KIND_SIT: case NETDEV_KIND_GRE: case NETDEV_KIND_GRETAP : case NETDEV_KIND_IP6GRE: case NETDEV_KIND_IP6GRETAP: case NETDEV_KIND_VTI : case NETDEV_KIND_VTI6: case NETDEV_KIND_IP6TNL: _found = 1; break; default: break; } _found; })) { | |||
758 | log_syntax(unit, LOG_ERR, filename, line, 0,({ int _level = (3), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 759 , __func__, "NetDev is not a tunnel, ignoring assignment: %s" , rvalue) : -abs(_e); }) | |||
759 | "NetDev is not a tunnel, ignoring assignment: %s", rvalue)({ int _level = (3), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 759 , __func__, "NetDev is not a tunnel, ignoring assignment: %s" , rvalue) : -abs(_e); }); | |||
760 | return 0; | |||
761 | } | |||
762 | ||||
763 | r = hashmap_put(network->stacked_netdevs, netdev->ifname, netdev); | |||
764 | if (r < 0) { | |||
765 | log_syntax(unit, LOG_ERR, filename, line, r, "Cannot add VLAN '%s' to network, ignoring: %m", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 765 , __func__, "Cannot add VLAN '%s' to network, ignoring: %m", rvalue ) : -abs(_e); }); | |||
766 | return 0; | |||
767 | } | |||
768 | ||||
769 | netdev_ref(netdev); | |||
770 | ||||
771 | return 0; | |||
772 | } | |||
773 | ||||
774 | int config_parse_ipv4ll( | |||
775 | const char* unit, | |||
776 | const char *filename, | |||
777 | unsigned line, | |||
778 | const char *section, | |||
779 | unsigned section_line, | |||
780 | const char *lvalue, | |||
781 | int ltype, | |||
782 | const char *rvalue, | |||
783 | void *data, | |||
784 | void *userdata) { | |||
785 | ||||
786 | AddressFamilyBoolean *link_local = data; | |||
787 | ||||
788 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/network/networkd-network.c" , 788, __PRETTY_FUNCTION__); } while (0); | |||
789 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/network/networkd-network.c" , 789, __PRETTY_FUNCTION__); } while (0); | |||
790 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/network/networkd-network.c" , 790, __PRETTY_FUNCTION__); } while (0); | |||
791 | assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/network/networkd-network.c" , 791, __PRETTY_FUNCTION__); } while (0); | |||
792 | ||||
793 | /* Note that this is mostly like | |||
794 | * config_parse_address_family_boolean(), except that it | |||
795 | * applies only to IPv4 */ | |||
796 | ||||
797 | SET_FLAG(*link_local, ADDRESS_FAMILY_IPV4, parse_boolean(rvalue))(*link_local) = (parse_boolean(rvalue)) ? ((*link_local) | (ADDRESS_FAMILY_IPV4 )) : ((*link_local) & ~(ADDRESS_FAMILY_IPV4)); | |||
798 | ||||
799 | return 0; | |||
800 | } | |||
801 | ||||
802 | int config_parse_dhcp( | |||
803 | const char* unit, | |||
804 | const char *filename, | |||
805 | unsigned line, | |||
806 | const char *section, | |||
807 | unsigned section_line, | |||
808 | const char *lvalue, | |||
809 | int ltype, | |||
810 | const char *rvalue, | |||
811 | void *data, | |||
812 | void *userdata) { | |||
813 | ||||
814 | AddressFamilyBoolean *dhcp = data, s; | |||
815 | ||||
816 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/network/networkd-network.c" , 816, __PRETTY_FUNCTION__); } while (0); | |||
817 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/network/networkd-network.c" , 817, __PRETTY_FUNCTION__); } while (0); | |||
818 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/network/networkd-network.c" , 818, __PRETTY_FUNCTION__); } while (0); | |||
819 | assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/network/networkd-network.c" , 819, __PRETTY_FUNCTION__); } while (0); | |||
820 | ||||
821 | /* Note that this is mostly like | |||
822 | * config_parse_address_family_boolean(), except that it | |||
823 | * understands some old names for the enum values */ | |||
824 | ||||
825 | s = address_family_boolean_from_string(rvalue); | |||
826 | if (s < 0) { | |||
827 | ||||
828 | /* Previously, we had a slightly different enum here, | |||
829 | * support its values for compatbility. */ | |||
830 | ||||
831 | if (streq(rvalue, "none")(strcmp((rvalue),("none")) == 0)) | |||
832 | s = ADDRESS_FAMILY_NO; | |||
833 | else if (streq(rvalue, "v4")(strcmp((rvalue),("v4")) == 0)) | |||
834 | s = ADDRESS_FAMILY_IPV4; | |||
835 | else if (streq(rvalue, "v6")(strcmp((rvalue),("v6")) == 0)) | |||
836 | s = ADDRESS_FAMILY_IPV6; | |||
837 | else if (streq(rvalue, "both")(strcmp((rvalue),("both")) == 0)) | |||
838 | s = ADDRESS_FAMILY_YES; | |||
839 | else { | |||
840 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse DHCP option, ignoring: %s", rvalue)({ int _level = (3), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 840 , __func__, "Failed to parse DHCP option, ignoring: %s", rvalue ) : -abs(_e); }); | |||
841 | return 0; | |||
842 | } | |||
843 | } | |||
844 | ||||
845 | *dhcp = s; | |||
846 | return 0; | |||
847 | } | |||
848 | ||||
849 | static const char* const dhcp_client_identifier_table[_DHCP_CLIENT_ID_MAX] = { | |||
850 | [DHCP_CLIENT_ID_MAC] = "mac", | |||
851 | [DHCP_CLIENT_ID_DUID] = "duid", | |||
852 | [DHCP_CLIENT_ID_DUID_ONLY] = "duid-only", | |||
853 | }; | |||
854 | ||||
855 | DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(dhcp_client_identifier, DHCPClientIdentifier)static DHCPClientIdentifier dhcp_client_identifier_from_string (const char *s) { return (DHCPClientIdentifier) string_table_lookup (dhcp_client_identifier_table, __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(dhcp_client_identifier_table ), typeof(&*(dhcp_client_identifier_table))), sizeof(dhcp_client_identifier_table )/sizeof((dhcp_client_identifier_table)[0]), ((void)0))), s); }; | |||
856 | DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp_client_identifier, dhcp_client_identifier, DHCPClientIdentifier, "Failed to parse client identifier type")int config_parse_dhcp_client_identifier(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue , void *data, void *userdata) { DHCPClientIdentifier *i = data , x; do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/network/networkd-network.c" , 856, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect (!!(!(lvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("lvalue"), "../src/network/networkd-network.c", 856, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("rvalue"), "../src/network/networkd-network.c" , 856, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect (!!(!(data)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ( "data"), "../src/network/networkd-network.c", 856, __PRETTY_FUNCTION__ ); } while (0); x = dhcp_client_identifier_from_string(rvalue ); if (x < 0) { ({ int _level = (3), _e = (0); (log_get_max_level_realm (LOG_REALM_SYSTEMD) >= ((_level) & 0x07)) ? log_syntax_internal (unit, _level, filename, line, _e, "../src/network/networkd-network.c" , 856, __func__, "Failed to parse client identifier type" ", ignoring: %s" , rvalue) : -abs(_e); }); return 0; } *i = x; return 0; }; | |||
857 | ||||
858 | int config_parse_ipv6token( | |||
859 | const char* unit, | |||
860 | const char *filename, | |||
861 | unsigned line, | |||
862 | const char *section, | |||
863 | unsigned section_line, | |||
864 | const char *lvalue, | |||
865 | int ltype, | |||
866 | const char *rvalue, | |||
867 | void *data, | |||
868 | void *userdata) { | |||
869 | ||||
870 | union in_addr_union buffer; | |||
871 | struct in6_addr *token = data; | |||
872 | int r; | |||
873 | ||||
874 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/network/networkd-network.c" , 874, __PRETTY_FUNCTION__); } while (0); | |||
875 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/network/networkd-network.c" , 875, __PRETTY_FUNCTION__); } while (0); | |||
876 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/network/networkd-network.c" , 876, __PRETTY_FUNCTION__); } while (0); | |||
877 | assert(token)do { if ((__builtin_expect(!!(!(token)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("token"), "../src/network/networkd-network.c" , 877, __PRETTY_FUNCTION__); } while (0); | |||
878 | ||||
879 | r = in_addr_from_string(AF_INET610, rvalue, &buffer); | |||
880 | if (r < 0) { | |||
881 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse IPv6 token, ignoring: %s", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 881 , __func__, "Failed to parse IPv6 token, ignoring: %s", rvalue ) : -abs(_e); }); | |||
882 | return 0; | |||
883 | } | |||
884 | ||||
885 | r = in_addr_is_null(AF_INET610, &buffer); | |||
886 | if (r != 0) { | |||
887 | log_syntax(unit, LOG_ERR, filename, line, r, "IPv6 token cannot be the ANY address, ignoring: %s", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 887 , __func__, "IPv6 token cannot be the ANY address, ignoring: %s" , rvalue) : -abs(_e); }); | |||
888 | return 0; | |||
889 | } | |||
890 | ||||
891 | if ((buffer.in6.s6_addr32__in6_u.__u6_addr32[0] | buffer.in6.s6_addr32__in6_u.__u6_addr32[1]) != 0) { | |||
892 | log_syntax(unit, LOG_ERR, filename, line, 0, "IPv6 token cannot be longer than 64 bits, ignoring: %s", rvalue)({ int _level = (3), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 892 , __func__, "IPv6 token cannot be longer than 64 bits, ignoring: %s" , rvalue) : -abs(_e); }); | |||
893 | return 0; | |||
894 | } | |||
895 | ||||
896 | *token = buffer.in6; | |||
897 | ||||
898 | return 0; | |||
899 | } | |||
900 | ||||
901 | static const char* const ipv6_privacy_extensions_table[_IPV6_PRIVACY_EXTENSIONS_MAX] = { | |||
902 | [IPV6_PRIVACY_EXTENSIONS_NO] = "no", | |||
903 | [IPV6_PRIVACY_EXTENSIONS_PREFER_PUBLIC] = "prefer-public", | |||
904 | [IPV6_PRIVACY_EXTENSIONS_YES] = "yes", | |||
905 | }; | |||
906 | ||||
907 | DEFINE_STRING_TABLE_LOOKUP(ipv6_privacy_extensions, IPv6PrivacyExtensions)const char *ipv6_privacy_extensions_to_string(IPv6PrivacyExtensions i) { if (i < 0 || i >= (IPv6PrivacyExtensions) __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p(typeof (ipv6_privacy_extensions_table), typeof(&*(ipv6_privacy_extensions_table ))), sizeof(ipv6_privacy_extensions_table)/sizeof((ipv6_privacy_extensions_table )[0]), ((void)0)))) return ((void*)0); return ipv6_privacy_extensions_table [i]; } IPv6PrivacyExtensions ipv6_privacy_extensions_from_string (const char *s) { return (IPv6PrivacyExtensions) string_table_lookup (ipv6_privacy_extensions_table, __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(ipv6_privacy_extensions_table ), typeof(&*(ipv6_privacy_extensions_table))), sizeof(ipv6_privacy_extensions_table )/sizeof((ipv6_privacy_extensions_table)[0]), ((void)0))), s) ; }; | |||
908 | ||||
909 | int config_parse_ipv6_privacy_extensions( | |||
910 | const char* unit, | |||
911 | const char *filename, | |||
912 | unsigned line, | |||
913 | const char *section, | |||
914 | unsigned section_line, | |||
915 | const char *lvalue, | |||
916 | int ltype, | |||
917 | const char *rvalue, | |||
918 | void *data, | |||
919 | void *userdata) { | |||
920 | ||||
921 | IPv6PrivacyExtensions *ipv6_privacy_extensions = data; | |||
922 | int k; | |||
923 | ||||
924 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/network/networkd-network.c" , 924, __PRETTY_FUNCTION__); } while (0); | |||
925 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/network/networkd-network.c" , 925, __PRETTY_FUNCTION__); } while (0); | |||
926 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/network/networkd-network.c" , 926, __PRETTY_FUNCTION__); } while (0); | |||
927 | assert(ipv6_privacy_extensions)do { if ((__builtin_expect(!!(!(ipv6_privacy_extensions)),0)) ) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("ipv6_privacy_extensions" ), "../src/network/networkd-network.c", 927, __PRETTY_FUNCTION__ ); } while (0); | |||
928 | ||||
929 | /* Our enum shall be a superset of booleans, hence first try | |||
930 | * to parse as boolean, and then as enum */ | |||
931 | ||||
932 | k = parse_boolean(rvalue); | |||
933 | if (k > 0) | |||
934 | *ipv6_privacy_extensions = IPV6_PRIVACY_EXTENSIONS_YES; | |||
935 | else if (k == 0) | |||
936 | *ipv6_privacy_extensions = IPV6_PRIVACY_EXTENSIONS_NO; | |||
937 | else { | |||
938 | IPv6PrivacyExtensions s; | |||
939 | ||||
940 | s = ipv6_privacy_extensions_from_string(rvalue); | |||
941 | if (s < 0) { | |||
942 | ||||
943 | if (streq(rvalue, "kernel")(strcmp((rvalue),("kernel")) == 0)) | |||
944 | s = _IPV6_PRIVACY_EXTENSIONS_INVALID; | |||
945 | else { | |||
946 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse IPv6 privacy extensions option, ignoring: %s", rvalue)({ int _level = (3), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 946 , __func__, "Failed to parse IPv6 privacy extensions option, ignoring: %s" , rvalue) : -abs(_e); }); | |||
947 | return 0; | |||
948 | } | |||
949 | } | |||
950 | ||||
951 | *ipv6_privacy_extensions = s; | |||
952 | } | |||
953 | ||||
954 | return 0; | |||
955 | } | |||
956 | ||||
957 | int config_parse_hostname( | |||
958 | const char *unit, | |||
959 | const char *filename, | |||
960 | unsigned line, | |||
961 | const char *section, | |||
962 | unsigned section_line, | |||
963 | const char *lvalue, | |||
964 | int ltype, | |||
965 | const char *rvalue, | |||
966 | void *data, | |||
967 | void *userdata) { | |||
968 | ||||
969 | char **hostname = data, *hn = NULL((void*)0); | |||
970 | int r; | |||
971 | ||||
972 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/network/networkd-network.c" , 972, __PRETTY_FUNCTION__); } while (0); | |||
973 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/network/networkd-network.c" , 973, __PRETTY_FUNCTION__); } while (0); | |||
974 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/network/networkd-network.c" , 974, __PRETTY_FUNCTION__); } while (0); | |||
975 | ||||
976 | r = config_parse_string(unit, filename, line, section, section_line, lvalue, ltype, rvalue, &hn, userdata); | |||
977 | if (r < 0) | |||
978 | return r; | |||
979 | ||||
980 | if (!hostname_is_valid(hn, false0)) { | |||
981 | log_syntax(unit, LOG_ERR, filename, line, 0, "Hostname is not valid, ignoring assignment: %s", rvalue)({ int _level = (3), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 981 , __func__, "Hostname is not valid, ignoring assignment: %s", rvalue) : -abs(_e); }); | |||
982 | free(hn); | |||
983 | return 0; | |||
984 | } | |||
985 | ||||
986 | free(*hostname); | |||
987 | *hostname = hostname_cleanup(hn); | |||
988 | return 0; | |||
989 | } | |||
990 | ||||
991 | int config_parse_timezone( | |||
992 | const char *unit, | |||
993 | const char *filename, | |||
994 | unsigned line, | |||
995 | const char *section, | |||
996 | unsigned section_line, | |||
997 | const char *lvalue, | |||
998 | int ltype, | |||
999 | const char *rvalue, | |||
1000 | void *data, | |||
1001 | void *userdata) { | |||
1002 | ||||
1003 | char **datap = data, *tz = NULL((void*)0); | |||
1004 | int r; | |||
1005 | ||||
1006 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/network/networkd-network.c" , 1006, __PRETTY_FUNCTION__); } while (0); | |||
1007 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/network/networkd-network.c" , 1007, __PRETTY_FUNCTION__); } while (0); | |||
1008 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/network/networkd-network.c" , 1008, __PRETTY_FUNCTION__); } while (0); | |||
1009 | ||||
1010 | r = config_parse_string(unit, filename, line, section, section_line, lvalue, ltype, rvalue, &tz, userdata); | |||
1011 | if (r < 0) | |||
1012 | return r; | |||
1013 | ||||
1014 | if (!timezone_is_valid(tz, LOG_ERR3)) { | |||
1015 | log_syntax(unit, LOG_ERR, filename, line, 0, "Timezone is not valid, ignoring assignment: %s", rvalue)({ int _level = (3), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 1015 , __func__, "Timezone is not valid, ignoring assignment: %s", rvalue) : -abs(_e); }); | |||
1016 | free(tz); | |||
1017 | return 0; | |||
1018 | } | |||
1019 | ||||
1020 | free(*datap); | |||
1021 | *datap = tz; | |||
1022 | ||||
1023 | return 0; | |||
1024 | } | |||
1025 | ||||
1026 | int config_parse_dhcp_server_dns( | |||
1027 | const char *unit, | |||
1028 | const char *filename, | |||
1029 | unsigned line, | |||
1030 | const char *section, | |||
1031 | unsigned section_line, | |||
1032 | const char *lvalue, | |||
1033 | int ltype, | |||
1034 | const char *rvalue, | |||
1035 | void *data, | |||
1036 | void *userdata) { | |||
1037 | ||||
1038 | Network *n = data; | |||
1039 | const char *p = rvalue; | |||
1040 | int r; | |||
1041 | ||||
1042 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/network/networkd-network.c" , 1042, __PRETTY_FUNCTION__); } while (0); | |||
1043 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/network/networkd-network.c" , 1043, __PRETTY_FUNCTION__); } while (0); | |||
1044 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/network/networkd-network.c" , 1044, __PRETTY_FUNCTION__); } while (0); | |||
1045 | ||||
1046 | for (;;) { | |||
1047 | _cleanup_free___attribute__((cleanup(freep))) char *w = NULL((void*)0); | |||
1048 | struct in_addr a, *m; | |||
1049 | ||||
1050 | r = extract_first_word(&p, &w, NULL((void*)0), 0); | |||
1051 | if (r == -ENOMEM12) | |||
1052 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 1052, __func__); | |||
1053 | if (r < 0) { | |||
1054 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to extract word, ignoring: %s", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 1054 , __func__, "Failed to extract word, ignoring: %s", rvalue) : -abs(_e); }); | |||
1055 | return 0; | |||
1056 | } | |||
1057 | if (r == 0) | |||
1058 | break; | |||
1059 | ||||
1060 | if (inet_pton(AF_INET2, w, &a) <= 0) { | |||
1061 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse DNS server address, ignoring: %s", w)({ int _level = (3), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 1061 , __func__, "Failed to parse DNS server address, ignoring: %s" , w) : -abs(_e); }); | |||
1062 | continue; | |||
1063 | } | |||
1064 | ||||
1065 | m = reallocarray(n->dhcp_server_dns, n->n_dhcp_server_dns + 1, sizeof(struct in_addr)); | |||
1066 | if (!m) | |||
1067 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 1067, __func__); | |||
1068 | ||||
1069 | m[n->n_dhcp_server_dns++] = a; | |||
1070 | n->dhcp_server_dns = m; | |||
1071 | } | |||
1072 | ||||
1073 | return 0; | |||
1074 | } | |||
1075 | ||||
1076 | int config_parse_radv_dns( | |||
1077 | const char *unit, | |||
1078 | const char *filename, | |||
1079 | unsigned line, | |||
1080 | const char *section, | |||
1081 | unsigned section_line, | |||
1082 | const char *lvalue, | |||
1083 | int ltype, | |||
1084 | const char *rvalue, | |||
1085 | void *data, | |||
1086 | void *userdata) { | |||
1087 | ||||
1088 | Network *n = data; | |||
1089 | const char *p = rvalue; | |||
1090 | int r; | |||
1091 | ||||
1092 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/network/networkd-network.c" , 1092, __PRETTY_FUNCTION__); } while (0); | |||
1093 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/network/networkd-network.c" , 1093, __PRETTY_FUNCTION__); } while (0); | |||
1094 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/network/networkd-network.c" , 1094, __PRETTY_FUNCTION__); } while (0); | |||
1095 | ||||
1096 | for (;;) { | |||
1097 | _cleanup_free___attribute__((cleanup(freep))) char *w = NULL((void*)0); | |||
1098 | union in_addr_union a; | |||
1099 | ||||
1100 | r = extract_first_word(&p, &w, NULL((void*)0), 0); | |||
1101 | if (r == -ENOMEM12) | |||
1102 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 1102, __func__); | |||
1103 | if (r < 0) { | |||
1104 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to extract word, ignoring: %s", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 1104 , __func__, "Failed to extract word, ignoring: %s", rvalue) : -abs(_e); }); | |||
1105 | return 0; | |||
1106 | } | |||
1107 | if (r == 0) | |||
1108 | break; | |||
1109 | ||||
1110 | if (in_addr_from_string(AF_INET610, w, &a) >= 0) { | |||
1111 | struct in6_addr *m; | |||
1112 | ||||
1113 | m = reallocarray(n->router_dns, n->n_router_dns + 1, sizeof(struct in6_addr)); | |||
1114 | if (!m) | |||
1115 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 1115, __func__); | |||
1116 | ||||
1117 | m[n->n_router_dns++] = a.in6; | |||
1118 | n->router_dns = m; | |||
1119 | ||||
1120 | } else | |||
1121 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse DNS server address, ignoring: %s", w)({ int _level = (3), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 1121 , __func__, "Failed to parse DNS server address, ignoring: %s" , w) : -abs(_e); }); | |||
1122 | ||||
1123 | } | |||
1124 | ||||
1125 | return 0; | |||
1126 | } | |||
1127 | ||||
1128 | int config_parse_radv_search_domains( | |||
1129 | const char *unit, | |||
1130 | const char *filename, | |||
1131 | unsigned line, | |||
1132 | const char *section, | |||
1133 | unsigned section_line, | |||
1134 | const char *lvalue, | |||
1135 | int ltype, | |||
1136 | const char *rvalue, | |||
1137 | void *data, | |||
1138 | void *userdata) { | |||
1139 | ||||
1140 | Network *n = data; | |||
1141 | const char *p = rvalue; | |||
1142 | int r; | |||
1143 | ||||
1144 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/network/networkd-network.c" , 1144, __PRETTY_FUNCTION__); } while (0); | |||
1145 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/network/networkd-network.c" , 1145, __PRETTY_FUNCTION__); } while (0); | |||
1146 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/network/networkd-network.c" , 1146, __PRETTY_FUNCTION__); } while (0); | |||
1147 | ||||
1148 | for (;;) { | |||
1149 | _cleanup_free___attribute__((cleanup(freep))) char *w = NULL((void*)0); | |||
1150 | _cleanup_free___attribute__((cleanup(freep))) char *idna = NULL((void*)0); | |||
1151 | ||||
1152 | r = extract_first_word(&p, &w, NULL((void*)0), 0); | |||
1153 | if (r == -ENOMEM12) | |||
1154 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 1154, __func__); | |||
1155 | if (r < 0) { | |||
1156 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to extract word, ignoring: %s", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 1156 , __func__, "Failed to extract word, ignoring: %s", rvalue) : -abs(_e); }); | |||
1157 | return 0; | |||
1158 | } | |||
1159 | if (r == 0) | |||
1160 | break; | |||
1161 | ||||
1162 | r = dns_name_apply_idna(w, &idna); | |||
1163 | if (r > 0) { | |||
1164 | r = strv_push(&n->router_search_domains, idna); | |||
1165 | if (r >= 0) | |||
1166 | idna = NULL((void*)0); | |||
1167 | } else if (r == 0) { | |||
1168 | r = strv_push(&n->router_search_domains, w); | |||
1169 | if (r >= 0) | |||
1170 | w = NULL((void*)0); | |||
1171 | } | |||
1172 | } | |||
1173 | ||||
1174 | return 0; | |||
1175 | } | |||
1176 | ||||
1177 | int config_parse_dhcp_server_ntp( | |||
1178 | const char *unit, | |||
1179 | const char *filename, | |||
1180 | unsigned line, | |||
1181 | const char *section, | |||
1182 | unsigned section_line, | |||
1183 | const char *lvalue, | |||
1184 | int ltype, | |||
1185 | const char *rvalue, | |||
1186 | void *data, | |||
1187 | void *userdata) { | |||
1188 | ||||
1189 | Network *n = data; | |||
1190 | const char *p = rvalue; | |||
1191 | int r; | |||
1192 | ||||
1193 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/network/networkd-network.c" , 1193, __PRETTY_FUNCTION__); } while (0); | |||
1194 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/network/networkd-network.c" , 1194, __PRETTY_FUNCTION__); } while (0); | |||
1195 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/network/networkd-network.c" , 1195, __PRETTY_FUNCTION__); } while (0); | |||
1196 | ||||
1197 | for (;;) { | |||
1198 | _cleanup_free___attribute__((cleanup(freep))) char *w = NULL((void*)0); | |||
1199 | struct in_addr a, *m; | |||
1200 | ||||
1201 | r = extract_first_word(&p, &w, NULL((void*)0), 0); | |||
1202 | if (r == -ENOMEM12) | |||
1203 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 1203, __func__); | |||
1204 | if (r < 0) { | |||
1205 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to extract word, ignoring: %s", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 1205 , __func__, "Failed to extract word, ignoring: %s", rvalue) : -abs(_e); }); | |||
1206 | return 0; | |||
1207 | } | |||
1208 | if (r == 0) | |||
1209 | return 0; | |||
1210 | ||||
1211 | if (inet_pton(AF_INET2, w, &a) <= 0) { | |||
1212 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse NTP server address, ignoring: %s", w)({ int _level = (3), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 1212 , __func__, "Failed to parse NTP server address, ignoring: %s" , w) : -abs(_e); }); | |||
1213 | continue; | |||
1214 | } | |||
1215 | ||||
1216 | m = reallocarray(n->dhcp_server_ntp, n->n_dhcp_server_ntp + 1, sizeof(struct in_addr)); | |||
1217 | if (!m) | |||
1218 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 1218, __func__); | |||
1219 | ||||
1220 | m[n->n_dhcp_server_ntp++] = a; | |||
1221 | n->dhcp_server_ntp = m; | |||
1222 | } | |||
1223 | } | |||
1224 | ||||
1225 | int config_parse_dns( | |||
1226 | const char *unit, | |||
1227 | const char *filename, | |||
1228 | unsigned line, | |||
1229 | const char *section, | |||
1230 | unsigned section_line, | |||
1231 | const char *lvalue, | |||
1232 | int ltype, | |||
1233 | const char *rvalue, | |||
1234 | void *data, | |||
1235 | void *userdata) { | |||
1236 | ||||
1237 | Network *n = userdata; | |||
1238 | int r; | |||
1239 | ||||
1240 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/network/networkd-network.c" , 1240, __PRETTY_FUNCTION__); } while (0); | |||
1241 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/network/networkd-network.c" , 1241, __PRETTY_FUNCTION__); } while (0); | |||
1242 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/network/networkd-network.c" , 1242, __PRETTY_FUNCTION__); } while (0); | |||
1243 | ||||
1244 | for (;;) { | |||
1245 | _cleanup_free___attribute__((cleanup(freep))) char *w = NULL((void*)0); | |||
1246 | union in_addr_union a; | |||
1247 | struct in_addr_data *m; | |||
1248 | int family; | |||
1249 | ||||
1250 | r = extract_first_word(&rvalue, &w, NULL((void*)0), 0); | |||
1251 | if (r == -ENOMEM12) | |||
1252 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 1252, __func__); | |||
1253 | if (r < 0) { | |||
1254 | log_syntax(unit, LOG_ERR, filename, line, r, "Invalid syntax, ignoring: %s", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 1254 , __func__, "Invalid syntax, ignoring: %s", rvalue) : -abs(_e ); }); | |||
1255 | break; | |||
1256 | } | |||
1257 | if (r == 0) | |||
1258 | break; | |||
1259 | ||||
1260 | r = in_addr_from_string_auto(w, &family, &a); | |||
1261 | if (r < 0) { | |||
1262 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse dns server address, ignoring: %s", w)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 1262 , __func__, "Failed to parse dns server address, ignoring: %s" , w) : -abs(_e); }); | |||
1263 | continue; | |||
1264 | } | |||
1265 | ||||
1266 | m = reallocarray(n->dns, n->n_dns + 1, sizeof(struct in_addr_data)); | |||
1267 | if (!m) | |||
1268 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 1268, __func__); | |||
1269 | ||||
1270 | m[n->n_dns++] = (struct in_addr_data) { | |||
1271 | .family = family, | |||
1272 | .address = a, | |||
1273 | }; | |||
1274 | ||||
1275 | n->dns = m; | |||
1276 | } | |||
1277 | ||||
1278 | return 0; | |||
1279 | } | |||
1280 | ||||
1281 | int config_parse_dnssec_negative_trust_anchors( | |||
1282 | const char *unit, | |||
1283 | const char *filename, | |||
1284 | unsigned line, | |||
1285 | const char *section, | |||
1286 | unsigned section_line, | |||
1287 | const char *lvalue, | |||
1288 | int ltype, | |||
1289 | const char *rvalue, | |||
1290 | void *data, | |||
1291 | void *userdata) { | |||
1292 | ||||
1293 | const char *p = rvalue; | |||
1294 | Network *n = data; | |||
1295 | int r; | |||
1296 | ||||
1297 | assert(n)do { if ((__builtin_expect(!!(!(n)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("n"), "../src/network/networkd-network.c" , 1297, __PRETTY_FUNCTION__); } while (0); | |||
1298 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/network/networkd-network.c" , 1298, __PRETTY_FUNCTION__); } while (0); | |||
1299 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/network/networkd-network.c" , 1299, __PRETTY_FUNCTION__); } while (0); | |||
1300 | ||||
1301 | if (isempty(rvalue)) { | |||
1302 | n->dnssec_negative_trust_anchors = set_free_free(n->dnssec_negative_trust_anchors); | |||
1303 | return 0; | |||
1304 | } | |||
1305 | ||||
1306 | for (;;) { | |||
1307 | _cleanup_free___attribute__((cleanup(freep))) char *w = NULL((void*)0); | |||
1308 | ||||
1309 | r = extract_first_word(&p, &w, NULL((void*)0), 0); | |||
1310 | if (r < 0) { | |||
1311 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to extract negative trust anchor domain, ignoring: %s", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 1311 , __func__, "Failed to extract negative trust anchor domain, ignoring: %s" , rvalue) : -abs(_e); }); | |||
1312 | break; | |||
1313 | } | |||
1314 | if (r == 0) | |||
1315 | break; | |||
1316 | ||||
1317 | r = dns_name_is_valid(w); | |||
1318 | if (r <= 0) { | |||
1319 | log_syntax(unit, LOG_ERR, filename, line, r, "%s is not a valid domain name, ignoring.", w)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 1319 , __func__, "%s is not a valid domain name, ignoring.", w) : - abs(_e); }); | |||
1320 | continue; | |||
1321 | } | |||
1322 | ||||
1323 | r = set_ensure_allocated(&n->dnssec_negative_trust_anchors, &dns_name_hash_ops)internal_set_ensure_allocated(&n->dnssec_negative_trust_anchors , &dns_name_hash_ops ); | |||
1324 | if (r < 0) | |||
1325 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 1325, __func__); | |||
1326 | ||||
1327 | r = set_put(n->dnssec_negative_trust_anchors, w); | |||
1328 | if (r < 0) | |||
1329 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 1329, __func__); | |||
1330 | if (r > 0) | |||
1331 | w = NULL((void*)0); | |||
1332 | } | |||
1333 | ||||
1334 | return 0; | |||
1335 | } | |||
1336 | ||||
1337 | int config_parse_ntp( | |||
1338 | const char *unit, | |||
1339 | const char *filename, | |||
1340 | unsigned line, | |||
1341 | const char *section, | |||
1342 | unsigned section_line, | |||
1343 | const char *lvalue, | |||
1344 | int ltype, | |||
1345 | const char *rvalue, | |||
1346 | void *data, | |||
1347 | void *userdata) { | |||
1348 | ||||
1349 | char ***l = data; | |||
1350 | int r; | |||
1351 | ||||
1352 | assert(l)do { if ((__builtin_expect(!!(!(l)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("l"), "../src/network/networkd-network.c" , 1352, __PRETTY_FUNCTION__); } while (0); | |||
1353 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/network/networkd-network.c" , 1353, __PRETTY_FUNCTION__); } while (0); | |||
1354 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/network/networkd-network.c" , 1354, __PRETTY_FUNCTION__); } while (0); | |||
1355 | ||||
1356 | if (isempty(rvalue)) { | |||
1357 | *l = strv_free(*l); | |||
1358 | return 0; | |||
1359 | } | |||
1360 | ||||
1361 | for (;;) { | |||
1362 | _cleanup_free___attribute__((cleanup(freep))) char *w = NULL((void*)0); | |||
1363 | ||||
1364 | r = extract_first_word(&rvalue, &w, NULL((void*)0), 0); | |||
1365 | if (r == -ENOMEM12) | |||
1366 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 1366, __func__); | |||
1367 | if (r < 0) { | |||
1368 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to extract NTP server name, ignoring: %s", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 1368 , __func__, "Failed to extract NTP server name, ignoring: %s" , rvalue) : -abs(_e); }); | |||
1369 | break; | |||
1370 | } | |||
1371 | if (r == 0) | |||
1372 | break; | |||
1373 | ||||
1374 | r = dns_name_is_valid_or_address(w); | |||
1375 | if (r <= 0) { | |||
1376 | log_syntax(unit, LOG_ERR, filename, line, r, "%s is not a valid domain name or IP address, ignoring.", w)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 1376 , __func__, "%s is not a valid domain name or IP address, ignoring." , w) : -abs(_e); }); | |||
1377 | continue; | |||
1378 | } | |||
1379 | ||||
1380 | r = strv_push(l, w); | |||
1381 | if (r < 0) | |||
1382 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 1382, __func__); | |||
1383 | ||||
1384 | w = NULL((void*)0); | |||
1385 | } | |||
1386 | ||||
1387 | return 0; | |||
1388 | } | |||
1389 | ||||
1390 | int config_parse_dhcp_user_class( | |||
1391 | const char *unit, | |||
1392 | const char *filename, | |||
1393 | unsigned line, | |||
1394 | const char *section, | |||
1395 | unsigned section_line, | |||
1396 | const char *lvalue, | |||
1397 | int ltype, | |||
1398 | const char *rvalue, | |||
1399 | void *data, | |||
1400 | void *userdata) { | |||
1401 | ||||
1402 | char ***l = data; | |||
1403 | int r; | |||
1404 | ||||
1405 | assert(l)do { if ((__builtin_expect(!!(!(l)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("l"), "../src/network/networkd-network.c" , 1405, __PRETTY_FUNCTION__); } while (0); | |||
1406 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/network/networkd-network.c" , 1406, __PRETTY_FUNCTION__); } while (0); | |||
1407 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/network/networkd-network.c" , 1407, __PRETTY_FUNCTION__); } while (0); | |||
1408 | ||||
1409 | if (isempty(rvalue)) { | |||
1410 | *l = strv_free(*l); | |||
1411 | return 0; | |||
1412 | } | |||
1413 | ||||
1414 | for (;;) { | |||
1415 | _cleanup_free___attribute__((cleanup(freep))) char *w = NULL((void*)0); | |||
1416 | ||||
1417 | r = extract_first_word(&rvalue, &w, NULL((void*)0), 0); | |||
1418 | if (r == -ENOMEM12) | |||
1419 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 1419, __func__); | |||
1420 | if (r < 0) { | |||
1421 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to split user classes option, ignoring: %s", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 1421 , __func__, "Failed to split user classes option, ignoring: %s" , rvalue) : -abs(_e); }); | |||
1422 | break; | |||
1423 | } | |||
1424 | if (r == 0) | |||
1425 | break; | |||
1426 | ||||
1427 | if (strlen(w) > 255) { | |||
1428 | log_syntax(unit, LOG_ERR, filename, line, r, "%s length is not in the range 1-255, ignoring.", w)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 1428 , __func__, "%s length is not in the range 1-255, ignoring.", w) : -abs(_e); }); | |||
1429 | continue; | |||
1430 | } | |||
1431 | ||||
1432 | r = strv_push(l, w); | |||
1433 | if (r < 0) | |||
1434 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/network/networkd-network.c" , 1434, __func__); | |||
1435 | ||||
1436 | w = NULL((void*)0); | |||
1437 | } | |||
1438 | ||||
1439 | return 0; | |||
1440 | } | |||
1441 | ||||
1442 | int config_parse_dhcp_route_table(const char *unit, | |||
1443 | const char *filename, | |||
1444 | unsigned line, | |||
1445 | const char *section, | |||
1446 | unsigned section_line, | |||
1447 | const char *lvalue, | |||
1448 | int ltype, | |||
1449 | const char *rvalue, | |||
1450 | void *data, | |||
1451 | void *userdata) { | |||
1452 | Network *network = data; | |||
1453 | uint32_t rt; | |||
1454 | int r; | |||
1455 | ||||
1456 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/network/networkd-network.c" , 1456, __PRETTY_FUNCTION__); } while (0); | |||
1457 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/network/networkd-network.c" , 1457, __PRETTY_FUNCTION__); } while (0); | |||
1458 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/network/networkd-network.c" , 1458, __PRETTY_FUNCTION__); } while (0); | |||
1459 | assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/network/networkd-network.c" , 1459, __PRETTY_FUNCTION__); } while (0); | |||
1460 | ||||
1461 | r = safe_atou32(rvalue, &rt); | |||
1462 | if (r < 0) { | |||
1463 | log_syntax(unit, LOG_ERR, filename, line, r,({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 1464 , __func__, "Unable to read RouteTable, ignoring assignment: %s" , rvalue) : -abs(_e); }) | |||
1464 | "Unable to read RouteTable, ignoring assignment: %s", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/network/networkd-network.c", 1464 , __func__, "Unable to read RouteTable, ignoring assignment: %s" , rvalue) : -abs(_e); }); | |||
1465 | return 0; | |||
1466 | } | |||
1467 | ||||
1468 | network->dhcp_route_table = rt; | |||
1469 | network->dhcp_route_table_set = true1; | |||
1470 | ||||
1471 | return 0; | |||
1472 | } | |||
1473 | ||||
1474 | DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp_use_domains, dhcp_use_domains, DHCPUseDomains, "Failed to parse DHCP use domains setting")int config_parse_dhcp_use_domains(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line , const char *lvalue, int ltype, const char *rvalue, void *data , void *userdata) { DHCPUseDomains *i = data, x; do { if ((__builtin_expect (!!(!(filename)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("filename"), "../src/network/networkd-network.c", 1474, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lvalue"), "../src/network/networkd-network.c" , 1474, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect (!!(!(rvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("rvalue"), "../src/network/networkd-network.c", 1474, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/network/networkd-network.c" , 1474, __PRETTY_FUNCTION__); } while (0); x = dhcp_use_domains_from_string (rvalue); if (x < 0) { ({ int _level = (3), _e = (0); (log_get_max_level_realm (LOG_REALM_SYSTEMD) >= ((_level) & 0x07)) ? log_syntax_internal (unit, _level, filename, line, _e, "../src/network/networkd-network.c" , 1474, __func__, "Failed to parse DHCP use domains setting" ", ignoring: %s" , rvalue) : -abs(_e); }); return 0; } *i = x; return 0; }; | |||
1475 | ||||
1476 | static const char* const dhcp_use_domains_table[_DHCP_USE_DOMAINS_MAX] = { | |||
1477 | [DHCP_USE_DOMAINS_NO] = "no", | |||
1478 | [DHCP_USE_DOMAINS_ROUTE] = "route", | |||
1479 | [DHCP_USE_DOMAINS_YES] = "yes", | |||
1480 | }; | |||
1481 | ||||
1482 | DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(dhcp_use_domains, DHCPUseDomains, DHCP_USE_DOMAINS_YES)const char *dhcp_use_domains_to_string(DHCPUseDomains i) { if (i < 0 || i >= (DHCPUseDomains) __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(dhcp_use_domains_table ), typeof(&*(dhcp_use_domains_table))), sizeof(dhcp_use_domains_table )/sizeof((dhcp_use_domains_table)[0]), ((void)0)))) return (( void*)0); return dhcp_use_domains_table[i]; } DHCPUseDomains dhcp_use_domains_from_string (const char *s) { int b; if (!s) return -1; b = parse_boolean (s); if (b == 0) return (DHCPUseDomains) 0; else if (b > 0 ) return DHCP_USE_DOMAINS_YES; return (DHCPUseDomains) string_table_lookup (dhcp_use_domains_table, __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(dhcp_use_domains_table ), typeof(&*(dhcp_use_domains_table))), sizeof(dhcp_use_domains_table )/sizeof((dhcp_use_domains_table)[0]), ((void)0))), s); }; | |||
1483 | ||||
1484 | DEFINE_CONFIG_PARSE_ENUM(config_parse_lldp_mode, lldp_mode, LLDPMode, "Failed to parse LLDP= setting.")int config_parse_lldp_mode(const char *unit, const char *filename , unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata) { LLDPMode *i = data, x; do { if ((__builtin_expect (!!(!(filename)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("filename"), "../src/network/networkd-network.c", 1484, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lvalue"), "../src/network/networkd-network.c" , 1484, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect (!!(!(rvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("rvalue"), "../src/network/networkd-network.c", 1484, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/network/networkd-network.c" , 1484, __PRETTY_FUNCTION__); } while (0); x = lldp_mode_from_string (rvalue); if (x < 0) { ({ int _level = (3), _e = (0); (log_get_max_level_realm (LOG_REALM_SYSTEMD) >= ((_level) & 0x07)) ? log_syntax_internal (unit, _level, filename, line, _e, "../src/network/networkd-network.c" , 1484, __func__, "Failed to parse LLDP= setting." ", ignoring: %s" , rvalue) : -abs(_e); }); return 0; } *i = x; return 0; }; | |||
1485 | ||||
1486 | static const char* const lldp_mode_table[_LLDP_MODE_MAX] = { | |||
1487 | [LLDP_MODE_NO] = "no", | |||
1488 | [LLDP_MODE_YES] = "yes", | |||
1489 | [LLDP_MODE_ROUTERS_ONLY] = "routers-only", | |||
1490 | }; | |||
1491 | ||||
1492 | DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(lldp_mode, LLDPMode, LLDP_MODE_YES)const char *lldp_mode_to_string(LLDPMode i) { if (i < 0 || i >= (LLDPMode) __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p (typeof(lldp_mode_table), typeof(&*(lldp_mode_table))), sizeof (lldp_mode_table)/sizeof((lldp_mode_table)[0]), ((void)0)))) return ((void*)0); return lldp_mode_table[i]; } LLDPMode lldp_mode_from_string (const char *s) { int b; if (!s) return -1; b = parse_boolean (s); if (b == 0) return (LLDPMode) 0; else if (b > 0) return LLDP_MODE_YES; return (LLDPMode) string_table_lookup(lldp_mode_table , __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p (typeof(lldp_mode_table), typeof(&*(lldp_mode_table))), sizeof (lldp_mode_table)/sizeof((lldp_mode_table)[0]), ((void)0))), s ); }; |