]>
Commit | Line | Data |
---|---|---|
f579559b TG |
1 | /*** |
2 | This file is part of systemd. | |
3 | ||
4 | Copyright 2013 Tom Gundersen <teg@jklm.no> | |
5 | ||
6 | systemd is free software; you can redistribute it and/or modify it | |
7 | under the terms of the GNU Lesser General Public License as published by | |
8 | the Free Software Foundation; either version 2.1 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | systemd is distributed in the hope that it will be useful, but | |
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | Lesser General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU Lesser General Public License | |
17 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
18 | ***/ | |
19 | ||
20 | #include <netinet/ether.h> | |
21 | #include <linux/if.h> | |
4cc7a82c | 22 | #include <unistd.h> |
f579559b | 23 | |
b5efdb8a | 24 | #include "alloc-util.h" |
1346b1f0 | 25 | #include "bus-util.h" |
bd91b83e | 26 | #include "dhcp-lease-internal.h" |
3ffd4af2 | 27 | #include "fd-util.h" |
cf1d700d TG |
28 | #include "fileio.h" |
29 | #include "netlink-util.h" | |
c6f7c917 | 30 | #include "network-internal.h" |
8e1ad1ea | 31 | #include "networkd-lldp-tx.h" |
23f53b99 | 32 | #include "networkd-manager.h" |
1e7a0e21 | 33 | #include "networkd-ndisc.h" |
cf1d700d TG |
34 | #include "set.h" |
35 | #include "socket-util.h" | |
15a5e950 | 36 | #include "stdio-util.h" |
8b43440b | 37 | #include "string-table.h" |
cf1d700d TG |
38 | #include "udev-util.h" |
39 | #include "util.h" | |
40 | #include "virt.h" | |
fc2f9534 | 41 | |
b9d74c40 LP |
42 | static bool link_dhcp6_enabled(Link *link) { |
43 | assert(link); | |
44 | ||
fa709992 LP |
45 | if (!socket_ipv6_is_supported()) |
46 | return false; | |
47 | ||
78c958f8 TG |
48 | if (link->flags & IFF_LOOPBACK) |
49 | return false; | |
50 | ||
51 | if (!link->network) | |
52 | return false; | |
53 | ||
e0ee46f2 | 54 | return link->network->dhcp & ADDRESS_FAMILY_IPV6; |
78c958f8 TG |
55 | } |
56 | ||
b9d74c40 LP |
57 | static bool link_dhcp4_enabled(Link *link) { |
58 | assert(link); | |
59 | ||
78c958f8 TG |
60 | if (link->flags & IFF_LOOPBACK) |
61 | return false; | |
62 | ||
63 | if (!link->network) | |
64 | return false; | |
65 | ||
e0ee46f2 | 66 | return link->network->dhcp & ADDRESS_FAMILY_IPV4; |
78c958f8 TG |
67 | } |
68 | ||
b9d74c40 LP |
69 | static bool link_dhcp4_server_enabled(Link *link) { |
70 | assert(link); | |
71 | ||
78c958f8 TG |
72 | if (link->flags & IFF_LOOPBACK) |
73 | return false; | |
74 | ||
75 | if (!link->network) | |
76 | return false; | |
77 | ||
78 | return link->network->dhcp_server; | |
79 | } | |
80 | ||
b9d74c40 LP |
81 | static bool link_ipv4ll_enabled(Link *link) { |
82 | assert(link); | |
83 | ||
78c958f8 TG |
84 | if (link->flags & IFF_LOOPBACK) |
85 | return false; | |
86 | ||
87 | if (!link->network) | |
88 | return false; | |
89 | ||
e0ee46f2 | 90 | return link->network->link_local & ADDRESS_FAMILY_IPV4; |
d0d6a4cd TG |
91 | } |
92 | ||
b9d74c40 LP |
93 | static bool link_ipv6ll_enabled(Link *link) { |
94 | assert(link); | |
95 | ||
fa709992 LP |
96 | if (!socket_ipv6_is_supported()) |
97 | return false; | |
98 | ||
d0d6a4cd TG |
99 | if (link->flags & IFF_LOOPBACK) |
100 | return false; | |
101 | ||
102 | if (!link->network) | |
103 | return false; | |
104 | ||
e0ee46f2 | 105 | return link->network->link_local & ADDRESS_FAMILY_IPV6; |
78c958f8 TG |
106 | } |
107 | ||
439689c6 SS |
108 | static bool link_ipv6_enabled(Link *link) { |
109 | assert(link); | |
110 | ||
111 | if (!socket_ipv6_is_supported()) | |
112 | return false; | |
113 | ||
2b00a4e0 TY |
114 | if (link->network->bridge) |
115 | return false; | |
116 | ||
4cef7fe3 TY |
117 | /* DHCPv6 client will not be started if no IPv6 link-local address is configured. */ |
118 | return link_ipv6ll_enabled(link) || network_has_static_ipv6_addresses(link->network); | |
439689c6 SS |
119 | } |
120 | ||
8e1ad1ea | 121 | static bool link_lldp_rx_enabled(Link *link) { |
b710e6b6 LP |
122 | assert(link); |
123 | ||
ce43e484 SS |
124 | if (link->flags & IFF_LOOPBACK) |
125 | return false; | |
126 | ||
b710e6b6 LP |
127 | if (link->iftype != ARPHRD_ETHER) |
128 | return false; | |
129 | ||
ce43e484 SS |
130 | if (!link->network) |
131 | return false; | |
132 | ||
5a8bcb67 | 133 | if (link->network->bridge) |
ce43e484 SS |
134 | return false; |
135 | ||
34437b4f | 136 | return link->network->lldp_mode != LLDP_MODE_NO; |
ce43e484 SS |
137 | } |
138 | ||
7272b25e | 139 | static bool link_lldp_emit_enabled(Link *link) { |
8e1ad1ea LP |
140 | assert(link); |
141 | ||
142 | if (link->flags & IFF_LOOPBACK) | |
143 | return false; | |
144 | ||
145 | if (link->iftype != ARPHRD_ETHER) | |
146 | return false; | |
147 | ||
148 | if (!link->network) | |
149 | return false; | |
150 | ||
7272b25e | 151 | return link->network->lldp_emit != LLDP_EMIT_NO; |
8e1ad1ea LP |
152 | } |
153 | ||
769d324c | 154 | static bool link_ipv4_forward_enabled(Link *link) { |
b9d74c40 LP |
155 | assert(link); |
156 | ||
5a8bcb67 LP |
157 | if (link->flags & IFF_LOOPBACK) |
158 | return false; | |
159 | ||
160 | if (!link->network) | |
161 | return false; | |
162 | ||
765afd5c LP |
163 | if (link->network->ip_forward == _ADDRESS_FAMILY_BOOLEAN_INVALID) |
164 | return false; | |
165 | ||
e0ee46f2 | 166 | return link->network->ip_forward & ADDRESS_FAMILY_IPV4; |
769d324c LP |
167 | } |
168 | ||
169 | static bool link_ipv6_forward_enabled(Link *link) { | |
b9d74c40 | 170 | assert(link); |
765afd5c LP |
171 | |
172 | if (!socket_ipv6_is_supported()) | |
173 | return false; | |
174 | ||
769d324c LP |
175 | if (link->flags & IFF_LOOPBACK) |
176 | return false; | |
177 | ||
178 | if (!link->network) | |
179 | return false; | |
180 | ||
765afd5c LP |
181 | if (link->network->ip_forward == _ADDRESS_FAMILY_BOOLEAN_INVALID) |
182 | return false; | |
183 | ||
e0ee46f2 | 184 | return link->network->ip_forward & ADDRESS_FAMILY_IPV6; |
5a8bcb67 LP |
185 | } |
186 | ||
23d8b221 SS |
187 | static bool link_proxy_arp_enabled(Link *link) { |
188 | assert(link); | |
189 | ||
190 | if (link->flags & IFF_LOOPBACK) | |
191 | return false; | |
192 | ||
193 | if (!link->network) | |
194 | return false; | |
195 | ||
196 | if (link->network->proxy_arp < 0) | |
197 | return false; | |
198 | ||
199 | return true; | |
200 | } | |
201 | ||
b9d74c40 LP |
202 | static bool link_ipv6_accept_ra_enabled(Link *link) { |
203 | assert(link); | |
204 | ||
fa709992 LP |
205 | if (!socket_ipv6_is_supported()) |
206 | return false; | |
207 | ||
f5a8c43f TG |
208 | if (link->flags & IFF_LOOPBACK) |
209 | return false; | |
210 | ||
211 | if (!link->network) | |
212 | return false; | |
213 | ||
214 | /* If unset use system default (enabled if local forwarding is disabled. | |
215 | * disabled if local forwarding is enabled). | |
216 | * If set, ignore or enforce RA independent of local forwarding state. | |
217 | */ | |
218 | if (link->network->ipv6_accept_ra < 0) | |
219 | /* default to accept RA if ip_forward is disabled and ignore RA if ip_forward is enabled */ | |
220 | return !link_ipv6_forward_enabled(link); | |
221 | else if (link->network->ipv6_accept_ra > 0) | |
222 | /* accept RA even if ip_forward is enabled */ | |
223 | return true; | |
224 | else | |
225 | /* ignore RA */ | |
226 | return false; | |
227 | } | |
228 | ||
1f0d9695 | 229 | static IPv6PrivacyExtensions link_ipv6_privacy_extensions(Link *link) { |
fa709992 | 230 | assert(link); |
d68e2e59 LP |
231 | |
232 | if (!socket_ipv6_is_supported()) | |
233 | return _IPV6_PRIVACY_EXTENSIONS_INVALID; | |
234 | ||
49092e22 | 235 | if (link->flags & IFF_LOOPBACK) |
1f0d9695 | 236 | return _IPV6_PRIVACY_EXTENSIONS_INVALID; |
49092e22 SS |
237 | |
238 | if (!link->network) | |
1f0d9695 | 239 | return _IPV6_PRIVACY_EXTENSIONS_INVALID; |
49092e22 SS |
240 | |
241 | return link->network->ipv6_privacy_extensions; | |
242 | } | |
243 | ||
439689c6 SS |
244 | static int link_enable_ipv6(Link *link) { |
245 | const char *p = NULL; | |
246 | bool disabled; | |
247 | int r; | |
248 | ||
249 | if (link->flags & IFF_LOOPBACK) | |
250 | return 0; | |
251 | ||
252 | disabled = !link_ipv6_enabled(link); | |
253 | ||
254 | p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/disable_ipv6"); | |
255 | ||
256 | r = write_string_file(p, one_zero(disabled), WRITE_STRING_FILE_VERIFY_ON_FAILURE); | |
257 | if (r < 0) | |
258 | log_link_warning_errno(link, r, "Cannot %s IPv6 for interface %s: %m", disabled ? "disable" : "enable", link->ifname); | |
2d37cd53 ZJS |
259 | else |
260 | log_link_info(link, "IPv6 %sd for interface: %m", enable_disable(!disabled)); | |
439689c6 SS |
261 | |
262 | return 0; | |
263 | } | |
264 | ||
84de38c5 TG |
265 | void link_update_operstate(Link *link) { |
266 | LinkOperationalState operstate; | |
267 | assert(link); | |
268 | ||
269 | if (link->kernel_operstate == IF_OPER_DORMANT) | |
270 | operstate = LINK_OPERSTATE_DORMANT; | |
271 | else if (link_has_carrier(link)) { | |
272 | Address *address; | |
273 | uint8_t scope = RT_SCOPE_NOWHERE; | |
274 | Iterator i; | |
275 | ||
276 | /* if we have carrier, check what addresses we have */ | |
277 | SET_FOREACH(address, link->addresses, i) { | |
278 | if (!address_is_ready(address)) | |
279 | continue; | |
280 | ||
281 | if (address->scope < scope) | |
282 | scope = address->scope; | |
283 | } | |
284 | ||
285 | /* for operstate we also take foreign addresses into account */ | |
286 | SET_FOREACH(address, link->addresses_foreign, i) { | |
287 | if (!address_is_ready(address)) | |
288 | continue; | |
289 | ||
290 | if (address->scope < scope) | |
291 | scope = address->scope; | |
292 | } | |
293 | ||
294 | if (scope < RT_SCOPE_SITE) | |
295 | /* universally accessible addresses found */ | |
296 | operstate = LINK_OPERSTATE_ROUTABLE; | |
297 | else if (scope < RT_SCOPE_HOST) | |
298 | /* only link or site local addresses found */ | |
299 | operstate = LINK_OPERSTATE_DEGRADED; | |
300 | else | |
301 | /* no useful addresses found */ | |
302 | operstate = LINK_OPERSTATE_CARRIER; | |
303 | } else if (link->flags & IFF_UP) | |
304 | operstate = LINK_OPERSTATE_NO_CARRIER; | |
305 | else | |
306 | operstate = LINK_OPERSTATE_OFF; | |
307 | ||
308 | if (link->operstate != operstate) { | |
309 | link->operstate = operstate; | |
310 | link_send_changed(link, "OperationalState", NULL); | |
311 | link_dirty(link); | |
84de38c5 TG |
312 | } |
313 | } | |
314 | ||
51d18171 TG |
315 | #define FLAG_STRING(string, flag, old, new) \ |
316 | (((old ^ new) & flag) \ | |
317 | ? ((old & flag) ? (" -" string) : (" +" string)) \ | |
318 | : "") | |
319 | ||
1c4baffc | 320 | static int link_update_flags(Link *link, sd_netlink_message *m) { |
51d18171 TG |
321 | unsigned flags, unknown_flags_added, unknown_flags_removed, unknown_flags; |
322 | uint8_t operstate; | |
323 | int r; | |
324 | ||
325 | assert(link); | |
326 | ||
327 | r = sd_rtnl_message_link_get_flags(m, &flags); | |
6a7a4e4d LP |
328 | if (r < 0) |
329 | return log_link_warning_errno(link, r, "Could not get link flags: %m"); | |
51d18171 | 330 | |
1c4baffc | 331 | r = sd_netlink_message_read_u8(m, IFLA_OPERSTATE, &operstate); |
51d18171 TG |
332 | if (r < 0) |
333 | /* if we got a message without operstate, take it to mean | |
334 | the state was unchanged */ | |
335 | operstate = link->kernel_operstate; | |
336 | ||
337 | if ((link->flags == flags) && (link->kernel_operstate == operstate)) | |
338 | return 0; | |
339 | ||
340 | if (link->flags != flags) { | |
6a7a4e4d | 341 | log_link_debug(link, "Flags change:%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", |
51d18171 TG |
342 | FLAG_STRING("LOOPBACK", IFF_LOOPBACK, link->flags, flags), |
343 | FLAG_STRING("MASTER", IFF_MASTER, link->flags, flags), | |
344 | FLAG_STRING("SLAVE", IFF_SLAVE, link->flags, flags), | |
345 | FLAG_STRING("UP", IFF_UP, link->flags, flags), | |
346 | FLAG_STRING("DORMANT", IFF_DORMANT, link->flags, flags), | |
347 | FLAG_STRING("LOWER_UP", IFF_LOWER_UP, link->flags, flags), | |
348 | FLAG_STRING("RUNNING", IFF_RUNNING, link->flags, flags), | |
349 | FLAG_STRING("MULTICAST", IFF_MULTICAST, link->flags, flags), | |
350 | FLAG_STRING("BROADCAST", IFF_BROADCAST, link->flags, flags), | |
351 | FLAG_STRING("POINTOPOINT", IFF_POINTOPOINT, link->flags, flags), | |
352 | FLAG_STRING("PROMISC", IFF_PROMISC, link->flags, flags), | |
353 | FLAG_STRING("ALLMULTI", IFF_ALLMULTI, link->flags, flags), | |
354 | FLAG_STRING("PORTSEL", IFF_PORTSEL, link->flags, flags), | |
355 | FLAG_STRING("AUTOMEDIA", IFF_AUTOMEDIA, link->flags, flags), | |
356 | FLAG_STRING("DYNAMIC", IFF_DYNAMIC, link->flags, flags), | |
357 | FLAG_STRING("NOARP", IFF_NOARP, link->flags, flags), | |
358 | FLAG_STRING("NOTRAILERS", IFF_NOTRAILERS, link->flags, flags), | |
359 | FLAG_STRING("DEBUG", IFF_DEBUG, link->flags, flags), | |
360 | FLAG_STRING("ECHO", IFF_ECHO, link->flags, flags)); | |
361 | ||
362 | unknown_flags = ~(IFF_LOOPBACK | IFF_MASTER | IFF_SLAVE | IFF_UP | | |
363 | IFF_DORMANT | IFF_LOWER_UP | IFF_RUNNING | | |
364 | IFF_MULTICAST | IFF_BROADCAST | IFF_POINTOPOINT | | |
365 | IFF_PROMISC | IFF_ALLMULTI | IFF_PORTSEL | | |
366 | IFF_AUTOMEDIA | IFF_DYNAMIC | IFF_NOARP | | |
367 | IFF_NOTRAILERS | IFF_DEBUG | IFF_ECHO); | |
368 | unknown_flags_added = ((link->flags ^ flags) & flags & unknown_flags); | |
369 | unknown_flags_removed = ((link->flags ^ flags) & link->flags & unknown_flags); | |
370 | ||
371 | /* link flags are currently at most 18 bits, let's align to | |
372 | * printing 20 */ | |
373 | if (unknown_flags_added) | |
79008bdd | 374 | log_link_debug(link, |
6a7a4e4d | 375 | "Unknown link flags gained: %#.5x (ignoring)", |
51d18171 TG |
376 | unknown_flags_added); |
377 | ||
378 | if (unknown_flags_removed) | |
79008bdd | 379 | log_link_debug(link, |
6a7a4e4d | 380 | "Unknown link flags lost: %#.5x (ignoring)", |
51d18171 TG |
381 | unknown_flags_removed); |
382 | } | |
383 | ||
384 | link->flags = flags; | |
385 | link->kernel_operstate = operstate; | |
386 | ||
84de38c5 | 387 | link_update_operstate(link); |
51d18171 TG |
388 | |
389 | return 0; | |
390 | } | |
391 | ||
1c4baffc | 392 | static int link_new(Manager *manager, sd_netlink_message *message, Link **ret) { |
14b746f7 | 393 | _cleanup_link_unref_ Link *link = NULL; |
505f8da7 | 394 | uint16_t type; |
6cad256d | 395 | const char *ifname, *kind = NULL; |
505f8da7 | 396 | int r, ifindex; |
b710e6b6 | 397 | unsigned short iftype; |
f579559b | 398 | |
0c2f9b84 | 399 | assert(manager); |
505f8da7 | 400 | assert(message); |
f579559b TG |
401 | assert(ret); |
402 | ||
6cad256d TJ |
403 | /* check for link kind */ |
404 | r = sd_netlink_message_enter_container(message, IFLA_LINKINFO); | |
405 | if (r == 0) { | |
406 | (void)sd_netlink_message_read_string(message, IFLA_INFO_KIND, &kind); | |
407 | r = sd_netlink_message_exit_container(message); | |
408 | if (r < 0) | |
409 | return r; | |
410 | } | |
411 | ||
1c4baffc | 412 | r = sd_netlink_message_get_type(message, &type); |
505f8da7 TG |
413 | if (r < 0) |
414 | return r; | |
415 | else if (type != RTM_NEWLINK) | |
416 | return -EINVAL; | |
417 | ||
418 | r = sd_rtnl_message_link_get_ifindex(message, &ifindex); | |
419 | if (r < 0) | |
420 | return r; | |
421 | else if (ifindex <= 0) | |
422 | return -EINVAL; | |
423 | ||
b710e6b6 LP |
424 | r = sd_rtnl_message_link_get_type(message, &iftype); |
425 | if (r < 0) | |
426 | return r; | |
427 | ||
1c4baffc | 428 | r = sd_netlink_message_read_string(message, IFLA_IFNAME, &ifname); |
505f8da7 TG |
429 | if (r < 0) |
430 | return r; | |
431 | ||
f579559b TG |
432 | link = new0(Link, 1); |
433 | if (!link) | |
434 | return -ENOMEM; | |
435 | ||
14b746f7 | 436 | link->n_ref = 1; |
5a3eb5a7 | 437 | link->manager = manager; |
8434fd5c | 438 | link->state = LINK_STATE_PENDING; |
be3a09b7 | 439 | link->rtnl_extended_attrs = true; |
505f8da7 | 440 | link->ifindex = ifindex; |
b710e6b6 | 441 | link->iftype = iftype; |
505f8da7 TG |
442 | link->ifname = strdup(ifname); |
443 | if (!link->ifname) | |
444 | return -ENOMEM; | |
f579559b | 445 | |
6cad256d TJ |
446 | if (kind) { |
447 | link->kind = strdup(kind); | |
448 | if (!link->kind) | |
449 | return -ENOMEM; | |
450 | } | |
451 | ||
1c4baffc | 452 | r = sd_netlink_message_read_ether_addr(message, IFLA_ADDRESS, &link->mac); |
512922f8 | 453 | if (r < 0) |
34437b4f | 454 | log_link_debug_errno(link, r, "MAC address not found for new device, continuing without"); |
512922f8 | 455 | |
34437b4f | 456 | if (asprintf(&link->state_file, "/run/systemd/netif/links/%d", link->ifindex) < 0) |
315db1a8 | 457 | return -ENOMEM; |
fe8db0c5 | 458 | |
34437b4f | 459 | if (asprintf(&link->lease_file, "/run/systemd/netif/leases/%d", link->ifindex) < 0) |
68a8723c TG |
460 | return -ENOMEM; |
461 | ||
34437b4f | 462 | if (asprintf(&link->lldp_file, "/run/systemd/netif/lldp/%d", link->ifindex) < 0) |
49699bac SS |
463 | return -ENOMEM; |
464 | ||
d5099efc | 465 | r = hashmap_ensure_allocated(&manager->links, NULL); |
ae06ab10 TG |
466 | if (r < 0) |
467 | return r; | |
468 | ||
469 | r = hashmap_put(manager->links, INT_TO_PTR(link->ifindex), link); | |
f579559b TG |
470 | if (r < 0) |
471 | return r; | |
472 | ||
51d18171 TG |
473 | r = link_update_flags(link, message); |
474 | if (r < 0) | |
475 | return r; | |
476 | ||
f579559b TG |
477 | *ret = link; |
478 | link = NULL; | |
479 | ||
480 | return 0; | |
481 | } | |
482 | ||
14b746f7 | 483 | static void link_free(Link *link) { |
428fd0a7 | 484 | Address *address; |
0d4ad91d AR |
485 | Iterator i; |
486 | Link *carrier; | |
428fd0a7 | 487 | |
f579559b TG |
488 | if (!link) |
489 | return; | |
490 | ||
cf1d700d TG |
491 | while (!set_isempty(link->addresses)) |
492 | address_free(set_first(link->addresses)); | |
493 | ||
adda1ed9 TG |
494 | while (!set_isempty(link->addresses_foreign)) |
495 | address_free(set_first(link->addresses_foreign)); | |
496 | ||
4701725c HV |
497 | link->addresses = set_free(link->addresses); |
498 | ||
499 | link->addresses_foreign = set_free(link->addresses_foreign); | |
adda1ed9 | 500 | |
11bf3cce LP |
501 | while ((address = link->pool_addresses)) { |
502 | LIST_REMOVE(addresses, link->pool_addresses, address); | |
503 | address_free(address); | |
504 | } | |
505 | ||
bfcdba8d | 506 | sd_dhcp_server_unref(link->dhcp_server); |
e5b04c8d | 507 | sd_dhcp_client_unref(link->dhcp_client); |
a6cc569e | 508 | sd_dhcp_lease_unref(link->dhcp_lease); |
f5be5601 | 509 | |
7272b25e | 510 | link_lldp_emit_stop(link); |
8e1ad1ea | 511 | |
68a8723c TG |
512 | free(link->lease_file); |
513 | ||
4afd3348 | 514 | sd_lldp_unref(link->lldp); |
49699bac SS |
515 | free(link->lldp_file); |
516 | ||
c69305ff LP |
517 | ndisc_flush(link); |
518 | ||
56cd007a | 519 | sd_ipv4ll_unref(link->ipv4ll); |
4138fb2c | 520 | sd_dhcp6_client_unref(link->dhcp6_client); |
1e7a0e21 LP |
521 | sd_ndisc_unref(link->ndisc); |
522 | ||
28aeb07f | 523 | if (link->manager) |
ae06ab10 | 524 | hashmap_remove(link->manager->links, INT_TO_PTR(link->ifindex)); |
f579559b | 525 | |
c166a070 | 526 | free(link->ifname); |
68a8723c | 527 | |
ceac4078 | 528 | free(link->kind); |
6cad256d | 529 | |
84de38c5 | 530 | (void)unlink(link->state_file); |
fe8db0c5 | 531 | free(link->state_file); |
c166a070 | 532 | |
b5db00e5 UTL |
533 | udev_device_unref(link->udev_device); |
534 | ||
0d4ad91d AR |
535 | HASHMAP_FOREACH (carrier, link->bound_to_links, i) |
536 | hashmap_remove(link->bound_to_links, INT_TO_PTR(carrier->ifindex)); | |
537 | hashmap_free(link->bound_to_links); | |
538 | ||
539 | HASHMAP_FOREACH (carrier, link->bound_by_links, i) | |
540 | hashmap_remove(link->bound_by_links, INT_TO_PTR(carrier->ifindex)); | |
541 | hashmap_free(link->bound_by_links); | |
542 | ||
f579559b TG |
543 | free(link); |
544 | } | |
545 | ||
14b746f7 | 546 | Link *link_unref(Link *link) { |
957325b7 TG |
547 | if (!link) |
548 | return NULL; | |
549 | ||
550 | assert(link->n_ref > 0); | |
551 | ||
313cefa1 | 552 | link->n_ref--; |
957325b7 TG |
553 | |
554 | if (link->n_ref > 0) | |
555 | return NULL; | |
556 | ||
557 | link_free(link); | |
14b746f7 TG |
558 | |
559 | return NULL; | |
560 | } | |
561 | ||
562 | Link *link_ref(Link *link) { | |
957325b7 TG |
563 | if (!link) |
564 | return NULL; | |
565 | ||
566 | assert(link->n_ref > 0); | |
567 | ||
313cefa1 | 568 | link->n_ref++; |
14b746f7 TG |
569 | |
570 | return link; | |
571 | } | |
572 | ||
11a7f229 TG |
573 | int link_get(Manager *m, int ifindex, Link **ret) { |
574 | Link *link; | |
11a7f229 TG |
575 | |
576 | assert(m); | |
11a7f229 TG |
577 | assert(ifindex); |
578 | assert(ret); | |
579 | ||
ae06ab10 | 580 | link = hashmap_get(m->links, INT_TO_PTR(ifindex)); |
11a7f229 TG |
581 | if (!link) |
582 | return -ENODEV; | |
583 | ||
584 | *ret = link; | |
585 | ||
586 | return 0; | |
587 | } | |
588 | ||
e331e246 TG |
589 | static void link_set_state(Link *link, LinkState state) { |
590 | assert(link); | |
591 | ||
592 | if (link->state == state) | |
593 | return; | |
594 | ||
595 | link->state = state; | |
596 | ||
597 | link_send_changed(link, "AdministrativeState", NULL); | |
e331e246 TG |
598 | } |
599 | ||
57bd6899 TG |
600 | static void link_enter_unmanaged(Link *link) { |
601 | assert(link); | |
602 | ||
6a7a4e4d | 603 | log_link_debug(link, "Unmanaged"); |
57bd6899 | 604 | |
e331e246 | 605 | link_set_state(link, LINK_STATE_UNMANAGED); |
57bd6899 | 606 | |
84de38c5 | 607 | link_dirty(link); |
57bd6899 TG |
608 | } |
609 | ||
111bb8f9 TG |
610 | static int link_stop_clients(Link *link) { |
611 | int r = 0, k; | |
612 | ||
613 | assert(link); | |
614 | assert(link->manager); | |
615 | assert(link->manager->event); | |
616 | ||
ba179154 | 617 | if (link->dhcp_client) { |
111bb8f9 | 618 | k = sd_dhcp_client_stop(link->dhcp_client); |
6a7a4e4d | 619 | if (k < 0) |
36c7d709 | 620 | r = log_link_warning_errno(link, k, "Could not stop DHCPv4 client: %m"); |
111bb8f9 TG |
621 | } |
622 | ||
ba179154 | 623 | if (link->ipv4ll) { |
111bb8f9 | 624 | k = sd_ipv4ll_stop(link->ipv4ll); |
6a7a4e4d | 625 | if (k < 0) |
36c7d709 | 626 | r = log_link_warning_errno(link, k, "Could not stop IPv4 link-local: %m"); |
dd43110f TG |
627 | } |
628 | ||
f5a8c43f TG |
629 | if (link->dhcp6_client) { |
630 | k = sd_dhcp6_client_stop(link->dhcp6_client); | |
631 | if (k < 0) | |
36c7d709 | 632 | r = log_link_warning_errno(link, k, "Could not stop DHCPv6 client: %m"); |
f5a8c43f | 633 | } |
4138fb2c | 634 | |
1e7a0e21 LP |
635 | if (link->ndisc) { |
636 | k = sd_ndisc_stop(link->ndisc); | |
6a7a4e4d | 637 | if (k < 0) |
36c7d709 | 638 | r = log_link_warning_errno(link, k, "Could not stop IPv6 Router Discovery: %m"); |
4138fb2c PF |
639 | } |
640 | ||
7272b25e | 641 | link_lldp_emit_stop(link); |
111bb8f9 TG |
642 | return r; |
643 | } | |
644 | ||
b22d8a00 | 645 | void link_enter_failed(Link *link) { |
ef1ba606 | 646 | assert(link); |
f882c247 | 647 | |
370e9930 | 648 | if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) |
2139694e TG |
649 | return; |
650 | ||
6a7a4e4d | 651 | log_link_warning(link, "Failed"); |
449f7554 | 652 | |
e331e246 | 653 | link_set_state(link, LINK_STATE_FAILED); |
fe8db0c5 | 654 | |
111bb8f9 TG |
655 | link_stop_clients(link); |
656 | ||
84de38c5 | 657 | link_dirty(link); |
f882c247 TG |
658 | } |
659 | ||
4f434938 LP |
660 | static Address* link_find_dhcp_server_address(Link *link) { |
661 | Address *address; | |
662 | ||
663 | assert(link); | |
664 | assert(link->network); | |
665 | ||
d4cdbea5 | 666 | /* The first statically configured address if there is any */ |
4f434938 LP |
667 | LIST_FOREACH(addresses, address, link->network->static_addresses) { |
668 | ||
669 | if (address->family != AF_INET) | |
670 | continue; | |
671 | ||
af93291c | 672 | if (in_addr_is_null(address->family, &address->in_addr)) |
4f434938 LP |
673 | continue; |
674 | ||
675 | return address; | |
676 | } | |
677 | ||
678 | /* If that didn't work, find a suitable address we got from the pool */ | |
679 | LIST_FOREACH(addresses, address, link->pool_addresses) { | |
680 | if (address->family != AF_INET) | |
681 | continue; | |
682 | ||
683 | return address; | |
684 | } | |
685 | ||
686 | return NULL; | |
687 | } | |
688 | ||
dd43110f | 689 | static int link_enter_configured(Link *link) { |
dd43110f TG |
690 | assert(link); |
691 | assert(link->network); | |
692 | assert(link->state == LINK_STATE_SETTING_ROUTES); | |
693 | ||
6a7a4e4d | 694 | log_link_info(link, "Configured"); |
dd43110f | 695 | |
e331e246 | 696 | link_set_state(link, LINK_STATE_CONFIGURED); |
dd43110f | 697 | |
84de38c5 | 698 | link_dirty(link); |
dd43110f TG |
699 | |
700 | return 0; | |
701 | } | |
702 | ||
8012cd39 TG |
703 | void link_check_ready(Link *link) { |
704 | Address *a; | |
705 | Iterator i; | |
706 | ||
3c9b8860 | 707 | assert(link); |
adda1ed9 | 708 | |
7209086d SS |
709 | if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) |
710 | return; | |
711 | ||
adda1ed9 TG |
712 | if (!link->network) |
713 | return; | |
3c9b8860 TG |
714 | |
715 | if (!link->static_configured) | |
716 | return; | |
717 | ||
78c958f8 | 718 | if (link_ipv4ll_enabled(link)) |
3c9b8860 TG |
719 | if (!link->ipv4ll_address || |
720 | !link->ipv4ll_route) | |
721 | return; | |
722 | ||
e7ab854c | 723 | if (link_ipv6ll_enabled(link)) |
c601ebf7 | 724 | if (in_addr_is_null(AF_INET6, (const union in_addr_union*) &link->ipv6ll_address) > 0) |
e7ab854c TG |
725 | return; |
726 | ||
3ada37a2 PF |
727 | if ((link_dhcp4_enabled(link) && !link_dhcp6_enabled(link) && |
728 | !link->dhcp4_configured) || | |
729 | (link_dhcp6_enabled(link) && !link_dhcp4_enabled(link) && | |
730 | !link->dhcp6_configured) || | |
731 | (link_dhcp4_enabled(link) && link_dhcp6_enabled(link) && | |
732 | !link->dhcp4_configured && !link->dhcp6_configured)) | |
18d29550 PF |
733 | return; |
734 | ||
fe307276 TG |
735 | if (link_ipv6_accept_ra_enabled(link) && !link->ndisc_configured) |
736 | return; | |
737 | ||
8012cd39 TG |
738 | SET_FOREACH(a, link->addresses, i) |
739 | if (!address_is_ready(a)) | |
740 | return; | |
741 | ||
9fdaa992 TG |
742 | if (link->state != LINK_STATE_CONFIGURED) |
743 | link_enter_configured(link); | |
3c9b8860 TG |
744 | |
745 | return; | |
746 | } | |
747 | ||
1c4baffc | 748 | static int route_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) { |
5da8149f | 749 | _cleanup_link_unref_ Link *link = userdata; |
f882c247 TG |
750 | int r; |
751 | ||
3c9b8860 | 752 | assert(link->link_messages > 0); |
370e9930 TG |
753 | assert(IN_SET(link->state, LINK_STATE_SETTING_ADDRESSES, |
754 | LINK_STATE_SETTING_ROUTES, LINK_STATE_FAILED, | |
755 | LINK_STATE_LINGER)); | |
f882c247 | 756 | |
313cefa1 | 757 | link->link_messages--; |
f882c247 | 758 | |
77a008c0 | 759 | if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) |
f882c247 TG |
760 | return 1; |
761 | ||
1c4baffc | 762 | r = sd_netlink_message_get_errno(m); |
c166a070 | 763 | if (r < 0 && r != -EEXIST) |
a2fae7bb | 764 | log_link_warning_errno(link, r, "Could not set route: %m"); |
f882c247 | 765 | |
3c9b8860 | 766 | if (link->link_messages == 0) { |
6a7a4e4d | 767 | log_link_debug(link, "Routes set"); |
3c9b8860 | 768 | link->static_configured = true; |
8012cd39 | 769 | link_check_ready(link); |
dd3efc09 | 770 | } |
f882c247 TG |
771 | |
772 | return 1; | |
773 | } | |
774 | ||
775 | static int link_enter_set_routes(Link *link) { | |
a6cc569e | 776 | Route *rt; |
f882c247 TG |
777 | int r; |
778 | ||
779 | assert(link); | |
780 | assert(link->network); | |
ef1ba606 | 781 | assert(link->state == LINK_STATE_SETTING_ADDRESSES); |
f882c247 | 782 | |
e331e246 | 783 | link_set_state(link, LINK_STATE_SETTING_ROUTES); |
f882c247 | 784 | |
3d3d4255 | 785 | LIST_FOREACH(routes, rt, link->network->static_routes) { |
483d099e | 786 | r = route_configure(rt, link, route_handler); |
dd3efc09 | 787 | if (r < 0) { |
6a7a4e4d | 788 | log_link_warning_errno(link, r, "Could not set routes: %m"); |
3c9b8860 | 789 | link_enter_failed(link); |
a6cc569e TG |
790 | return r; |
791 | } | |
792 | ||
313cefa1 | 793 | link->link_messages++; |
8ddbeaa2 | 794 | } |
f5be5601 | 795 | |
3c9b8860 TG |
796 | if (link->link_messages == 0) { |
797 | link->static_configured = true; | |
8012cd39 | 798 | link_check_ready(link); |
431ca2ce | 799 | } else |
6a7a4e4d | 800 | log_link_debug(link, "Setting routes"); |
f882c247 TG |
801 | |
802 | return 0; | |
803 | } | |
804 | ||
91b5f997 | 805 | int link_route_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) { |
5da8149f | 806 | _cleanup_link_unref_ Link *link = userdata; |
5c1d3fc9 UTL |
807 | int r; |
808 | ||
809 | assert(m); | |
810 | assert(link); | |
811 | assert(link->ifname); | |
812 | ||
5da8149f | 813 | if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) |
5c1d3fc9 UTL |
814 | return 1; |
815 | ||
1c4baffc | 816 | r = sd_netlink_message_get_errno(m); |
b90b025a | 817 | if (r < 0 && r != -ESRCH) |
a2fae7bb | 818 | log_link_warning_errno(link, r, "Could not drop route: %m"); |
5c1d3fc9 | 819 | |
5bdd314c | 820 | return 1; |
5c1d3fc9 UTL |
821 | } |
822 | ||
1c4baffc | 823 | static int address_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) { |
5da8149f | 824 | _cleanup_link_unref_ Link *link = userdata; |
f882c247 TG |
825 | int r; |
826 | ||
4958aee4 | 827 | assert(rtnl); |
f5be5601 TG |
828 | assert(m); |
829 | assert(link); | |
830 | assert(link->ifname); | |
3c9b8860 | 831 | assert(link->link_messages > 0); |
370e9930 TG |
832 | assert(IN_SET(link->state, LINK_STATE_SETTING_ADDRESSES, |
833 | LINK_STATE_FAILED, LINK_STATE_LINGER)); | |
f882c247 | 834 | |
313cefa1 | 835 | link->link_messages--; |
f882c247 | 836 | |
5da8149f | 837 | if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) |
f882c247 TG |
838 | return 1; |
839 | ||
1c4baffc | 840 | r = sd_netlink_message_get_errno(m); |
c166a070 | 841 | if (r < 0 && r != -EEXIST) |
a2fae7bb | 842 | log_link_warning_errno(link, r, "could not set address: %m"); |
45af44d4 | 843 | else if (r >= 0) |
200a0868 | 844 | manager_rtnl_process_address(rtnl, m, link->manager); |
f882c247 | 845 | |
3c9b8860 | 846 | if (link->link_messages == 0) { |
6a7a4e4d | 847 | log_link_debug(link, "Addresses set"); |
ef1ba606 | 848 | link_enter_set_routes(link); |
dd3efc09 | 849 | } |
f882c247 TG |
850 | |
851 | return 1; | |
852 | } | |
853 | ||
4f5f911e LP |
854 | static int link_push_dns_to_dhcp_server(Link *link, sd_dhcp_server *s) { |
855 | _cleanup_free_ struct in_addr *addresses = NULL; | |
856 | size_t n_addresses = 0, n_allocated = 0; | |
5512a963 | 857 | unsigned i; |
4f5f911e LP |
858 | |
859 | log_debug("Copying DNS server information from %s", link->ifname); | |
860 | ||
861 | if (!link->network) | |
862 | return 0; | |
863 | ||
5512a963 | 864 | for (i = 0; i < link->network->n_dns; i++) { |
4f5f911e LP |
865 | |
866 | /* Only look for IPv4 addresses */ | |
5512a963 | 867 | if (link->network->dns[i].family != AF_INET) |
4f5f911e LP |
868 | continue; |
869 | ||
870 | if (!GREEDY_REALLOC(addresses, n_allocated, n_addresses + 1)) | |
871 | return log_oom(); | |
872 | ||
5512a963 | 873 | addresses[n_addresses++] = link->network->dns[i].address.in; |
4f5f911e LP |
874 | } |
875 | ||
5512a963 | 876 | if (link->network->dhcp_use_dns && link->dhcp_lease) { |
4f5f911e LP |
877 | const struct in_addr *da = NULL; |
878 | int n; | |
879 | ||
880 | n = sd_dhcp_lease_get_dns(link->dhcp_lease, &da); | |
881 | if (n > 0) { | |
882 | ||
883 | if (!GREEDY_REALLOC(addresses, n_allocated, n_addresses + n)) | |
884 | return log_oom(); | |
885 | ||
886 | memcpy(addresses + n_addresses, da, n * sizeof(struct in_addr)); | |
887 | n_addresses += n; | |
888 | } | |
889 | } | |
890 | ||
891 | if (n_addresses <= 0) | |
892 | return 0; | |
893 | ||
894 | return sd_dhcp_server_set_dns(s, addresses, n_addresses); | |
895 | } | |
896 | ||
897 | static int link_push_ntp_to_dhcp_server(Link *link, sd_dhcp_server *s) { | |
898 | _cleanup_free_ struct in_addr *addresses = NULL; | |
899 | size_t n_addresses = 0, n_allocated = 0; | |
900 | char **a; | |
901 | ||
902 | if (!link->network) | |
903 | return 0; | |
904 | ||
905 | log_debug("Copying NTP server information from %s", link->ifname); | |
906 | ||
907 | STRV_FOREACH(a, link->network->ntp) { | |
908 | struct in_addr ia; | |
909 | ||
910 | /* Only look for IPv4 addresses */ | |
911 | if (inet_pton(AF_INET, *a, &ia) <= 0) | |
912 | continue; | |
913 | ||
914 | if (!GREEDY_REALLOC(addresses, n_allocated, n_addresses + 1)) | |
915 | return log_oom(); | |
916 | ||
917 | addresses[n_addresses++] = ia; | |
918 | } | |
919 | ||
5512a963 | 920 | if (link->network->dhcp_use_ntp && link->dhcp_lease) { |
4f5f911e LP |
921 | const struct in_addr *da = NULL; |
922 | int n; | |
923 | ||
924 | n = sd_dhcp_lease_get_ntp(link->dhcp_lease, &da); | |
925 | if (n > 0) { | |
926 | ||
927 | if (!GREEDY_REALLOC(addresses, n_allocated, n_addresses + n)) | |
928 | return log_oom(); | |
929 | ||
930 | memcpy(addresses + n_addresses, da, n * sizeof(struct in_addr)); | |
931 | n_addresses += n; | |
932 | } | |
933 | } | |
934 | ||
935 | if (n_addresses <= 0) | |
936 | return 0; | |
937 | ||
938 | return sd_dhcp_server_set_ntp(s, addresses, n_addresses); | |
939 | } | |
940 | ||
f6bb7ac5 TJ |
941 | static int link_set_bridge_fdb(Link *link) { |
942 | FdbEntry *fdb_entry; | |
197e2809 | 943 | int r; |
f6bb7ac5 TJ |
944 | |
945 | LIST_FOREACH(static_fdb_entries, fdb_entry, link->network->static_fdb_entries) { | |
946 | r = fdb_entry_configure(link, fdb_entry); | |
197e2809 | 947 | if (r < 0) |
f6bb7ac5 | 948 | return log_link_error_errno(link, r, "Failed to add MAC entry to static MAC table: %m"); |
f6bb7ac5 TJ |
949 | } |
950 | ||
197e2809 | 951 | return 0; |
f6bb7ac5 TJ |
952 | } |
953 | ||
f882c247 | 954 | static int link_enter_set_addresses(Link *link) { |
a6cc569e | 955 | Address *ad; |
f882c247 TG |
956 | int r; |
957 | ||
958 | assert(link); | |
959 | assert(link->network); | |
f5be5601 | 960 | assert(link->state != _LINK_STATE_INVALID); |
f882c247 | 961 | |
f6bb7ac5 TJ |
962 | r = link_set_bridge_fdb(link); |
963 | if (r < 0) | |
964 | return r; | |
965 | ||
e331e246 | 966 | link_set_state(link, LINK_STATE_SETTING_ADDRESSES); |
f882c247 | 967 | |
3d3d4255 | 968 | LIST_FOREACH(addresses, ad, link->network->static_addresses) { |
483d099e | 969 | r = address_configure(ad, link, address_handler, false); |
dd3efc09 | 970 | if (r < 0) { |
5a8bcb67 | 971 | log_link_warning_errno(link, r, "Could not set addresses: %m"); |
f5be5601 TG |
972 | link_enter_failed(link); |
973 | return r; | |
974 | } | |
975 | ||
313cefa1 | 976 | link->link_messages++; |
f882c247 TG |
977 | } |
978 | ||
d4cdbea5 TG |
979 | /* now that we can figure out a default address for the dhcp server, |
980 | start it */ | |
981 | if (link_dhcp4_server_enabled(link)) { | |
d4cdbea5 | 982 | Address *address; |
4f5f911e LP |
983 | Link *uplink = NULL; |
984 | bool acquired_uplink = false; | |
d4cdbea5 TG |
985 | |
986 | address = link_find_dhcp_server_address(link); | |
987 | if (!address) { | |
6a7a4e4d | 988 | log_link_warning(link, "Failed to find suitable address for DHCPv4 server instance."); |
d4cdbea5 TG |
989 | link_enter_failed(link); |
990 | return 0; | |
991 | } | |
992 | ||
61986155 | 993 | /* use the server address' subnet as the pool */ |
9b3a67c5 TG |
994 | r = sd_dhcp_server_configure_pool(link->dhcp_server, &address->in_addr.in, address->prefixlen, |
995 | link->network->dhcp_server_pool_offset, link->network->dhcp_server_pool_size); | |
d4cdbea5 TG |
996 | if (r < 0) |
997 | return r; | |
998 | ||
999 | /* TODO: | |
1000 | r = sd_dhcp_server_set_router(link->dhcp_server, | |
1001 | &main_address->in_addr.in); | |
1002 | if (r < 0) | |
1003 | return r; | |
d4cdbea5 TG |
1004 | */ |
1005 | ||
586ac6f7 LP |
1006 | if (link->network->dhcp_server_max_lease_time_usec > 0) { |
1007 | r = sd_dhcp_server_set_max_lease_time( | |
1008 | link->dhcp_server, | |
1009 | DIV_ROUND_UP(link->network->dhcp_server_max_lease_time_usec, USEC_PER_SEC)); | |
1010 | if (r < 0) | |
1011 | return r; | |
1012 | } | |
1013 | ||
1014 | if (link->network->dhcp_server_default_lease_time_usec > 0) { | |
1015 | r = sd_dhcp_server_set_default_lease_time( | |
1016 | link->dhcp_server, | |
1017 | DIV_ROUND_UP(link->network->dhcp_server_default_lease_time_usec, USEC_PER_SEC)); | |
1018 | if (r < 0) | |
1019 | return r; | |
1020 | } | |
1021 | ||
1a04db0f LP |
1022 | if (link->network->dhcp_server_emit_dns) { |
1023 | ||
4f5f911e | 1024 | if (link->network->n_dhcp_server_dns > 0) |
1a04db0f | 1025 | r = sd_dhcp_server_set_dns(link->dhcp_server, link->network->dhcp_server_dns, link->network->n_dhcp_server_dns); |
4f5f911e LP |
1026 | else { |
1027 | uplink = manager_find_uplink(link->manager, link); | |
1028 | acquired_uplink = true; | |
1029 | ||
1030 | if (!uplink) { | |
1031 | log_link_debug(link, "Not emitting DNS server information on link, couldn't find suitable uplink."); | |
1032 | r = 0; | |
1033 | } else | |
1034 | r = link_push_dns_to_dhcp_server(uplink, link->dhcp_server); | |
1035 | } | |
1036 | if (r < 0) | |
1037 | log_link_warning_errno(link, r, "Failed to set DNS server for DHCP server, ignoring: %m"); | |
1a04db0f LP |
1038 | } |
1039 | ||
1040 | ||
1041 | if (link->network->dhcp_server_emit_ntp) { | |
1042 | ||
4f5f911e | 1043 | if (link->network->n_dhcp_server_ntp > 0) |
1a04db0f | 1044 | r = sd_dhcp_server_set_ntp(link->dhcp_server, link->network->dhcp_server_ntp, link->network->n_dhcp_server_ntp); |
4f5f911e LP |
1045 | else { |
1046 | if (!acquired_uplink) | |
1047 | uplink = manager_find_uplink(link->manager, link); | |
1048 | ||
1049 | if (!uplink) { | |
1050 | log_link_debug(link, "Not emitting NTP server information on link, couldn't find suitable uplink."); | |
1051 | r = 0; | |
1052 | } else | |
1053 | r = link_push_ntp_to_dhcp_server(uplink, link->dhcp_server); | |
1054 | ||
1055 | } | |
1056 | if (r < 0) | |
1057 | log_link_warning_errno(link, r, "Failed to set NTP server for DHCP server, ignoring: %m"); | |
1a04db0f LP |
1058 | } |
1059 | ||
77ff6022 CG |
1060 | r = sd_dhcp_server_set_emit_router(link->dhcp_server, link->network->dhcp_server_emit_router); |
1061 | if (r < 0) { | |
1062 | log_link_warning_errno(link, r, "Failed to set router emission for DHCP server: %m"); | |
1063 | return r; | |
1064 | } | |
1065 | ||
8eb9058d LP |
1066 | if (link->network->dhcp_server_emit_timezone) { |
1067 | _cleanup_free_ char *buffer = NULL; | |
0ab8a1b6 | 1068 | const char *tz = NULL; |
8eb9058d LP |
1069 | |
1070 | if (link->network->dhcp_server_timezone) | |
1071 | tz = link->network->dhcp_server_timezone; | |
1072 | else { | |
1073 | r = get_timezone(&buffer); | |
1074 | if (r < 0) | |
1075 | log_warning_errno(r, "Failed to determine timezone: %m"); | |
1076 | else | |
1077 | tz = buffer; | |
1078 | } | |
1079 | ||
1080 | if (tz) { | |
1081 | r = sd_dhcp_server_set_timezone(link->dhcp_server, tz); | |
1082 | if (r < 0) | |
1083 | return r; | |
1084 | } | |
1085 | } | |
1086 | ||
d4cdbea5 TG |
1087 | r = sd_dhcp_server_start(link->dhcp_server); |
1088 | if (r < 0) { | |
6a7a4e4d | 1089 | log_link_warning_errno(link, r, "Could not start DHCPv4 server instance: %m"); |
d4cdbea5 TG |
1090 | |
1091 | link_enter_failed(link); | |
1092 | ||
1093 | return 0; | |
1094 | } | |
1095 | ||
6a7a4e4d | 1096 | log_link_debug(link, "Offering DHCPv4 leases"); |
d4cdbea5 TG |
1097 | } |
1098 | ||
6a7a4e4d | 1099 | if (link->link_messages == 0) |
431ca2ce | 1100 | link_enter_set_routes(link); |
6a7a4e4d LP |
1101 | else |
1102 | log_link_debug(link, "Setting addresses"); | |
431ca2ce | 1103 | |
f882c247 TG |
1104 | return 0; |
1105 | } | |
1106 | ||
91b5f997 | 1107 | int link_address_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) { |
5da8149f | 1108 | _cleanup_link_unref_ Link *link = userdata; |
ff254138 TG |
1109 | int r; |
1110 | ||
1111 | assert(m); | |
1112 | assert(link); | |
1113 | assert(link->ifname); | |
1114 | ||
5da8149f | 1115 | if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) |
ff254138 TG |
1116 | return 1; |
1117 | ||
1c4baffc | 1118 | r = sd_netlink_message_get_errno(m); |
b90b025a | 1119 | if (r < 0 && r != -EADDRNOTAVAIL) |
a2fae7bb | 1120 | log_link_warning_errno(link, r, "Could not drop address: %m"); |
ff254138 | 1121 | |
5bdd314c | 1122 | return 1; |
ff254138 TG |
1123 | } |
1124 | ||
13b498f9 TJ |
1125 | static int link_set_bridge_vlan(Link *link) { |
1126 | int r = 0; | |
1127 | ||
1128 | r = br_vlan_configure(link, link->network->pvid, link->network->br_vid_bitmap, link->network->br_untagged_bitmap); | |
1129 | if (r < 0) | |
1130 | log_link_error_errno(link, r, "Failed to assign VLANs to bridge port: %m"); | |
1131 | ||
1132 | return r; | |
1133 | } | |
1134 | ||
a60a720c | 1135 | static int link_set_proxy_arp(Link *link) { |
23d8b221 SS |
1136 | const char *p = NULL; |
1137 | int r; | |
1138 | ||
1139 | if (!link_proxy_arp_enabled(link)) | |
1140 | return 0; | |
1141 | ||
1142 | p = strjoina("/proc/sys/net/ipv4/conf/", link->ifname, "/proxy_arp"); | |
1143 | ||
1144 | r = write_string_file(p, one_zero(link->network->proxy_arp), WRITE_STRING_FILE_VERIFY_ON_FAILURE); | |
1145 | if (r < 0) | |
1146 | log_link_warning_errno(link, r, "Cannot configure proxy ARP for interface: %m"); | |
1147 | ||
1148 | return 0; | |
1149 | } | |
1150 | ||
1c4baffc | 1151 | static int link_set_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) { |
e1853b00 SS |
1152 | _cleanup_link_unref_ Link *link = userdata; |
1153 | int r; | |
1154 | ||
6a7a4e4d | 1155 | log_link_debug(link, "Set link"); |
e1853b00 | 1156 | |
1c4baffc | 1157 | r = sd_netlink_message_get_errno(m); |
e1853b00 | 1158 | if (r < 0 && r != -EEXIST) { |
f2341e0a | 1159 | log_link_error_errno(link, r, "Could not join netdev: %m"); |
e1853b00 SS |
1160 | link_enter_failed(link); |
1161 | return 1; | |
1162 | } | |
1163 | ||
1164 | return 0; | |
1165 | } | |
1166 | ||
19070062 | 1167 | static int set_hostname_handler(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { |
5da8149f | 1168 | _cleanup_link_unref_ Link *link = userdata; |
21b80ad1 | 1169 | const sd_bus_error *e; |
1346b1f0 | 1170 | |
19070062 | 1171 | assert(m); |
b226d99b TG |
1172 | assert(link); |
1173 | ||
5da8149f | 1174 | if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) |
370e9930 | 1175 | return 1; |
370e9930 | 1176 | |
21b80ad1 LP |
1177 | e = sd_bus_message_get_error(m); |
1178 | if (e) | |
1179 | log_link_warning_errno(link, sd_bus_error_get_errno(e), "Could not set hostname: %s", e->message); | |
1346b1f0 TG |
1180 | |
1181 | return 1; | |
1182 | } | |
1183 | ||
3c9b8860 | 1184 | int link_set_hostname(Link *link, const char *hostname) { |
21b80ad1 | 1185 | int r; |
1346b1f0 | 1186 | |
b226d99b TG |
1187 | assert(link); |
1188 | assert(link->manager); | |
1346b1f0 | 1189 | |
dce391e7 | 1190 | log_link_debug(link, "Setting transient hostname: '%s'", strna(hostname)); |
1346b1f0 | 1191 | |
3c9b8860 TG |
1192 | if (!link->manager->bus) { |
1193 | /* TODO: replace by assert when we can rely on kdbus */ | |
6a7a4e4d | 1194 | log_link_info(link, "Not connected to system bus, ignoring transient hostname."); |
bcbca829 TG |
1195 | return 0; |
1196 | } | |
1197 | ||
9c34154a | 1198 | r = sd_bus_call_method_async( |
b226d99b | 1199 | link->manager->bus, |
9c34154a | 1200 | NULL, |
1346b1f0 TG |
1201 | "org.freedesktop.hostname1", |
1202 | "/org/freedesktop/hostname1", | |
1203 | "org.freedesktop.hostname1", | |
9c34154a UTL |
1204 | "SetHostname", |
1205 | set_hostname_handler, | |
1206 | link, | |
1207 | "sb", | |
1208 | hostname, | |
1209 | false); | |
1346b1f0 | 1210 | |
6a7a4e4d LP |
1211 | if (r < 0) |
1212 | return log_link_error_errno(link, r, "Could not set transient hostname: %m"); | |
b226d99b TG |
1213 | |
1214 | link_ref(link); | |
1346b1f0 | 1215 | |
5da8149f | 1216 | return 0; |
1346b1f0 TG |
1217 | } |
1218 | ||
21b80ad1 LP |
1219 | static int set_timezone_handler(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { |
1220 | _cleanup_link_unref_ Link *link = userdata; | |
1221 | const sd_bus_error *e; | |
1222 | ||
1223 | assert(m); | |
1224 | assert(link); | |
1225 | ||
1226 | if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) | |
1227 | return 1; | |
1228 | ||
1229 | e = sd_bus_message_get_error(m); | |
1230 | if (e) | |
1231 | log_link_warning_errno(link, sd_bus_error_get_errno(e), "Could not set timezone: %s", e->message); | |
1232 | ||
1233 | return 1; | |
1234 | } | |
1235 | ||
64d6c229 | 1236 | int link_set_timezone(Link *link, const char *tz) { |
21b80ad1 LP |
1237 | int r; |
1238 | ||
1239 | assert(link); | |
1240 | assert(link->manager); | |
64d6c229 | 1241 | assert(tz); |
21b80ad1 | 1242 | |
64d6c229 | 1243 | log_link_debug(link, "Setting system timezone: '%s'", tz); |
21b80ad1 LP |
1244 | |
1245 | if (!link->manager->bus) { | |
1246 | log_link_info(link, "Not connected to system bus, ignoring timezone."); | |
1247 | return 0; | |
1248 | } | |
1249 | ||
1250 | r = sd_bus_call_method_async( | |
1251 | link->manager->bus, | |
1252 | NULL, | |
1253 | "org.freedesktop.timedate1", | |
1254 | "/org/freedesktop/timedate1", | |
1255 | "org.freedesktop.timedate1", | |
1256 | "SetTimezone", | |
1257 | set_timezone_handler, | |
1258 | link, | |
1259 | "sb", | |
64d6c229 | 1260 | tz, |
21b80ad1 LP |
1261 | false); |
1262 | if (r < 0) | |
1263 | return log_link_error_errno(link, r, "Could not set timezone: %m"); | |
1264 | ||
1265 | link_ref(link); | |
1266 | ||
1267 | return 0; | |
1268 | } | |
1269 | ||
1c4baffc | 1270 | static int set_mtu_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) { |
5da8149f | 1271 | _cleanup_link_unref_ Link *link = userdata; |
4f882b2a TG |
1272 | int r; |
1273 | ||
1274 | assert(m); | |
1275 | assert(link); | |
1276 | assert(link->ifname); | |
1277 | ||
5da8149f | 1278 | if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) |
4f882b2a TG |
1279 | return 1; |
1280 | ||
1c4baffc | 1281 | r = sd_netlink_message_get_errno(m); |
c9ccc19f | 1282 | if (r < 0) |
a2fae7bb | 1283 | log_link_warning_errno(link, r, "Could not set MTU: %m"); |
4f882b2a TG |
1284 | |
1285 | return 1; | |
1286 | } | |
1287 | ||
3c9b8860 | 1288 | int link_set_mtu(Link *link, uint32_t mtu) { |
4afd3348 | 1289 | _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL; |
4f882b2a TG |
1290 | int r; |
1291 | ||
1292 | assert(link); | |
1293 | assert(link->manager); | |
1294 | assert(link->manager->rtnl); | |
1295 | ||
6a7a4e4d | 1296 | log_link_debug(link, "Setting MTU: %" PRIu32, mtu); |
4f882b2a | 1297 | |
6a7a4e4d LP |
1298 | r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_SETLINK, link->ifindex); |
1299 | if (r < 0) | |
1300 | return log_link_error_errno(link, r, "Could not allocate RTM_SETLINK message: %m"); | |
4f882b2a | 1301 | |
1c4baffc | 1302 | r = sd_netlink_message_append_u32(req, IFLA_MTU, mtu); |
6a7a4e4d LP |
1303 | if (r < 0) |
1304 | return log_link_error_errno(link, r, "Could not append MTU: %m"); | |
4f882b2a | 1305 | |
1c4baffc | 1306 | r = sd_netlink_call_async(link->manager->rtnl, req, set_mtu_handler, link, 0, NULL); |
6a7a4e4d LP |
1307 | if (r < 0) |
1308 | return log_link_error_errno(link, r, "Could not send rtnetlink message: %m"); | |
4f882b2a | 1309 | |
ae941762 | 1310 | link_ref(link); |
b226d99b | 1311 | |
4f882b2a TG |
1312 | return 0; |
1313 | } | |
1314 | ||
99d2baa2 SS |
1315 | static int set_flags_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) { |
1316 | _cleanup_link_unref_ Link *link = userdata; | |
1317 | int r; | |
1318 | ||
1319 | assert(m); | |
1320 | assert(link); | |
1321 | assert(link->ifname); | |
1322 | ||
1323 | if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) | |
1324 | return 1; | |
1325 | ||
1326 | r = sd_netlink_message_get_errno(m); | |
1327 | if (r < 0) | |
1328 | log_link_warning_errno(link, r, "Could not set link flags: %m"); | |
1329 | ||
1330 | return 1; | |
1331 | } | |
1332 | ||
1333 | static int link_set_flags(Link *link) { | |
1334 | _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL; | |
1335 | unsigned ifi_change = 0; | |
1336 | unsigned ifi_flags = 0; | |
1337 | int r; | |
1338 | ||
1339 | assert(link); | |
1340 | assert(link->manager); | |
1341 | assert(link->manager->rtnl); | |
1342 | ||
1343 | if (link->flags & IFF_LOOPBACK) | |
1344 | return 0; | |
1345 | ||
1346 | if (!link->network) | |
1347 | return 0; | |
1348 | ||
1349 | if (link->network->arp < 0) | |
1350 | return 0; | |
1351 | ||
1352 | r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_SETLINK, link->ifindex); | |
1353 | if (r < 0) | |
1354 | return log_link_error_errno(link, r, "Could not allocate RTM_SETLINK message: %m"); | |
1355 | ||
1356 | if (link->network->arp >= 0) { | |
1357 | ifi_change |= IFF_NOARP; | |
1ed1f50f | 1358 | ifi_flags |= link->network->arp ? 0 : IFF_NOARP; |
99d2baa2 SS |
1359 | } |
1360 | ||
1361 | r = sd_rtnl_message_link_set_flags(req, ifi_flags, ifi_change); | |
1362 | if (r < 0) | |
1363 | return log_link_error_errno(link, r, "Could not set link flags: %m"); | |
1364 | ||
1365 | r = sd_netlink_call_async(link->manager->rtnl, req, set_flags_handler, link, 0, NULL); | |
1366 | if (r < 0) | |
1367 | return log_link_error_errno(link, r, "Could not send rtnetlink message: %m"); | |
1368 | ||
1369 | link_ref(link); | |
1370 | ||
1371 | return 0; | |
1372 | } | |
1373 | ||
e1853b00 | 1374 | static int link_set_bridge(Link *link) { |
4afd3348 | 1375 | _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL; |
e1853b00 SS |
1376 | int r; |
1377 | ||
1378 | assert(link); | |
1379 | assert(link->network); | |
1380 | ||
6a7a4e4d LP |
1381 | r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_SETLINK, link->ifindex); |
1382 | if (r < 0) | |
1383 | return log_link_error_errno(link, r, "Could not allocate RTM_SETLINK message: %m"); | |
e1853b00 SS |
1384 | |
1385 | r = sd_rtnl_message_link_set_family(req, PF_BRIDGE); | |
6a7a4e4d LP |
1386 | if (r < 0) |
1387 | return log_link_error_errno(link, r, "Could not set message family: %m"); | |
e1853b00 | 1388 | |
1c4baffc | 1389 | r = sd_netlink_message_open_container(req, IFLA_PROTINFO); |
6a7a4e4d LP |
1390 | if (r < 0) |
1391 | return log_link_error_errno(link, r, "Could not append IFLA_PROTINFO attribute: %m"); | |
e1853b00 | 1392 | |
84c34096 | 1393 | r = sd_netlink_message_append_u8(req, IFLA_BRPORT_GUARD, !link->network->use_bpdu); |
eb7ff4dd SS |
1394 | if (r < 0) |
1395 | return log_link_error_errno(link, r, "Could not append IFLA_BRPORT_GUARD attribute: %m"); | |
1396 | ||
1397 | r = sd_netlink_message_append_u8(req, IFLA_BRPORT_MODE, link->network->hairpin); | |
1398 | if (r < 0) | |
1399 | return log_link_error_errno(link, r, "Could not append IFLA_BRPORT_MODE attribute: %m"); | |
1400 | ||
1401 | r = sd_netlink_message_append_u8(req, IFLA_BRPORT_FAST_LEAVE, link->network->fast_leave); | |
1402 | if (r < 0) | |
1403 | return log_link_error_errno(link, r, "Could not append IFLA_BRPORT_FAST_LEAVE attribute: %m"); | |
1404 | ||
23da66bb | 1405 | r = sd_netlink_message_append_u8(req, IFLA_BRPORT_PROTECT, !link->network->allow_port_to_be_root); |
eb7ff4dd SS |
1406 | if (r < 0) |
1407 | return log_link_error_errno(link, r, "Could not append IFLA_BRPORT_PROTECT attribute: %m"); | |
1408 | ||
1409 | r = sd_netlink_message_append_u8(req, IFLA_BRPORT_UNICAST_FLOOD, link->network->unicast_flood); | |
1410 | if (r < 0) | |
1411 | return log_link_error_errno(link, r, "Could not append IFLA_BRPORT_UNICAST_FLOOD attribute: %m"); | |
1412 | ||
34437b4f | 1413 | if (link->network->cost != 0) { |
1c4baffc | 1414 | r = sd_netlink_message_append_u32(req, IFLA_BRPORT_COST, link->network->cost); |
6a7a4e4d LP |
1415 | if (r < 0) |
1416 | return log_link_error_errno(link, r, "Could not append IFLA_BRPORT_COST attribute: %m"); | |
e1853b00 SS |
1417 | } |
1418 | ||
1c4baffc | 1419 | r = sd_netlink_message_close_container(req); |
6a7a4e4d LP |
1420 | if (r < 0) |
1421 | return log_link_error_errno(link, r, "Could not append IFLA_LINKINFO attribute: %m"); | |
e1853b00 | 1422 | |
1c4baffc | 1423 | r = sd_netlink_call_async(link->manager->rtnl, req, link_set_handler, link, 0, NULL); |
6a7a4e4d LP |
1424 | if (r < 0) |
1425 | return log_link_error_errno(link, r, "Could not send rtnetlink message: %m"); | |
e1853b00 SS |
1426 | |
1427 | link_ref(link); | |
1428 | ||
1429 | return r; | |
1430 | } | |
1431 | ||
34437b4f LP |
1432 | static int link_lldp_save(Link *link) { |
1433 | _cleanup_free_ char *temp_path = NULL; | |
1434 | _cleanup_fclose_ FILE *f = NULL; | |
1435 | sd_lldp_neighbor **l = NULL; | |
1436 | int n = 0, r, i; | |
49699bac SS |
1437 | |
1438 | assert(link); | |
34437b4f LP |
1439 | assert(link->lldp_file); |
1440 | ||
1441 | if (!link->lldp) { | |
1442 | (void) unlink(link->lldp_file); | |
1443 | return 0; | |
1444 | } | |
1445 | ||
1446 | r = sd_lldp_get_neighbors(link->lldp, &l); | |
1447 | if (r < 0) | |
1448 | goto finish; | |
1449 | if (r == 0) { | |
1450 | (void) unlink(link->lldp_file); | |
1451 | goto finish; | |
1452 | } | |
1453 | ||
1454 | n = r; | |
1455 | ||
1456 | r = fopen_temporary(link->lldp_file, &f, &temp_path); | |
1457 | if (r < 0) | |
1458 | goto finish; | |
1459 | ||
1460 | fchmod(fileno(f), 0644); | |
49699bac | 1461 | |
34437b4f LP |
1462 | for (i = 0; i < n; i++) { |
1463 | const void *p; | |
1464 | le64_t u; | |
1465 | size_t sz; | |
1466 | ||
1467 | r = sd_lldp_neighbor_get_raw(l[i], &p, &sz); | |
9ef61f2e | 1468 | if (r < 0) |
34437b4f LP |
1469 | goto finish; |
1470 | ||
1471 | u = htole64(sz); | |
1472 | (void) fwrite(&u, 1, sizeof(u), f); | |
1473 | (void) fwrite(p, 1, sz, f); | |
1474 | } | |
49699bac | 1475 | |
34437b4f LP |
1476 | r = fflush_and_check(f); |
1477 | if (r < 0) | |
1478 | goto finish; | |
1479 | ||
1480 | if (rename(temp_path, link->lldp_file) < 0) { | |
1481 | r = -errno; | |
1482 | goto finish; | |
9ef61f2e | 1483 | } |
34437b4f LP |
1484 | |
1485 | finish: | |
1486 | if (r < 0) { | |
1487 | (void) unlink(link->lldp_file); | |
1488 | if (temp_path) | |
1489 | (void) unlink(temp_path); | |
1490 | ||
1491 | log_link_error_errno(link, r, "Failed to save LLDP data to %s: %m", link->lldp_file); | |
1492 | } | |
1493 | ||
1494 | if (l) { | |
1495 | for (i = 0; i < n; i++) | |
1496 | sd_lldp_neighbor_unref(l[i]); | |
1497 | free(l); | |
1498 | } | |
1499 | ||
1500 | return r; | |
1501 | } | |
1502 | ||
90dffb22 | 1503 | static void lldp_handler(sd_lldp *lldp, sd_lldp_event event, sd_lldp_neighbor *n, void *userdata) { |
34437b4f | 1504 | Link *link = userdata; |
90dffb22 | 1505 | int r; |
34437b4f LP |
1506 | |
1507 | assert(link); | |
1508 | ||
1509 | (void) link_lldp_save(link); | |
90dffb22 | 1510 | |
7272b25e | 1511 | if (link_lldp_emit_enabled(link) && event == SD_LLDP_EVENT_ADDED) { |
90dffb22 LP |
1512 | /* If we received information about a new neighbor, restart the LLDP "fast" logic */ |
1513 | ||
1514 | log_link_debug(link, "Received LLDP datagram from previously unknown neighbor, restarting 'fast' LLDP transmission."); | |
1515 | ||
7272b25e | 1516 | r = link_lldp_emit_start(link); |
90dffb22 LP |
1517 | if (r < 0) |
1518 | log_link_warning_errno(link, r, "Failed to restart LLDP transmission: %m"); | |
1519 | } | |
49699bac SS |
1520 | } |
1521 | ||
e7ab854c TG |
1522 | static int link_acquire_ipv6_conf(Link *link) { |
1523 | int r; | |
1524 | ||
1525 | assert(link); | |
1526 | ||
1527 | if (link_dhcp6_enabled(link)) { | |
1528 | assert(link->dhcp6_client); | |
c601ebf7 | 1529 | assert(in_addr_is_link_local(AF_INET6, (const union in_addr_union*)&link->ipv6ll_address) > 0); |
e7ab854c | 1530 | |
720bec40 TY |
1531 | /* start DHCPv6 client in stateless mode */ |
1532 | r = dhcp6_request_address(link, true); | |
63348d13 | 1533 | if (r < 0 && r != -EBUSY) |
e7ab854c | 1534 | return log_link_warning_errno(link, r, "Could not acquire DHCPv6 lease: %m"); |
720bec40 TY |
1535 | else |
1536 | log_link_debug(link, "Acquiring DHCPv6 lease"); | |
e7ab854c TG |
1537 | } |
1538 | ||
1539 | if (link_ipv6_accept_ra_enabled(link)) { | |
1e7a0e21 | 1540 | assert(link->ndisc); |
e7ab854c TG |
1541 | |
1542 | log_link_debug(link, "Discovering IPv6 routers"); | |
1543 | ||
1e7a0e21 | 1544 | r = sd_ndisc_start(link->ndisc); |
63348d13 | 1545 | if (r < 0 && r != -EBUSY) |
e7ab854c TG |
1546 | return log_link_warning_errno(link, r, "Could not start IPv6 Router Discovery: %m"); |
1547 | } | |
1548 | ||
1549 | return 0; | |
1550 | } | |
1551 | ||
6fc25497 | 1552 | static int link_acquire_ipv4_conf(Link *link) { |
ff254138 TG |
1553 | int r; |
1554 | ||
1555 | assert(link); | |
1556 | assert(link->network); | |
ff254138 TG |
1557 | assert(link->manager); |
1558 | assert(link->manager->event); | |
1559 | ||
78c958f8 | 1560 | if (link_ipv4ll_enabled(link)) { |
eb34d4af | 1561 | assert(link->ipv4ll); |
ff254138 | 1562 | |
6a7a4e4d | 1563 | log_link_debug(link, "Acquiring IPv4 link-local address"); |
5c1d3fc9 UTL |
1564 | |
1565 | r = sd_ipv4ll_start(link->ipv4ll); | |
6a7a4e4d LP |
1566 | if (r < 0) |
1567 | return log_link_warning_errno(link, r, "Could not acquire IPv4 link-local address: %m"); | |
5c1d3fc9 UTL |
1568 | } |
1569 | ||
78c958f8 | 1570 | if (link_dhcp4_enabled(link)) { |
eb34d4af | 1571 | assert(link->dhcp_client); |
ff254138 | 1572 | |
6a7a4e4d | 1573 | log_link_debug(link, "Acquiring DHCPv4 lease"); |
ab47d620 | 1574 | |
5c1d3fc9 | 1575 | r = sd_dhcp_client_start(link->dhcp_client); |
6a7a4e4d LP |
1576 | if (r < 0) |
1577 | return log_link_warning_errno(link, r, "Could not acquire DHCPv4 lease: %m"); | |
5c1d3fc9 | 1578 | } |
ff254138 | 1579 | |
6fc25497 SS |
1580 | return 0; |
1581 | } | |
1582 | ||
1583 | static int link_acquire_conf(Link *link) { | |
1584 | int r; | |
1585 | ||
1586 | assert(link); | |
1587 | ||
1588 | r = link_acquire_ipv4_conf(link); | |
1589 | if (r < 0) | |
1590 | return r; | |
1591 | ||
1592 | if (in_addr_is_null(AF_INET6, (const union in_addr_union*) &link->ipv6ll_address) == 0) { | |
1593 | r = link_acquire_ipv6_conf(link); | |
1594 | if (r < 0) | |
1595 | return r; | |
1596 | } | |
1597 | ||
7272b25e LP |
1598 | if (link_lldp_emit_enabled(link)) { |
1599 | r = link_lldp_emit_start(link); | |
8e1ad1ea LP |
1600 | if (r < 0) |
1601 | return log_link_warning_errno(link, r, "Failed to start LLDP transmission: %m"); | |
1602 | } | |
1603 | ||
ff254138 TG |
1604 | return 0; |
1605 | } | |
1606 | ||
a61bb41c | 1607 | bool link_has_carrier(Link *link) { |
deb2e523 TG |
1608 | /* see Documentation/networking/operstates.txt in the kernel sources */ |
1609 | ||
a61bb41c | 1610 | if (link->kernel_operstate == IF_OPER_UP) |
deb2e523 TG |
1611 | return true; |
1612 | ||
a61bb41c | 1613 | if (link->kernel_operstate == IF_OPER_UNKNOWN) |
deb2e523 | 1614 | /* operstate may not be implemented, so fall back to flags */ |
a61bb41c | 1615 | if ((link->flags & IFF_LOWER_UP) && !(link->flags & IFF_DORMANT)) |
deb2e523 TG |
1616 | return true; |
1617 | ||
1618 | return false; | |
1619 | } | |
1620 | ||
1c4baffc | 1621 | static int link_up_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) { |
5da8149f | 1622 | _cleanup_link_unref_ Link *link = userdata; |
dd3efc09 TG |
1623 | int r; |
1624 | ||
1746cf2a TG |
1625 | assert(link); |
1626 | ||
5da8149f | 1627 | if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) |
1746cf2a TG |
1628 | return 1; |
1629 | ||
1c4baffc | 1630 | r = sd_netlink_message_get_errno(m); |
6a7a4e4d LP |
1631 | if (r < 0) |
1632 | /* we warn but don't fail the link, as it may be | |
1633 | brought up later */ | |
a2fae7bb | 1634 | log_link_warning_errno(link, r, "Could not bring up interface: %m"); |
45ad2c13 | 1635 | |
f882c247 TG |
1636 | return 1; |
1637 | } | |
1638 | ||
1639 | static int link_up(Link *link) { | |
4afd3348 | 1640 | _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL; |
5c3072ea | 1641 | uint8_t ipv6ll_mode; |
f579559b TG |
1642 | int r; |
1643 | ||
f882c247 | 1644 | assert(link); |
c106cc36 | 1645 | assert(link->network); |
f882c247 TG |
1646 | assert(link->manager); |
1647 | assert(link->manager->rtnl); | |
1648 | ||
6a7a4e4d | 1649 | log_link_debug(link, "Bringing link up"); |
449f7554 | 1650 | |
6a7a4e4d LP |
1651 | r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_SETLINK, link->ifindex); |
1652 | if (r < 0) | |
1653 | return log_link_error_errno(link, r, "Could not allocate RTM_SETLINK message: %m"); | |
f579559b | 1654 | |
2b2d8603 | 1655 | /* set it free if not enslaved with networkd */ |
6cb955c6 | 1656 | if (!link->network->bridge && !link->network->bond && !link->network->vrf) { |
2b2d8603 TY |
1657 | r = sd_netlink_message_append_u32(req, IFLA_MASTER, 0); |
1658 | if (r < 0) | |
1659 | return log_link_error_errno(link, r, "Could not append IFLA_MASTER attribute: %m"); | |
1660 | } | |
1661 | ||
5d4795f3 | 1662 | r = sd_rtnl_message_link_set_flags(req, IFF_UP, IFF_UP); |
6a7a4e4d LP |
1663 | if (r < 0) |
1664 | return log_link_error_errno(link, r, "Could not set link flags: %m"); | |
fc25d7f8 | 1665 | |
c106cc36 | 1666 | if (link->network->mac) { |
1c4baffc | 1667 | r = sd_netlink_message_append_ether_addr(req, IFLA_ADDRESS, link->network->mac); |
6a7a4e4d LP |
1668 | if (r < 0) |
1669 | return log_link_error_errno(link, r, "Could not set MAC address: %m"); | |
c106cc36 TG |
1670 | } |
1671 | ||
4cef7fe3 | 1672 | /* If IPv6 not configured (no static IPv6 address and IPv6LL autoconfiguration is disabled) |
2b00a4e0 | 1673 | for this interface, or if it is a bridge slave, then disable IPv6 else enable it. */ |
439689c6 SS |
1674 | (void) link_enable_ipv6(link); |
1675 | ||
c106cc36 | 1676 | if (link->network->mtu) { |
439689c6 SS |
1677 | /* IPv6 protocol requires a minimum MTU of IPV6_MTU_MIN(1280) bytes |
1678 | on the interface. Bump up MTU bytes to IPV6_MTU_MIN. */ | |
1679 | if (link_ipv6_enabled(link) && link->network->mtu < IPV6_MIN_MTU) { | |
1680 | ||
1681 | log_link_warning(link, "Bumping MTU to " STRINGIFY(IPV6_MIN_MTU) ", as " | |
1682 | "IPv6 is requested and requires a minimum MTU of " STRINGIFY(IPV6_MIN_MTU) " bytes: %m"); | |
1683 | ||
1684 | link->network->mtu = IPV6_MIN_MTU; | |
1685 | } | |
1686 | ||
1c4baffc | 1687 | r = sd_netlink_message_append_u32(req, IFLA_MTU, link->network->mtu); |
6a7a4e4d LP |
1688 | if (r < 0) |
1689 | return log_link_error_errno(link, r, "Could not set MTU: %m"); | |
c106cc36 TG |
1690 | } |
1691 | ||
1c4baffc | 1692 | r = sd_netlink_message_open_container(req, IFLA_AF_SPEC); |
6a7a4e4d LP |
1693 | if (r < 0) |
1694 | return log_link_error_errno(link, r, "Could not open IFLA_AF_SPEC container: %m"); | |
d0d6a4cd | 1695 | |
439689c6 | 1696 | if (link_ipv6_enabled(link)) { |
01d28f81 | 1697 | /* if the kernel lacks ipv6 support setting IFF_UP fails if any ipv6 options are passed */ |
1c4baffc | 1698 | r = sd_netlink_message_open_container(req, AF_INET6); |
01d28f81 TG |
1699 | if (r < 0) |
1700 | return log_link_error_errno(link, r, "Could not open AF_INET6 container: %m"); | |
d0d6a4cd | 1701 | |
fbc38f23 TY |
1702 | if (!link_ipv6ll_enabled(link)) |
1703 | ipv6ll_mode = IN6_ADDR_GEN_MODE_NONE; | |
1704 | else { | |
1705 | const char *p = NULL; | |
1706 | _cleanup_free_ char *stable_secret = NULL; | |
1707 | ||
1708 | p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/stable_secret"); | |
1709 | r = read_one_line_file(p, &stable_secret); | |
1710 | ||
1711 | if (r < 0) | |
1712 | ipv6ll_mode = IN6_ADDR_GEN_MODE_EUI64; | |
1713 | else | |
1714 | ipv6ll_mode = IN6_ADDR_GEN_MODE_STABLE_PRIVACY; | |
1715 | } | |
1c4baffc | 1716 | r = sd_netlink_message_append_u8(req, IFLA_INET6_ADDR_GEN_MODE, ipv6ll_mode); |
01d28f81 TG |
1717 | if (r < 0) |
1718 | return log_link_error_errno(link, r, "Could not append IFLA_INET6_ADDR_GEN_MODE: %m"); | |
d0d6a4cd | 1719 | |
01d28f81 | 1720 | if (!in_addr_is_null(AF_INET6, &link->network->ipv6_token)) { |
1c4baffc | 1721 | r = sd_netlink_message_append_in6_addr(req, IFLA_INET6_TOKEN, &link->network->ipv6_token.in6); |
01d28f81 TG |
1722 | if (r < 0) |
1723 | return log_link_error_errno(link, r, "Could not append IFLA_INET6_TOKEN: %m"); | |
1724 | } | |
1725 | ||
1c4baffc | 1726 | r = sd_netlink_message_close_container(req); |
6a7a4e4d | 1727 | if (r < 0) |
01d28f81 | 1728 | return log_link_error_errno(link, r, "Could not close AF_INET6 container: %m"); |
7f77697a | 1729 | } |
d0d6a4cd | 1730 | |
1c4baffc | 1731 | r = sd_netlink_message_close_container(req); |
6a7a4e4d LP |
1732 | if (r < 0) |
1733 | return log_link_error_errno(link, r, "Could not close IFLA_AF_SPEC container: %m"); | |
d0d6a4cd | 1734 | |
1c4baffc | 1735 | r = sd_netlink_call_async(link->manager->rtnl, req, link_up_handler, link, 0, NULL); |
6a7a4e4d LP |
1736 | if (r < 0) |
1737 | return log_link_error_errno(link, r, "Could not send rtnetlink message: %m"); | |
f579559b | 1738 | |
b226d99b TG |
1739 | link_ref(link); |
1740 | ||
f882c247 TG |
1741 | return 0; |
1742 | } | |
1743 | ||
1c4baffc | 1744 | static int link_down_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) { |
0d4ad91d AR |
1745 | _cleanup_link_unref_ Link *link = userdata; |
1746 | int r; | |
1747 | ||
1748 | assert(link); | |
1749 | ||
1750 | if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) | |
1751 | return 1; | |
1752 | ||
1c4baffc | 1753 | r = sd_netlink_message_get_errno(m); |
0d4ad91d | 1754 | if (r < 0) |
a2fae7bb | 1755 | log_link_warning_errno(link, r, "Could not bring down interface: %m"); |
0d4ad91d AR |
1756 | |
1757 | return 1; | |
1758 | } | |
1759 | ||
1760 | static int link_down(Link *link) { | |
4afd3348 | 1761 | _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL; |
0d4ad91d AR |
1762 | int r; |
1763 | ||
1764 | assert(link); | |
1765 | assert(link->manager); | |
1766 | assert(link->manager->rtnl); | |
1767 | ||
6a7a4e4d | 1768 | log_link_debug(link, "Bringing link down"); |
0d4ad91d AR |
1769 | |
1770 | r = sd_rtnl_message_new_link(link->manager->rtnl, &req, | |
1771 | RTM_SETLINK, link->ifindex); | |
6a7a4e4d LP |
1772 | if (r < 0) |
1773 | return log_link_error_errno(link, r, "Could not allocate RTM_SETLINK message: %m"); | |
0d4ad91d AR |
1774 | |
1775 | r = sd_rtnl_message_link_set_flags(req, 0, IFF_UP); | |
6a7a4e4d LP |
1776 | if (r < 0) |
1777 | return log_link_error_errno(link, r, "Could not set link flags: %m"); | |
0d4ad91d | 1778 | |
1c4baffc | 1779 | r = sd_netlink_call_async(link->manager->rtnl, req, link_down_handler, link, 0, NULL); |
6a7a4e4d LP |
1780 | if (r < 0) |
1781 | return log_link_error_errno(link, r, "Could not send rtnetlink message: %m"); | |
0d4ad91d AR |
1782 | |
1783 | link_ref(link); | |
1784 | ||
1785 | return 0; | |
1786 | } | |
1787 | ||
92c918b0 SS |
1788 | static int link_up_can(Link *link) { |
1789 | _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL; | |
1790 | int r; | |
1791 | ||
1792 | assert(link); | |
1793 | ||
1794 | log_link_debug(link, "Bringing CAN link up"); | |
1795 | ||
1796 | r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_SETLINK, link->ifindex); | |
1797 | if (r < 0) | |
1798 | return log_link_error_errno(link, r, "Could not allocate RTM_SETLINK message: %m"); | |
1799 | ||
1800 | r = sd_rtnl_message_link_set_flags(req, IFF_UP, IFF_UP); | |
1801 | if (r < 0) | |
1802 | return log_link_error_errno(link, r, "Could not set link flags: %m"); | |
1803 | ||
1804 | r = sd_netlink_call_async(link->manager->rtnl, req, link_up_handler, link, 0, NULL); | |
1805 | if (r < 0) | |
1806 | return log_link_error_errno(link, r, "Could not send rtnetlink message: %m"); | |
1807 | ||
1808 | link_ref(link); | |
1809 | ||
1810 | return 0; | |
1811 | } | |
1812 | ||
0d4ad91d AR |
1813 | static int link_handle_bound_to_list(Link *link) { |
1814 | Link *l; | |
1815 | Iterator i; | |
1816 | int r; | |
1817 | bool required_up = false; | |
1818 | bool link_is_up = false; | |
1819 | ||
1820 | assert(link); | |
1821 | ||
1822 | if (hashmap_isempty(link->bound_to_links)) | |
1823 | return 0; | |
1824 | ||
1825 | if (link->flags & IFF_UP) | |
1826 | link_is_up = true; | |
1827 | ||
1828 | HASHMAP_FOREACH (l, link->bound_to_links, i) | |
1829 | if (link_has_carrier(l)) { | |
1830 | required_up = true; | |
1831 | break; | |
1832 | } | |
1833 | ||
1834 | if (!required_up && link_is_up) { | |
1835 | r = link_down(link); | |
1836 | if (r < 0) | |
1837 | return r; | |
1838 | } else if (required_up && !link_is_up) { | |
1839 | r = link_up(link); | |
1840 | if (r < 0) | |
1841 | return r; | |
1842 | } | |
1843 | ||
1844 | return 0; | |
1845 | } | |
1846 | ||
1847 | static int link_handle_bound_by_list(Link *link) { | |
1848 | Iterator i; | |
1849 | Link *l; | |
1850 | int r; | |
1851 | ||
1852 | assert(link); | |
1853 | ||
1854 | if (hashmap_isempty(link->bound_by_links)) | |
1855 | return 0; | |
1856 | ||
1857 | HASHMAP_FOREACH (l, link->bound_by_links, i) { | |
1858 | r = link_handle_bound_to_list(l); | |
1859 | if (r < 0) | |
1860 | return r; | |
1861 | } | |
1862 | ||
1863 | return 0; | |
1864 | } | |
1865 | ||
1866 | static int link_put_carrier(Link *link, Link *carrier, Hashmap **h) { | |
1867 | int r; | |
1868 | ||
1869 | assert(link); | |
1870 | assert(carrier); | |
1871 | ||
1872 | if (link == carrier) | |
1873 | return 0; | |
1874 | ||
1875 | if (hashmap_get(*h, INT_TO_PTR(carrier->ifindex))) | |
1876 | return 0; | |
1877 | ||
1878 | r = hashmap_ensure_allocated(h, NULL); | |
1879 | if (r < 0) | |
1880 | return r; | |
1881 | ||
1882 | r = hashmap_put(*h, INT_TO_PTR(carrier->ifindex), carrier); | |
1883 | if (r < 0) | |
1884 | return r; | |
1885 | ||
1886 | return 0; | |
1887 | } | |
1888 | ||
1889 | static int link_new_bound_by_list(Link *link) { | |
1890 | Manager *m; | |
1891 | Link *carrier; | |
1892 | Iterator i; | |
1893 | int r; | |
1894 | bool list_updated = false; | |
1895 | ||
1896 | assert(link); | |
1897 | assert(link->manager); | |
1898 | ||
1899 | m = link->manager; | |
1900 | ||
b295beea | 1901 | HASHMAP_FOREACH(carrier, m->links, i) { |
0d4ad91d AR |
1902 | if (!carrier->network) |
1903 | continue; | |
1904 | ||
1905 | if (strv_isempty(carrier->network->bind_carrier)) | |
1906 | continue; | |
1907 | ||
1908 | if (strv_fnmatch(carrier->network->bind_carrier, link->ifname, 0)) { | |
1909 | r = link_put_carrier(link, carrier, &link->bound_by_links); | |
1910 | if (r < 0) | |
1911 | return r; | |
1912 | ||
1913 | list_updated = true; | |
1914 | } | |
1915 | } | |
1916 | ||
1917 | if (list_updated) | |
84de38c5 | 1918 | link_dirty(link); |
0d4ad91d | 1919 | |
b295beea | 1920 | HASHMAP_FOREACH(carrier, link->bound_by_links, i) { |
0d4ad91d AR |
1921 | r = link_put_carrier(carrier, link, &carrier->bound_to_links); |
1922 | if (r < 0) | |
1923 | return r; | |
1924 | ||
84de38c5 | 1925 | link_dirty(carrier); |
0d4ad91d AR |
1926 | } |
1927 | ||
1928 | return 0; | |
1929 | } | |
1930 | ||
1931 | static int link_new_bound_to_list(Link *link) { | |
1932 | Manager *m; | |
1933 | Link *carrier; | |
1934 | Iterator i; | |
1935 | int r; | |
1936 | bool list_updated = false; | |
1937 | ||
1938 | assert(link); | |
1939 | assert(link->manager); | |
1940 | ||
1941 | if (!link->network) | |
1942 | return 0; | |
1943 | ||
1944 | if (strv_isempty(link->network->bind_carrier)) | |
1945 | return 0; | |
1946 | ||
1947 | m = link->manager; | |
1948 | ||
1949 | HASHMAP_FOREACH (carrier, m->links, i) { | |
1950 | if (strv_fnmatch(link->network->bind_carrier, carrier->ifname, 0)) { | |
1951 | r = link_put_carrier(link, carrier, &link->bound_to_links); | |
1952 | if (r < 0) | |
1953 | return r; | |
1954 | ||
1955 | list_updated = true; | |
1956 | } | |
1957 | } | |
1958 | ||
1959 | if (list_updated) | |
84de38c5 | 1960 | link_dirty(link); |
0d4ad91d AR |
1961 | |
1962 | HASHMAP_FOREACH (carrier, link->bound_to_links, i) { | |
1963 | r = link_put_carrier(carrier, link, &carrier->bound_by_links); | |
1964 | if (r < 0) | |
1965 | return r; | |
1966 | ||
84de38c5 | 1967 | link_dirty(carrier); |
0d4ad91d AR |
1968 | } |
1969 | ||
1970 | return 0; | |
1971 | } | |
1972 | ||
1973 | static int link_new_carrier_maps(Link *link) { | |
1974 | int r; | |
1975 | ||
1976 | r = link_new_bound_by_list(link); | |
1977 | if (r < 0) | |
1978 | return r; | |
1979 | ||
1980 | r = link_handle_bound_by_list(link); | |
1981 | if (r < 0) | |
1982 | return r; | |
1983 | ||
1984 | r = link_new_bound_to_list(link); | |
1985 | if (r < 0) | |
1986 | return r; | |
1987 | ||
1988 | r = link_handle_bound_to_list(link); | |
1989 | if (r < 0) | |
1990 | return r; | |
1991 | ||
1992 | return 0; | |
1993 | } | |
1994 | ||
1995 | static void link_free_bound_to_list(Link *link) { | |
1996 | Link *bound_to; | |
1997 | Iterator i; | |
1998 | ||
1999 | HASHMAP_FOREACH (bound_to, link->bound_to_links, i) { | |
2000 | hashmap_remove(link->bound_to_links, INT_TO_PTR(bound_to->ifindex)); | |
2001 | ||
2002 | if (hashmap_remove(bound_to->bound_by_links, INT_TO_PTR(link->ifindex))) | |
84de38c5 | 2003 | link_dirty(bound_to); |
0d4ad91d AR |
2004 | } |
2005 | ||
2006 | return; | |
2007 | } | |
2008 | ||
2009 | static void link_free_bound_by_list(Link *link) { | |
2010 | Link *bound_by; | |
2011 | Iterator i; | |
2012 | ||
2013 | HASHMAP_FOREACH (bound_by, link->bound_by_links, i) { | |
2014 | hashmap_remove(link->bound_by_links, INT_TO_PTR(bound_by->ifindex)); | |
2015 | ||
2016 | if (hashmap_remove(bound_by->bound_to_links, INT_TO_PTR(link->ifindex))) { | |
84de38c5 | 2017 | link_dirty(bound_by); |
0d4ad91d AR |
2018 | link_handle_bound_to_list(bound_by); |
2019 | } | |
2020 | } | |
2021 | ||
2022 | return; | |
2023 | } | |
2024 | ||
2025 | static void link_free_carrier_maps(Link *link) { | |
2026 | bool list_updated = false; | |
2027 | ||
2028 | assert(link); | |
2029 | ||
2030 | if (!hashmap_isempty(link->bound_to_links)) { | |
2031 | link_free_bound_to_list(link); | |
2032 | list_updated = true; | |
2033 | } | |
2034 | ||
2035 | if (!hashmap_isempty(link->bound_by_links)) { | |
2036 | link_free_bound_by_list(link); | |
2037 | list_updated = true; | |
2038 | } | |
2039 | ||
2040 | if (list_updated) | |
84de38c5 | 2041 | link_dirty(link); |
0d4ad91d AR |
2042 | |
2043 | return; | |
2044 | } | |
2045 | ||
2046 | void link_drop(Link *link) { | |
2047 | if (!link || link->state == LINK_STATE_LINGER) | |
2048 | return; | |
2049 | ||
2050 | link_set_state(link, LINK_STATE_LINGER); | |
2051 | ||
2052 | link_free_carrier_maps(link); | |
2053 | ||
6a7a4e4d | 2054 | log_link_debug(link, "Link removed"); |
0d4ad91d | 2055 | |
84de38c5 | 2056 | (void)unlink(link->state_file); |
0d4ad91d AR |
2057 | link_unref(link); |
2058 | ||
2059 | return; | |
2060 | } | |
2061 | ||
3f265037 | 2062 | static int link_joined(Link *link) { |
f882c247 TG |
2063 | int r; |
2064 | ||
ef1ba606 | 2065 | assert(link); |
f5be5601 | 2066 | assert(link->network); |
dd3efc09 | 2067 | |
0d4ad91d AR |
2068 | if (!hashmap_isempty(link->bound_to_links)) { |
2069 | r = link_handle_bound_to_list(link); | |
2070 | if (r < 0) | |
2071 | return r; | |
2072 | } else if (!(link->flags & IFF_UP)) { | |
505f8da7 TG |
2073 | r = link_up(link); |
2074 | if (r < 0) { | |
2075 | link_enter_failed(link); | |
2076 | return r; | |
2077 | } | |
ef1ba606 | 2078 | } |
f882c247 | 2079 | |
9ed794a3 | 2080 | if (link->network->bridge) { |
e1853b00 | 2081 | r = link_set_bridge(link); |
6a7a4e4d LP |
2082 | if (r < 0) |
2083 | log_link_error_errno(link, r, "Could not set bridge message: %m"); | |
e1853b00 SS |
2084 | } |
2085 | ||
ffff9abe TJ |
2086 | if (link->network->use_br_vlan && |
2087 | (link->network->bridge || streq_ptr("bridge", link->kind))) { | |
13b498f9 TJ |
2088 | r = link_set_bridge_vlan(link); |
2089 | if (r < 0) | |
2090 | log_link_error_errno(link, r, "Could not set bridge vlan: %m"); | |
2091 | } | |
2092 | ||
fb6730c4 | 2093 | return link_enter_set_addresses(link); |
02b59d57 TG |
2094 | } |
2095 | ||
62e2d5bb | 2096 | static int netdev_join_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) { |
5da8149f | 2097 | _cleanup_link_unref_ Link *link = userdata; |
02b59d57 TG |
2098 | int r; |
2099 | ||
1746cf2a | 2100 | assert(link); |
ef1ba606 | 2101 | assert(link->network); |
02b59d57 | 2102 | |
313cefa1 | 2103 | link->enslaving--; |
52433f6b | 2104 | |
5da8149f | 2105 | if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) |
02b59d57 TG |
2106 | return 1; |
2107 | ||
1c4baffc | 2108 | r = sd_netlink_message_get_errno(m); |
856f962c | 2109 | if (r < 0 && r != -EEXIST) { |
a2fae7bb | 2110 | log_link_error_errno(link, r, "Could not join netdev: %m"); |
ef1ba606 TG |
2111 | link_enter_failed(link); |
2112 | return 1; | |
ba179154 | 2113 | } else |
6a7a4e4d | 2114 | log_link_debug(link, "Joined netdev"); |
02b59d57 | 2115 | |
856f962c | 2116 | if (link->enslaving <= 0) |
3f265037 | 2117 | link_joined(link); |
02b59d57 TG |
2118 | |
2119 | return 1; | |
2120 | } | |
2121 | ||
3f265037 | 2122 | static int link_enter_join_netdev(Link *link) { |
6a0a2f86 | 2123 | NetDev *netdev; |
672682a6 | 2124 | Iterator i; |
02b59d57 TG |
2125 | int r; |
2126 | ||
2127 | assert(link); | |
2128 | assert(link->network); | |
8434fd5c | 2129 | assert(link->state == LINK_STATE_PENDING); |
02b59d57 | 2130 | |
e331e246 | 2131 | link_set_state(link, LINK_STATE_ENSLAVING); |
02b59d57 | 2132 | |
84de38c5 | 2133 | link_dirty(link); |
fe8db0c5 | 2134 | |
7951dea2 SS |
2135 | if (!link->network->bridge && |
2136 | !link->network->bond && | |
6cb955c6 | 2137 | !link->network->vrf && |
6a0a2f86 | 2138 | hashmap_isempty(link->network->stacked_netdevs)) |
3f265037 | 2139 | return link_joined(link); |
02b59d57 | 2140 | |
d9c67ea1 | 2141 | if (link->network->bond) { |
f2341e0a LP |
2142 | log_struct(LOG_DEBUG, |
2143 | LOG_LINK_INTERFACE(link), | |
2144 | LOG_NETDEV_INTERFACE(link->network->bond), | |
2145 | LOG_LINK_MESSAGE(link, "Enslaving by '%s'", link->network->bond->ifname), | |
2146 | NULL); | |
2147 | ||
2148 | r = netdev_join(link->network->bond, link, netdev_join_handler); | |
52433f6b | 2149 | if (r < 0) { |
f2341e0a LP |
2150 | log_struct_errno(LOG_WARNING, r, |
2151 | LOG_LINK_INTERFACE(link), | |
2152 | LOG_NETDEV_INTERFACE(link->network->bond), | |
2153 | LOG_LINK_MESSAGE(link, "Could not join netdev '%s': %m", link->network->bond->ifname), | |
2154 | NULL); | |
2155 | ||
52433f6b TG |
2156 | link_enter_failed(link); |
2157 | return r; | |
2158 | } | |
2159 | ||
313cefa1 | 2160 | link->enslaving++; |
0ad6148e MO |
2161 | } |
2162 | ||
d9c67ea1 | 2163 | if (link->network->bridge) { |
f2341e0a LP |
2164 | log_struct(LOG_DEBUG, |
2165 | LOG_LINK_INTERFACE(link), | |
2166 | LOG_NETDEV_INTERFACE(link->network->bridge), | |
2167 | LOG_LINK_MESSAGE(link, "Enslaving by '%s'", link->network->bridge->ifname), | |
2168 | NULL); | |
2169 | ||
2170 | r = netdev_join(link->network->bridge, link, netdev_join_handler); | |
0ad6148e | 2171 | if (r < 0) { |
f2341e0a LP |
2172 | log_struct_errno(LOG_WARNING, r, |
2173 | LOG_LINK_INTERFACE(link), | |
2174 | LOG_NETDEV_INTERFACE(link->network->bridge), | |
2175 | LOG_LINK_MESSAGE(link, "Could not join netdev '%s': %m", link->network->bridge->ifname), | |
2176 | NULL), | |
0ad6148e MO |
2177 | link_enter_failed(link); |
2178 | return r; | |
2179 | } | |
2180 | ||
313cefa1 | 2181 | link->enslaving++; |
52433f6b TG |
2182 | } |
2183 | ||
6cb955c6 AR |
2184 | if (link->network->vrf) { |
2185 | log_struct(LOG_DEBUG, | |
2186 | LOG_LINK_INTERFACE(link), | |
2187 | LOG_NETDEV_INTERFACE(link->network->vrf), | |
2188 | LOG_LINK_MESSAGE(link, "Enslaving by '%s'", link->network->vrf->ifname), | |
2189 | NULL); | |
2190 | r = netdev_join(link->network->vrf, link, netdev_join_handler); | |
2191 | if (r < 0) { | |
2192 | log_struct_errno(LOG_WARNING, r, | |
2193 | LOG_LINK_INTERFACE(link), | |
2194 | LOG_NETDEV_INTERFACE(link->network->vrf), | |
2195 | LOG_LINK_MESSAGE(link, "Could not join netdev '%s': %m", link->network->vrf->ifname), | |
2196 | NULL); | |
2197 | link_enter_failed(link); | |
2198 | return r; | |
2199 | } | |
2200 | ||
2201 | link->enslaving++; | |
2202 | } | |
2203 | ||
6a0a2f86 | 2204 | HASHMAP_FOREACH(netdev, link->network->stacked_netdevs, i) { |
7951dea2 | 2205 | |
f2341e0a LP |
2206 | log_struct(LOG_DEBUG, |
2207 | LOG_LINK_INTERFACE(link), | |
2208 | LOG_NETDEV_INTERFACE(netdev), | |
2209 | LOG_LINK_MESSAGE(link, "Enslaving by '%s'", netdev->ifname), | |
2210 | NULL); | |
2211 | ||
2212 | r = netdev_join(netdev, link, netdev_join_handler); | |
7951dea2 | 2213 | if (r < 0) { |
f2341e0a LP |
2214 | log_struct_errno(LOG_WARNING, r, |
2215 | LOG_LINK_INTERFACE(link), | |
2216 | LOG_NETDEV_INTERFACE(netdev), | |
2217 | LOG_LINK_MESSAGE(link, "Could not join netdev '%s': %m", netdev->ifname), | |
2218 | NULL); | |
326cb406 SS |
2219 | link_enter_failed(link); |
2220 | return r; | |
2221 | } | |
2222 | ||
313cefa1 | 2223 | link->enslaving++; |
326cb406 SS |
2224 | } |
2225 | ||
ef1ba606 TG |
2226 | return 0; |
2227 | } | |
2228 | ||
769d324c | 2229 | static int link_set_ipv4_forward(Link *link) { |
5a8bcb67 LP |
2230 | int r; |
2231 | ||
765afd5c | 2232 | if (!link_ipv4_forward_enabled(link)) |
15dee3f0 LP |
2233 | return 0; |
2234 | ||
765afd5c LP |
2235 | /* We propagate the forwarding flag from one interface to the |
2236 | * global setting one way. This means: as long as at least one | |
2237 | * interface was configured at any time that had IP forwarding | |
2238 | * enabled the setting will stay on for good. We do this | |
2239 | * primarily to keep IPv4 and IPv6 packet forwarding behaviour | |
2240 | * somewhat in sync (see below). */ | |
15dee3f0 | 2241 | |
765afd5c | 2242 | r = write_string_file("/proc/sys/net/ipv4/ip_forward", "1", WRITE_STRING_FILE_VERIFY_ON_FAILURE); |
eb3da901 | 2243 | if (r < 0) |
765afd5c | 2244 | log_link_warning_errno(link, r, "Cannot turn on IPv4 packet forwarding, ignoring: %m"); |
43c6d5ab | 2245 | |
769d324c LP |
2246 | return 0; |
2247 | } | |
2248 | ||
2249 | static int link_set_ipv6_forward(Link *link) { | |
769d324c LP |
2250 | int r; |
2251 | ||
765afd5c | 2252 | if (!link_ipv6_forward_enabled(link)) |
8add5f79 NO |
2253 | return 0; |
2254 | ||
61233823 | 2255 | /* On Linux, the IPv6 stack does not know a per-interface |
765afd5c LP |
2256 | * packet forwarding setting: either packet forwarding is on |
2257 | * for all, or off for all. We hence don't bother with a | |
2258 | * per-interface setting, but simply propagate the interface | |
2259 | * flag, if it is set, to the global flag, one-way. Note that | |
2260 | * while IPv4 would allow a per-interface flag, we expose the | |
2261 | * same behaviour there and also propagate the setting from | |
2262 | * one to all, to keep things simple (see above). */ | |
15dee3f0 | 2263 | |
765afd5c | 2264 | r = write_string_file("/proc/sys/net/ipv6/conf/all/forwarding", "1", WRITE_STRING_FILE_VERIFY_ON_FAILURE); |
eb3da901 | 2265 | if (r < 0) |
765afd5c | 2266 | log_link_warning_errno(link, r, "Cannot configure IPv6 packet forwarding, ignoring: %m"); |
5a8bcb67 LP |
2267 | |
2268 | return 0; | |
2269 | } | |
2270 | ||
49092e22 | 2271 | static int link_set_ipv6_privacy_extensions(Link *link) { |
1f0d9695 LP |
2272 | char buf[DECIMAL_STR_MAX(unsigned) + 1]; |
2273 | IPv6PrivacyExtensions s; | |
49092e22 SS |
2274 | const char *p = NULL; |
2275 | int r; | |
2276 | ||
1f0d9695 | 2277 | s = link_ipv6_privacy_extensions(link); |
66a6bd68 | 2278 | if (s < 0) |
49092e22 SS |
2279 | return 0; |
2280 | ||
2281 | p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/use_tempaddr"); | |
66a6bd68 | 2282 | xsprintf(buf, "%u", (unsigned) link->network->ipv6_privacy_extensions); |
49092e22 | 2283 | |
eb3da901 LP |
2284 | r = write_string_file(p, buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE); |
2285 | if (r < 0) | |
49092e22 SS |
2286 | log_link_warning_errno(link, r, "Cannot configure IPv6 privacy extension for interface: %m"); |
2287 | ||
2288 | return 0; | |
2289 | } | |
2290 | ||
4f2e437a | 2291 | static int link_set_ipv6_accept_ra(Link *link) { |
3b015d40 | 2292 | const char *p = NULL; |
4f2e437a SS |
2293 | int r; |
2294 | ||
2295 | /* Make this a NOP if IPv6 is not available */ | |
2296 | if (!socket_ipv6_is_supported()) | |
2297 | return 0; | |
2298 | ||
2299 | if (link->flags & IFF_LOOPBACK) | |
2300 | return 0; | |
2301 | ||
d68e2e59 LP |
2302 | if (!link->network) |
2303 | return 0; | |
2304 | ||
4f2e437a | 2305 | p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/accept_ra"); |
4f2e437a | 2306 | |
0053598f | 2307 | /* We handle router advertisements ourselves, tell the kernel to GTFO */ |
fe307276 | 2308 | r = write_string_file(p, "0", WRITE_STRING_FILE_VERIFY_ON_FAILURE); |
eb3da901 | 2309 | if (r < 0) |
fe307276 | 2310 | log_link_warning_errno(link, r, "Cannot disable kernel IPv6 accept_ra for interface: %m"); |
4f2e437a SS |
2311 | |
2312 | return 0; | |
2313 | } | |
2314 | ||
8749cbcd | 2315 | static int link_set_ipv6_dad_transmits(Link *link) { |
66a6bd68 | 2316 | char buf[DECIMAL_STR_MAX(int) + 1]; |
8749cbcd SS |
2317 | const char *p = NULL; |
2318 | int r; | |
2319 | ||
2320 | /* Make this a NOP if IPv6 is not available */ | |
2321 | if (!socket_ipv6_is_supported()) | |
2322 | return 0; | |
2323 | ||
2324 | if (link->flags & IFF_LOOPBACK) | |
2325 | return 0; | |
2326 | ||
d68e2e59 LP |
2327 | if (!link->network) |
2328 | return 0; | |
2329 | ||
8749cbcd SS |
2330 | if (link->network->ipv6_dad_transmits < 0) |
2331 | return 0; | |
2332 | ||
2333 | p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/dad_transmits"); | |
66a6bd68 | 2334 | xsprintf(buf, "%i", link->network->ipv6_dad_transmits); |
8749cbcd | 2335 | |
eb3da901 LP |
2336 | r = write_string_file(p, buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE); |
2337 | if (r < 0) | |
8749cbcd | 2338 | log_link_warning_errno(link, r, "Cannot set IPv6 dad transmits for interface: %m"); |
8749cbcd SS |
2339 | |
2340 | return 0; | |
2341 | } | |
2342 | ||
b69c3180 | 2343 | static int link_set_ipv6_hop_limit(Link *link) { |
66a6bd68 | 2344 | char buf[DECIMAL_STR_MAX(int) + 1]; |
b69c3180 SS |
2345 | const char *p = NULL; |
2346 | int r; | |
2347 | ||
2348 | /* Make this a NOP if IPv6 is not available */ | |
2349 | if (!socket_ipv6_is_supported()) | |
2350 | return 0; | |
2351 | ||
2352 | if (link->flags & IFF_LOOPBACK) | |
2353 | return 0; | |
2354 | ||
d68e2e59 LP |
2355 | if (!link->network) |
2356 | return 0; | |
2357 | ||
b69c3180 SS |
2358 | if (link->network->ipv6_hop_limit < 0) |
2359 | return 0; | |
2360 | ||
2361 | p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/hop_limit"); | |
66a6bd68 | 2362 | xsprintf(buf, "%i", link->network->ipv6_hop_limit); |
b69c3180 | 2363 | |
eb3da901 LP |
2364 | r = write_string_file(p, buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE); |
2365 | if (r < 0) | |
b69c3180 | 2366 | log_link_warning_errno(link, r, "Cannot set IPv6 hop limit for interface: %m"); |
b69c3180 SS |
2367 | |
2368 | return 0; | |
2369 | } | |
2370 | ||
5e5b137a TG |
2371 | static int link_drop_foreign_config(Link *link) { |
2372 | Address *address; | |
2373 | Route *route; | |
2374 | Iterator i; | |
2375 | int r; | |
2376 | ||
2377 | SET_FOREACH(address, link->addresses_foreign, i) { | |
fe307276 | 2378 | /* we consider IPv6LL addresses to be managed by the kernel */ |
5e5b137a TG |
2379 | if (address->family == AF_INET6 && in_addr_is_link_local(AF_INET6, &address->in_addr) == 1) |
2380 | continue; | |
2381 | ||
2382 | r = address_remove(address, link, link_address_remove_handler); | |
2383 | if (r < 0) | |
2384 | return r; | |
2385 | } | |
2386 | ||
2387 | SET_FOREACH(route, link->routes_foreign, i) { | |
fe307276 | 2388 | /* do not touch routes managed by the kernel */ |
5e5b137a TG |
2389 | if (route->protocol == RTPROT_KERNEL) |
2390 | continue; | |
2391 | ||
3fb1ac5d | 2392 | r = route_remove(route, link, link_route_remove_handler); |
5e5b137a TG |
2393 | if (r < 0) |
2394 | return r; | |
2395 | } | |
2396 | ||
2397 | return 0; | |
2398 | } | |
2399 | ||
3104883d SS |
2400 | static int link_drop_config(Link *link) { |
2401 | Address *address; | |
2402 | Route *route; | |
2403 | Iterator i; | |
2404 | int r; | |
2405 | ||
2406 | SET_FOREACH(address, link->addresses, i) { | |
2407 | /* we consider IPv6LL addresses to be managed by the kernel */ | |
2408 | if (address->family == AF_INET6 && in_addr_is_link_local(AF_INET6, &address->in_addr) == 1) | |
2409 | continue; | |
2410 | ||
2411 | r = address_remove(address, link, link_address_remove_handler); | |
2412 | if (r < 0) | |
2413 | return r; | |
2414 | } | |
2415 | ||
2416 | SET_FOREACH(route, link->routes, i) { | |
2417 | /* do not touch routes managed by the kernel */ | |
2418 | if (route->protocol == RTPROT_KERNEL) | |
2419 | continue; | |
2420 | ||
2421 | r = route_remove(route, link, link_route_remove_handler); | |
2422 | if (r < 0) | |
2423 | return r; | |
2424 | } | |
2425 | ||
c69305ff LP |
2426 | ndisc_flush(link); |
2427 | ||
3104883d SS |
2428 | return 0; |
2429 | } | |
2430 | ||
273eec24 LP |
2431 | static int link_update_lldp(Link *link) { |
2432 | int r; | |
2433 | ||
2434 | assert(link); | |
2435 | ||
2436 | if (!link->lldp) | |
2437 | return 0; | |
2438 | ||
2439 | if (link->flags & IFF_UP) { | |
2440 | r = sd_lldp_start(link->lldp); | |
2441 | if (r > 0) | |
2442 | log_link_debug(link, "Started LLDP."); | |
2443 | } else { | |
2444 | r = sd_lldp_stop(link->lldp); | |
2445 | if (r > 0) | |
2446 | log_link_debug(link, "Stopped LLDP."); | |
2447 | } | |
2448 | ||
2449 | return r; | |
2450 | } | |
2451 | ||
a748b692 | 2452 | static int link_configure(Link *link) { |
02b59d57 TG |
2453 | int r; |
2454 | ||
ef1ba606 | 2455 | assert(link); |
b22d8a00 | 2456 | assert(link->network); |
8434fd5c | 2457 | assert(link->state == LINK_STATE_PENDING); |
a748b692 | 2458 | |
92c918b0 SS |
2459 | if (streq_ptr(link->kind, "vcan")) { |
2460 | ||
2461 | if (!(link->flags & IFF_UP)) { | |
2462 | r = link_up_can(link); | |
2463 | if (r < 0) { | |
2464 | link_enter_failed(link); | |
2465 | return r; | |
2466 | } | |
2467 | } | |
2468 | ||
2469 | return 0; | |
2470 | } | |
2471 | ||
02e28621 ДГ |
2472 | /* Drop foreign config, but ignore loopback or critical devices. |
2473 | * We do not want to remove loopback address or addresses used for root NFS. */ | |
2474 | if (!(link->flags & IFF_LOOPBACK) && !(link->network->dhcp_critical)) { | |
e5d44b34 CH |
2475 | r = link_drop_foreign_config(link); |
2476 | if (r < 0) | |
2477 | return r; | |
2478 | } | |
5e5b137a | 2479 | |
23d8b221 SS |
2480 | r = link_set_proxy_arp(link); |
2481 | if (r < 0) | |
2482 | return r; | |
2483 | ||
769d324c LP |
2484 | r = link_set_ipv4_forward(link); |
2485 | if (r < 0) | |
2486 | return r; | |
2487 | ||
2488 | r = link_set_ipv6_forward(link); | |
5a8bcb67 LP |
2489 | if (r < 0) |
2490 | return r; | |
2491 | ||
49092e22 SS |
2492 | r = link_set_ipv6_privacy_extensions(link); |
2493 | if (r < 0) | |
2494 | return r; | |
2495 | ||
4f2e437a SS |
2496 | r = link_set_ipv6_accept_ra(link); |
2497 | if (r < 0) | |
2498 | return r; | |
2499 | ||
8749cbcd SS |
2500 | r = link_set_ipv6_dad_transmits(link); |
2501 | if (r < 0) | |
2502 | return r; | |
b69c3180 SS |
2503 | |
2504 | r = link_set_ipv6_hop_limit(link); | |
2505 | if (r < 0) | |
2506 | return r; | |
8749cbcd | 2507 | |
99d2baa2 SS |
2508 | r = link_set_flags(link); |
2509 | if (r < 0) | |
2510 | return r; | |
2511 | ||
78c958f8 | 2512 | if (link_ipv4ll_enabled(link)) { |
b22d8a00 | 2513 | r = ipv4ll_configure(link); |
eb34d4af TG |
2514 | if (r < 0) |
2515 | return r; | |
2516 | } | |
2517 | ||
78c958f8 | 2518 | if (link_dhcp4_enabled(link)) { |
3c9b8860 | 2519 | r = dhcp4_configure(link); |
eb34d4af TG |
2520 | if (r < 0) |
2521 | return r; | |
eb34d4af TG |
2522 | } |
2523 | ||
78c958f8 | 2524 | if (link_dhcp4_server_enabled(link)) { |
dd43110f TG |
2525 | r = sd_dhcp_server_new(&link->dhcp_server, link->ifindex); |
2526 | if (r < 0) | |
2527 | return r; | |
2528 | ||
2529 | r = sd_dhcp_server_attach_event(link->dhcp_server, NULL, 0); | |
2530 | if (r < 0) | |
2531 | return r; | |
dd43110f TG |
2532 | } |
2533 | ||
62379e88 TG |
2534 | if (link_dhcp6_enabled(link) || |
2535 | link_ipv6_accept_ra_enabled(link)) { | |
f5a8c43f TG |
2536 | r = dhcp6_configure(link); |
2537 | if (r < 0) | |
2538 | return r; | |
2539 | } | |
2540 | ||
2541 | if (link_ipv6_accept_ra_enabled(link)) { | |
de1e9928 | 2542 | r = ndisc_configure(link); |
4138fb2c PF |
2543 | if (r < 0) |
2544 | return r; | |
2545 | } | |
2546 | ||
8e1ad1ea | 2547 | if (link_lldp_rx_enabled(link)) { |
fc6a313b LP |
2548 | r = sd_lldp_new(&link->lldp); |
2549 | if (r < 0) | |
2550 | return r; | |
2551 | ||
2552 | r = sd_lldp_set_ifindex(link->lldp, link->ifindex); | |
34437b4f LP |
2553 | if (r < 0) |
2554 | return r; | |
2555 | ||
2556 | r = sd_lldp_match_capabilities(link->lldp, | |
2557 | link->network->lldp_mode == LLDP_MODE_ROUTERS_ONLY ? | |
6afa6767 BG |
2558 | SD_LLDP_SYSTEM_CAPABILITIES_ALL_ROUTERS : |
2559 | SD_LLDP_SYSTEM_CAPABILITIES_ALL); | |
ce43e484 SS |
2560 | if (r < 0) |
2561 | return r; | |
2562 | ||
b553a6b1 LP |
2563 | r = sd_lldp_set_filter_address(link->lldp, &link->mac); |
2564 | if (r < 0) | |
2565 | return r; | |
2566 | ||
ce43e484 SS |
2567 | r = sd_lldp_attach_event(link->lldp, NULL, 0); |
2568 | if (r < 0) | |
2569 | return r; | |
49699bac | 2570 | |
032b27f5 | 2571 | r = sd_lldp_set_callback(link->lldp, lldp_handler, link); |
49699bac SS |
2572 | if (r < 0) |
2573 | return r; | |
273eec24 LP |
2574 | |
2575 | r = link_update_lldp(link); | |
2576 | if (r < 0) | |
2577 | return r; | |
ce43e484 SS |
2578 | } |
2579 | ||
a61bb41c | 2580 | if (link_has_carrier(link)) { |
1e9be60b TG |
2581 | r = link_acquire_conf(link); |
2582 | if (r < 0) | |
2583 | return r; | |
cc544d5f | 2584 | } |
1e9be60b | 2585 | |
3f265037 | 2586 | return link_enter_join_netdev(link); |
505f8da7 TG |
2587 | } |
2588 | ||
1c4baffc | 2589 | static int link_initialized_and_synced(sd_netlink *rtnl, sd_netlink_message *m, |
3c9b8860 | 2590 | void *userdata) { |
5da8149f | 2591 | _cleanup_link_unref_ Link *link = userdata; |
505f8da7 | 2592 | Network *network; |
505f8da7 TG |
2593 | int r; |
2594 | ||
2595 | assert(link); | |
2596 | assert(link->ifname); | |
2597 | assert(link->manager); | |
2598 | ||
8434fd5c | 2599 | if (link->state != LINK_STATE_PENDING) |
5da8149f | 2600 | return 1; |
505f8da7 | 2601 | |
6a7a4e4d | 2602 | log_link_debug(link, "Link state is up-to-date"); |
505f8da7 | 2603 | |
0d4ad91d AR |
2604 | r = link_new_bound_by_list(link); |
2605 | if (r < 0) | |
2606 | return r; | |
2607 | ||
2608 | r = link_handle_bound_by_list(link); | |
2609 | if (r < 0) | |
2610 | return r; | |
2611 | ||
c4a03a56 TG |
2612 | if (!link->network) { |
2613 | r = network_get(link->manager, link->udev_device, link->ifname, | |
2614 | &link->mac, &network); | |
2615 | if (r == -ENOENT) { | |
2616 | link_enter_unmanaged(link); | |
2617 | return 1; | |
2618 | } else if (r < 0) | |
2619 | return r; | |
505f8da7 | 2620 | |
c4a03a56 TG |
2621 | if (link->flags & IFF_LOOPBACK) { |
2622 | if (network->link_local != ADDRESS_FAMILY_NO) | |
2623 | log_link_debug(link, "Ignoring link-local autoconfiguration for loopback link"); | |
78c958f8 | 2624 | |
c4a03a56 TG |
2625 | if (network->dhcp != ADDRESS_FAMILY_NO) |
2626 | log_link_debug(link, "Ignoring DHCP clients for loopback link"); | |
78c958f8 | 2627 | |
c4a03a56 TG |
2628 | if (network->dhcp_server) |
2629 | log_link_debug(link, "Ignoring DHCP server for loopback link"); | |
2630 | } | |
bd2efe92 | 2631 | |
7d342c03 | 2632 | r = network_apply(network, link); |
c4a03a56 TG |
2633 | if (r < 0) |
2634 | return r; | |
2635 | } | |
505f8da7 | 2636 | |
0d4ad91d AR |
2637 | r = link_new_bound_to_list(link); |
2638 | if (r < 0) | |
2639 | return r; | |
2640 | ||
a748b692 TG |
2641 | r = link_configure(link); |
2642 | if (r < 0) | |
2643 | return r; | |
2644 | ||
5da8149f | 2645 | return 1; |
505f8da7 TG |
2646 | } |
2647 | ||
4f561e8e | 2648 | int link_initialized(Link *link, struct udev_device *device) { |
4afd3348 | 2649 | _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL; |
4f561e8e TG |
2650 | int r; |
2651 | ||
2652 | assert(link); | |
2653 | assert(link->manager); | |
2654 | assert(link->manager->rtnl); | |
2655 | assert(device); | |
2656 | ||
8434fd5c | 2657 | if (link->state != LINK_STATE_PENDING) |
4f561e8e TG |
2658 | return 0; |
2659 | ||
679b3605 TG |
2660 | if (link->udev_device) |
2661 | return 0; | |
2662 | ||
79008bdd | 2663 | log_link_debug(link, "udev initialized link"); |
4f561e8e TG |
2664 | |
2665 | link->udev_device = udev_device_ref(device); | |
2666 | ||
3c9b8860 TG |
2667 | /* udev has initialized the link, but we don't know if we have yet |
2668 | * processed the NEWLINK messages with the latest state. Do a GETLINK, | |
2669 | * when it returns we know that the pending NEWLINKs have already been | |
2670 | * processed and that we are up-to-date */ | |
4f561e8e | 2671 | |
3c9b8860 TG |
2672 | r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_GETLINK, |
2673 | link->ifindex); | |
4f561e8e TG |
2674 | if (r < 0) |
2675 | return r; | |
2676 | ||
1c4baffc | 2677 | r = sd_netlink_call_async(link->manager->rtnl, req, |
3c9b8860 | 2678 | link_initialized_and_synced, link, 0, NULL); |
4f561e8e TG |
2679 | if (r < 0) |
2680 | return r; | |
2681 | ||
5da8149f TG |
2682 | link_ref(link); |
2683 | ||
4f561e8e TG |
2684 | return 0; |
2685 | } | |
2686 | ||
c4a03a56 | 2687 | static int link_load(Link *link) { |
0bc70f1d TG |
2688 | _cleanup_free_ char *network_file = NULL, |
2689 | *addresses = NULL, | |
f703cc2c | 2690 | *routes = NULL, |
0bc70f1d TG |
2691 | *dhcp4_address = NULL, |
2692 | *ipv4ll_address = NULL; | |
2693 | union in_addr_union address; | |
f703cc2c | 2694 | union in_addr_union route_dst; |
c598ac76 | 2695 | const char *p; |
c4a03a56 TG |
2696 | int r; |
2697 | ||
2698 | assert(link); | |
2699 | ||
2700 | r = parse_env_file(link->state_file, NEWLINE, | |
2701 | "NETWORK_FILE", &network_file, | |
2702 | "ADDRESSES", &addresses, | |
f703cc2c | 2703 | "ROUTES", &routes, |
0bc70f1d TG |
2704 | "DHCP4_ADDRESS", &dhcp4_address, |
2705 | "IPV4LL_ADDRESS", &ipv4ll_address, | |
c4a03a56 TG |
2706 | NULL); |
2707 | if (r < 0 && r != -ENOENT) | |
2708 | return log_link_error_errno(link, r, "Failed to read %s: %m", link->state_file); | |
2709 | ||
2710 | if (network_file) { | |
2711 | Network *network; | |
2712 | char *suffix; | |
2713 | ||
2714 | /* drop suffix */ | |
2715 | suffix = strrchr(network_file, '.'); | |
2716 | if (!suffix) { | |
2717 | log_link_debug(link, "Failed to get network name from %s", network_file); | |
2718 | goto network_file_fail; | |
2719 | } | |
2720 | *suffix = '\0'; | |
2721 | ||
2722 | r = network_get_by_name(link->manager, basename(network_file), &network); | |
2723 | if (r < 0) { | |
2724 | log_link_debug_errno(link, r, "Failed to get network %s: %m", basename(network_file)); | |
2725 | goto network_file_fail; | |
2726 | } | |
2727 | ||
7d342c03 | 2728 | r = network_apply(network, link); |
c4a03a56 TG |
2729 | if (r < 0) |
2730 | return log_link_error_errno(link, r, "Failed to apply network %s: %m", basename(network_file)); | |
2731 | } | |
2732 | ||
2733 | network_file_fail: | |
2734 | ||
2735 | if (addresses) { | |
c598ac76 | 2736 | p = addresses; |
c4a03a56 | 2737 | |
c598ac76 TG |
2738 | for (;;) { |
2739 | _cleanup_free_ char *address_str = NULL; | |
c4a03a56 TG |
2740 | char *prefixlen_str; |
2741 | int family; | |
2742 | unsigned char prefixlen; | |
c4a03a56 | 2743 | |
c598ac76 TG |
2744 | r = extract_first_word(&p, &address_str, NULL, 0); |
2745 | if (r < 0) { | |
2746 | log_link_debug_errno(link, r, "Failed to extract next address string: %m"); | |
2747 | continue; | |
928bc597 TA |
2748 | } |
2749 | if (r == 0) | |
c598ac76 TG |
2750 | break; |
2751 | ||
2752 | prefixlen_str = strchr(address_str, '/'); | |
c4a03a56 | 2753 | if (!prefixlen_str) { |
c598ac76 | 2754 | log_link_debug(link, "Failed to parse address and prefix length %s", address_str); |
c4a03a56 TG |
2755 | continue; |
2756 | } | |
2757 | ||
313cefa1 | 2758 | *prefixlen_str++ = '\0'; |
c4a03a56 TG |
2759 | |
2760 | r = sscanf(prefixlen_str, "%hhu", &prefixlen); | |
2761 | if (r != 1) { | |
2762 | log_link_error(link, "Failed to parse prefixlen %s", prefixlen_str); | |
2763 | continue; | |
2764 | } | |
2765 | ||
c598ac76 | 2766 | r = in_addr_from_string_auto(address_str, &family, &address); |
c4a03a56 | 2767 | if (r < 0) { |
c598ac76 | 2768 | log_link_debug_errno(link, r, "Failed to parse address %s: %m", address_str); |
c4a03a56 TG |
2769 | continue; |
2770 | } | |
2771 | ||
2772 | r = address_add(link, family, &address, prefixlen, NULL); | |
2773 | if (r < 0) | |
2774 | return log_link_error_errno(link, r, "Failed to add address: %m"); | |
2775 | } | |
2776 | } | |
2777 | ||
f703cc2c | 2778 | if (routes) { |
74544b4e TA |
2779 | p = routes; |
2780 | ||
c598ac76 | 2781 | for (;;) { |
f833694d | 2782 | Route *route; |
c598ac76 | 2783 | _cleanup_free_ char *route_str = NULL; |
4afd3348 | 2784 | _cleanup_(sd_event_source_unrefp) sd_event_source *expire = NULL; |
f833694d | 2785 | usec_t lifetime; |
f703cc2c TG |
2786 | char *prefixlen_str; |
2787 | int family; | |
2788 | unsigned char prefixlen, tos, table; | |
2789 | uint32_t priority; | |
2790 | ||
c598ac76 TG |
2791 | r = extract_first_word(&p, &route_str, NULL, 0); |
2792 | if (r < 0) { | |
2793 | log_link_debug_errno(link, r, "Failed to extract next route string: %m"); | |
2794 | continue; | |
928bc597 TA |
2795 | } |
2796 | if (r == 0) | |
c598ac76 TG |
2797 | break; |
2798 | ||
2799 | prefixlen_str = strchr(route_str, '/'); | |
f703cc2c | 2800 | if (!prefixlen_str) { |
c598ac76 | 2801 | log_link_debug(link, "Failed to parse route %s", route_str); |
f703cc2c TG |
2802 | continue; |
2803 | } | |
2804 | ||
313cefa1 | 2805 | *prefixlen_str++ = '\0'; |
f703cc2c | 2806 | |
f833694d TG |
2807 | r = sscanf(prefixlen_str, "%hhu/%hhu/%"SCNu32"/%hhu/"USEC_FMT, &prefixlen, &tos, &priority, &table, &lifetime); |
2808 | if (r != 5) { | |
2809 | log_link_debug(link, | |
2810 | "Failed to parse destination prefix length, tos, priority, table or expiration %s", | |
2811 | prefixlen_str); | |
f703cc2c TG |
2812 | continue; |
2813 | } | |
2814 | ||
c598ac76 | 2815 | r = in_addr_from_string_auto(route_str, &family, &route_dst); |
f703cc2c | 2816 | if (r < 0) { |
c598ac76 | 2817 | log_link_debug_errno(link, r, "Failed to parse route destination %s: %m", route_str); |
f703cc2c TG |
2818 | continue; |
2819 | } | |
2820 | ||
f833694d | 2821 | r = route_add(link, family, &route_dst, prefixlen, tos, priority, table, &route); |
f703cc2c TG |
2822 | if (r < 0) |
2823 | return log_link_error_errno(link, r, "Failed to add route: %m"); | |
f833694d TG |
2824 | |
2825 | if (lifetime != USEC_INFINITY) { | |
2826 | r = sd_event_add_time(link->manager->event, &expire, clock_boottime_or_monotonic(), lifetime, | |
2827 | 0, route_expire_handler, route); | |
2828 | if (r < 0) | |
2829 | log_link_warning_errno(link, r, "Could not arm route expiration handler: %m"); | |
2830 | } | |
2831 | ||
2832 | route->lifetime = lifetime; | |
2833 | sd_event_source_unref(route->expire); | |
2834 | route->expire = expire; | |
2835 | expire = NULL; | |
f703cc2c TG |
2836 | } |
2837 | } | |
2838 | ||
0bc70f1d TG |
2839 | if (dhcp4_address) { |
2840 | r = in_addr_from_string(AF_INET, dhcp4_address, &address); | |
2841 | if (r < 0) { | |
b68d26b8 | 2842 | log_link_debug_errno(link, r, "Failed to parse DHCPv4 address %s: %m", dhcp4_address); |
0bc70f1d TG |
2843 | goto dhcp4_address_fail; |
2844 | } | |
2845 | ||
2846 | r = sd_dhcp_client_new(&link->dhcp_client); | |
2847 | if (r < 0) | |
b68d26b8 | 2848 | return log_link_error_errno(link, r, "Failed to create DHCPv4 client: %m"); |
0bc70f1d TG |
2849 | |
2850 | r = sd_dhcp_client_set_request_address(link->dhcp_client, &address.in); | |
2851 | if (r < 0) | |
b68d26b8 | 2852 | return log_link_error_errno(link, r, "Failed to set initial DHCPv4 address %s: %m", dhcp4_address); |
0bc70f1d TG |
2853 | } |
2854 | ||
2855 | dhcp4_address_fail: | |
2856 | ||
2857 | if (ipv4ll_address) { | |
2858 | r = in_addr_from_string(AF_INET, ipv4ll_address, &address); | |
2859 | if (r < 0) { | |
b68d26b8 | 2860 | log_link_debug_errno(link, r, "Failed to parse IPv4LL address %s: %m", ipv4ll_address); |
0bc70f1d TG |
2861 | goto ipv4ll_address_fail; |
2862 | } | |
2863 | ||
2864 | r = sd_ipv4ll_new(&link->ipv4ll); | |
2865 | if (r < 0) | |
b68d26b8 | 2866 | return log_link_error_errno(link, r, "Failed to create IPv4LL client: %m"); |
0bc70f1d TG |
2867 | |
2868 | r = sd_ipv4ll_set_address(link->ipv4ll, &address.in); | |
2869 | if (r < 0) | |
b68d26b8 | 2870 | return log_link_error_errno(link, r, "Failed to set initial IPv4LL address %s: %m", ipv4ll_address); |
0bc70f1d TG |
2871 | } |
2872 | ||
2873 | ipv4ll_address_fail: | |
2874 | ||
c4a03a56 TG |
2875 | return 0; |
2876 | } | |
2877 | ||
1c4baffc | 2878 | int link_add(Manager *m, sd_netlink_message *message, Link **ret) { |
505f8da7 TG |
2879 | Link *link; |
2880 | _cleanup_udev_device_unref_ struct udev_device *device = NULL; | |
2881 | char ifindex_str[2 + DECIMAL_STR_MAX(int)]; | |
2882 | int r; | |
2883 | ||
2884 | assert(m); | |
fbbeb65a | 2885 | assert(m->rtnl); |
505f8da7 TG |
2886 | assert(message); |
2887 | assert(ret); | |
2888 | ||
2889 | r = link_new(m, message, ret); | |
2890 | if (r < 0) | |
2891 | return r; | |
2892 | ||
2893 | link = *ret; | |
2894 | ||
6a7a4e4d | 2895 | log_link_debug(link, "Link %d added", link->ifindex); |
505f8da7 | 2896 | |
c4a03a56 TG |
2897 | r = link_load(link); |
2898 | if (r < 0) | |
2899 | return r; | |
2900 | ||
75f86906 | 2901 | if (detect_container() <= 0) { |
505f8da7 | 2902 | /* not in a container, udev will be around */ |
ae06ab10 | 2903 | sprintf(ifindex_str, "n%d", link->ifindex); |
505f8da7 | 2904 | device = udev_device_new_from_device_id(m->udev, ifindex_str); |
5c416fc4 TG |
2905 | if (!device) { |
2906 | r = log_link_warning_errno(link, errno, "Could not find udev device: %m"); | |
2907 | goto failed; | |
2908 | } | |
505f8da7 | 2909 | |
3c4cb064 | 2910 | if (udev_device_get_is_initialized(device) <= 0) { |
505f8da7 | 2911 | /* not yet ready */ |
79008bdd | 2912 | log_link_debug(link, "link pending udev initialization..."); |
505f8da7 | 2913 | return 0; |
3c4cb064 | 2914 | } |
505f8da7 | 2915 | |
4f561e8e TG |
2916 | r = link_initialized(link, device); |
2917 | if (r < 0) | |
5c416fc4 | 2918 | goto failed; |
4f561e8e | 2919 | } else { |
5da8149f TG |
2920 | /* we are calling a callback directly, so must take a ref */ |
2921 | link_ref(link); | |
2922 | ||
4f561e8e TG |
2923 | r = link_initialized_and_synced(m->rtnl, NULL, link); |
2924 | if (r < 0) | |
5c416fc4 | 2925 | goto failed; |
4f561e8e | 2926 | } |
505f8da7 | 2927 | |
a748b692 | 2928 | return 0; |
5c416fc4 TG |
2929 | failed: |
2930 | link_enter_failed(link); | |
2931 | return r; | |
a748b692 TG |
2932 | } |
2933 | ||
c601ebf7 | 2934 | int link_ipv6ll_gained(Link *link, const struct in6_addr *address) { |
e7ab854c TG |
2935 | int r; |
2936 | ||
2937 | assert(link); | |
2938 | ||
2939 | log_link_info(link, "Gained IPv6LL"); | |
2940 | ||
c601ebf7 | 2941 | link->ipv6ll_address = *address; |
e7ab854c TG |
2942 | link_check_ready(link); |
2943 | ||
201f0c91 | 2944 | if (!IN_SET(link->state, LINK_STATE_PENDING, LINK_STATE_UNMANAGED, LINK_STATE_FAILED)) { |
e7ab854c TG |
2945 | r = link_acquire_ipv6_conf(link); |
2946 | if (r < 0) { | |
2947 | link_enter_failed(link); | |
2948 | return r; | |
2949 | } | |
2950 | } | |
2951 | ||
2952 | return 0; | |
2953 | } | |
2954 | ||
9c0a72f9 TG |
2955 | static int link_carrier_gained(Link *link) { |
2956 | int r; | |
2957 | ||
2958 | assert(link); | |
2959 | ||
201f0c91 | 2960 | if (!IN_SET(link->state, LINK_STATE_PENDING, LINK_STATE_UNMANAGED, LINK_STATE_FAILED)) { |
9c0a72f9 TG |
2961 | r = link_acquire_conf(link); |
2962 | if (r < 0) { | |
2963 | link_enter_failed(link); | |
2964 | return r; | |
2965 | } | |
6fc25497 SS |
2966 | |
2967 | r = link_enter_set_addresses(link); | |
2968 | if (r < 0) | |
2969 | return r; | |
9c0a72f9 TG |
2970 | } |
2971 | ||
0d4ad91d AR |
2972 | r = link_handle_bound_by_list(link); |
2973 | if (r < 0) | |
2974 | return r; | |
2975 | ||
9c0a72f9 TG |
2976 | return 0; |
2977 | } | |
2978 | ||
2979 | static int link_carrier_lost(Link *link) { | |
2980 | int r; | |
2981 | ||
2982 | assert(link); | |
2983 | ||
2984 | r = link_stop_clients(link); | |
2985 | if (r < 0) { | |
2986 | link_enter_failed(link); | |
2987 | return r; | |
2988 | } | |
2989 | ||
3104883d SS |
2990 | r = link_drop_config(link); |
2991 | if (r < 0) | |
2992 | return r; | |
2993 | ||
f258e948 MP |
2994 | if (!IN_SET(link->state, LINK_STATE_UNMANAGED, LINK_STATE_PENDING)) { |
2995 | log_link_debug(link, "State is %s, dropping config", link_state_to_string(link->state)); | |
c436d553 MM |
2996 | r = link_drop_foreign_config(link); |
2997 | if (r < 0) | |
2998 | return r; | |
2999 | } | |
3104883d | 3000 | |
0d4ad91d AR |
3001 | r = link_handle_bound_by_list(link); |
3002 | if (r < 0) | |
3003 | return r; | |
3004 | ||
9c0a72f9 TG |
3005 | return 0; |
3006 | } | |
3007 | ||
3008 | int link_carrier_reset(Link *link) { | |
3009 | int r; | |
3010 | ||
3011 | assert(link); | |
3012 | ||
3013 | if (link_has_carrier(link)) { | |
3014 | r = link_carrier_lost(link); | |
3015 | if (r < 0) | |
3016 | return r; | |
3017 | ||
3018 | r = link_carrier_gained(link); | |
3019 | if (r < 0) | |
3020 | return r; | |
3021 | ||
6a7a4e4d | 3022 | log_link_info(link, "Reset carrier"); |
9c0a72f9 TG |
3023 | } |
3024 | ||
3025 | return 0; | |
3026 | } | |
3027 | ||
1c4baffc | 3028 | int link_update(Link *link, sd_netlink_message *m) { |
c49b33ac | 3029 | struct ether_addr mac; |
ca4e095a | 3030 | const char *ifname; |
afe7fd56 | 3031 | uint32_t mtu; |
a61bb41c | 3032 | bool had_carrier, carrier_gained, carrier_lost; |
22936833 TG |
3033 | int r; |
3034 | ||
dd3efc09 | 3035 | assert(link); |
b8941f74 | 3036 | assert(link->ifname); |
22936833 TG |
3037 | assert(m); |
3038 | ||
7619683b TG |
3039 | if (link->state == LINK_STATE_LINGER) { |
3040 | link_ref(link); | |
6a7a4e4d | 3041 | log_link_info(link, "Link readded"); |
e331e246 | 3042 | link_set_state(link, LINK_STATE_ENSLAVING); |
0d4ad91d AR |
3043 | |
3044 | r = link_new_carrier_maps(link); | |
3045 | if (r < 0) | |
3046 | return r; | |
7619683b TG |
3047 | } |
3048 | ||
1c4baffc | 3049 | r = sd_netlink_message_read_string(m, IFLA_IFNAME, &ifname); |
b8941f74 | 3050 | if (r >= 0 && !streq(ifname, link->ifname)) { |
6a7a4e4d | 3051 | log_link_info(link, "Renamed to %s", ifname); |
b8941f74 | 3052 | |
0d4ad91d AR |
3053 | link_free_carrier_maps(link); |
3054 | ||
2fc09a9c DM |
3055 | r = free_and_strdup(&link->ifname, ifname); |
3056 | if (r < 0) | |
3057 | return r; | |
0d4ad91d AR |
3058 | |
3059 | r = link_new_carrier_maps(link); | |
3060 | if (r < 0) | |
3061 | return r; | |
b8941f74 TG |
3062 | } |
3063 | ||
1c4baffc | 3064 | r = sd_netlink_message_read_u32(m, IFLA_MTU, &mtu); |
afe7fd56 TG |
3065 | if (r >= 0 && mtu > 0) { |
3066 | link->mtu = mtu; | |
3067 | if (!link->original_mtu) { | |
3068 | link->original_mtu = mtu; | |
6a7a4e4d | 3069 | log_link_debug(link, "Saved original MTU: %" PRIu32, link->original_mtu); |
afe7fd56 TG |
3070 | } |
3071 | ||
3072 | if (link->dhcp_client) { | |
3c9b8860 TG |
3073 | r = sd_dhcp_client_set_mtu(link->dhcp_client, |
3074 | link->mtu); | |
afe7fd56 | 3075 | if (r < 0) { |
6a7a4e4d | 3076 | log_link_warning_errno(link, r, "Could not update MTU in DHCP client: %m"); |
afe7fd56 TG |
3077 | return r; |
3078 | } | |
3079 | } | |
9842de0d | 3080 | } |
69629de9 | 3081 | |
e9189a1f TG |
3082 | /* The kernel may broadcast NEWLINK messages without the MAC address |
3083 | set, simply ignore them. */ | |
1c4baffc | 3084 | r = sd_netlink_message_read_ether_addr(m, IFLA_ADDRESS, &mac); |
e9189a1f | 3085 | if (r >= 0) { |
3c9b8860 TG |
3086 | if (memcmp(link->mac.ether_addr_octet, mac.ether_addr_octet, |
3087 | ETH_ALEN)) { | |
c49b33ac | 3088 | |
3c9b8860 TG |
3089 | memcpy(link->mac.ether_addr_octet, mac.ether_addr_octet, |
3090 | ETH_ALEN); | |
c49b33ac | 3091 | |
79008bdd | 3092 | log_link_debug(link, "MAC address: " |
20861203 TG |
3093 | "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", |
3094 | mac.ether_addr_octet[0], | |
3095 | mac.ether_addr_octet[1], | |
3096 | mac.ether_addr_octet[2], | |
3097 | mac.ether_addr_octet[3], | |
3098 | mac.ether_addr_octet[4], | |
3099 | mac.ether_addr_octet[5]); | |
c49b33ac | 3100 | |
20861203 TG |
3101 | if (link->ipv4ll) { |
3102 | r = sd_ipv4ll_set_mac(link->ipv4ll, &link->mac); | |
6a7a4e4d LP |
3103 | if (r < 0) |
3104 | return log_link_warning_errno(link, r, "Could not update MAC address in IPv4LL client: %m"); | |
c49b33ac | 3105 | } |
c49b33ac | 3106 | |
20861203 | 3107 | if (link->dhcp_client) { |
8341a5c3 ZJS |
3108 | const DUID *duid = link_duid(link); |
3109 | ||
3c9b8860 | 3110 | r = sd_dhcp_client_set_mac(link->dhcp_client, |
76253e73 DW |
3111 | (const uint8_t *) &link->mac, |
3112 | sizeof (link->mac), | |
3113 | ARPHRD_ETHER); | |
6a7a4e4d LP |
3114 | if (r < 0) |
3115 | return log_link_warning_errno(link, r, "Could not update MAC address in DHCP client: %m"); | |
413708d1 | 3116 | |
8341a5c3 ZJS |
3117 | r = sd_dhcp_client_set_iaid_duid(link->dhcp_client, |
3118 | link->network->iaid, | |
3119 | duid->type, | |
3120 | duid->raw_data_len > 0 ? duid->raw_data : NULL, | |
3121 | duid->raw_data_len); | |
413708d1 VK |
3122 | if (r < 0) |
3123 | return log_link_warning_errno(link, r, "Could not update DUID/IAID in DHCP client: %m"); | |
c49b33ac | 3124 | } |
4138fb2c PF |
3125 | |
3126 | if (link->dhcp6_client) { | |
8341a5c3 ZJS |
3127 | const DUID* duid = link_duid(link); |
3128 | ||
4138fb2c | 3129 | r = sd_dhcp6_client_set_mac(link->dhcp6_client, |
76253e73 DW |
3130 | (const uint8_t *) &link->mac, |
3131 | sizeof (link->mac), | |
3132 | ARPHRD_ETHER); | |
6a7a4e4d LP |
3133 | if (r < 0) |
3134 | return log_link_warning_errno(link, r, "Could not update MAC address in DHCPv6 client: %m"); | |
413708d1 VK |
3135 | |
3136 | r = sd_dhcp6_client_set_iaid(link->dhcp6_client, | |
3137 | link->network->iaid); | |
3138 | if (r < 0) | |
3139 | return log_link_warning_errno(link, r, "Could not update DHCPv6 IAID: %m"); | |
3140 | ||
8341a5c3 ZJS |
3141 | r = sd_dhcp6_client_set_duid(link->dhcp6_client, |
3142 | duid->type, | |
3143 | duid->raw_data_len > 0 ? duid->raw_data : NULL, | |
3144 | duid->raw_data_len); | |
413708d1 VK |
3145 | if (r < 0) |
3146 | return log_link_warning_errno(link, r, "Could not update DHCPv6 DUID: %m"); | |
4138fb2c | 3147 | } |
c49b33ac | 3148 | } |
4f882b2a TG |
3149 | } |
3150 | ||
a61bb41c TG |
3151 | had_carrier = link_has_carrier(link); |
3152 | ||
3153 | r = link_update_flags(link, m); | |
3154 | if (r < 0) | |
3155 | return r; | |
3156 | ||
273eec24 LP |
3157 | r = link_update_lldp(link); |
3158 | if (r < 0) | |
3159 | return r; | |
3160 | ||
a61bb41c TG |
3161 | carrier_gained = !had_carrier && link_has_carrier(link); |
3162 | carrier_lost = had_carrier && !link_has_carrier(link); | |
3163 | ||
3164 | if (carrier_gained) { | |
6a7a4e4d | 3165 | log_link_info(link, "Gained carrier"); |
a61bb41c | 3166 | |
9c0a72f9 TG |
3167 | r = link_carrier_gained(link); |
3168 | if (r < 0) | |
3169 | return r; | |
a61bb41c | 3170 | } else if (carrier_lost) { |
6a7a4e4d | 3171 | log_link_info(link, "Lost carrier"); |
a61bb41c | 3172 | |
9c0a72f9 TG |
3173 | r = link_carrier_lost(link); |
3174 | if (r < 0) | |
a61bb41c | 3175 | return r; |
a61bb41c TG |
3176 | } |
3177 | ||
3178 | return 0; | |
dd3efc09 | 3179 | } |
fe8db0c5 | 3180 | |
b295beea LP |
3181 | static void print_link_hashmap(FILE *f, const char *prefix, Hashmap* h) { |
3182 | bool space = false; | |
3183 | Iterator i; | |
3184 | Link *link; | |
3185 | ||
3186 | assert(f); | |
3187 | assert(prefix); | |
3188 | ||
3189 | if (hashmap_isempty(h)) | |
3190 | return; | |
3191 | ||
3192 | fputs(prefix, f); | |
3193 | HASHMAP_FOREACH(link, h, i) { | |
3194 | if (space) | |
3195 | fputc(' ', f); | |
3196 | ||
3197 | fprintf(f, "%i", link->ifindex); | |
3198 | space = true; | |
3199 | } | |
3200 | ||
3201 | fputc('\n', f); | |
3202 | } | |
3203 | ||
fe8db0c5 | 3204 | int link_save(Link *link) { |
68a8723c | 3205 | _cleanup_free_ char *temp_path = NULL; |
fe8db0c5 | 3206 | _cleanup_fclose_ FILE *f = NULL; |
e375dcde | 3207 | const char *admin_state, *oper_state; |
e7780c8d | 3208 | Address *a; |
c1eb9872 | 3209 | Route *route; |
e7780c8d | 3210 | Iterator i; |
fe8db0c5 TG |
3211 | int r; |
3212 | ||
3213 | assert(link); | |
3214 | assert(link->state_file); | |
68a8723c | 3215 | assert(link->lease_file); |
bbf7c048 TG |
3216 | assert(link->manager); |
3217 | ||
370e9930 TG |
3218 | if (link->state == LINK_STATE_LINGER) { |
3219 | unlink(link->state_file); | |
3220 | return 0; | |
3221 | } | |
3222 | ||
34437b4f LP |
3223 | link_lldp_save(link); |
3224 | ||
deb2e523 TG |
3225 | admin_state = link_state_to_string(link->state); |
3226 | assert(admin_state); | |
3227 | ||
e375dcde TG |
3228 | oper_state = link_operstate_to_string(link->operstate); |
3229 | assert(oper_state); | |
deb2e523 | 3230 | |
fe8db0c5 TG |
3231 | r = fopen_temporary(link->state_file, &f, &temp_path); |
3232 | if (r < 0) | |
6a7a4e4d | 3233 | goto fail; |
fe8db0c5 | 3234 | |
5512a963 | 3235 | (void) fchmod(fileno(f), 0644); |
fe8db0c5 TG |
3236 | |
3237 | fprintf(f, | |
3238 | "# This is private data. Do not parse.\n" | |
deb2e523 | 3239 | "ADMIN_STATE=%s\n" |
6dcaa6f5 TG |
3240 | "OPER_STATE=%s\n", |
3241 | admin_state, oper_state); | |
fe8db0c5 | 3242 | |
bcb7a07e | 3243 | if (link->network) { |
ea352b40 | 3244 | bool space; |
07bdc70d | 3245 | sd_dhcp6_lease *dhcp6_lease = NULL; |
b2a81c0b LP |
3246 | const char *dhcp_domainname = NULL; |
3247 | char **dhcp6_domains = NULL; | |
5512a963 | 3248 | unsigned j; |
07bdc70d PF |
3249 | |
3250 | if (link->dhcp6_client) { | |
4058d339 TG |
3251 | r = sd_dhcp6_client_get_lease(link->dhcp6_client, &dhcp6_lease); |
3252 | if (r < 0 && r != -ENOMSG) | |
07bdc70d PF |
3253 | log_link_debug(link, "No DHCPv6 lease"); |
3254 | } | |
b0e39c82 | 3255 | |
adc5b2e2 TG |
3256 | fprintf(f, "NETWORK_FILE=%s\n", link->network->filename); |
3257 | ||
b0e39c82 | 3258 | fputs("DNS=", f); |
ea352b40 | 3259 | space = false; |
5512a963 LP |
3260 | |
3261 | for (j = 0; j < link->network->n_dns; j++) { | |
3262 | _cleanup_free_ char *b = NULL; | |
3263 | ||
3264 | r = in_addr_to_string(link->network->dns[j].family, | |
3265 | &link->network->dns[j].address, &b); | |
3266 | if (r < 0) { | |
3267 | log_debug_errno(r, "Failed to format address, ignoring: %m"); | |
3268 | continue; | |
3269 | } | |
3270 | ||
3271 | if (space) | |
3272 | fputc(' ', f); | |
3273 | fputs(b, f); | |
3274 | space = true; | |
3275 | } | |
d5314fff | 3276 | |
27cb34f5 | 3277 | if (link->network->dhcp_use_dns && |
b0e39c82 TG |
3278 | link->dhcp_lease) { |
3279 | const struct in_addr *addresses; | |
3280 | ||
3281 | r = sd_dhcp_lease_get_dns(link->dhcp_lease, &addresses); | |
3282 | if (r > 0) { | |
ea352b40 LP |
3283 | if (space) |
3284 | fputc(' ', f); | |
b0e39c82 | 3285 | serialize_in_addrs(f, addresses, r); |
07bdc70d PF |
3286 | space = true; |
3287 | } | |
3288 | } | |
3289 | ||
27cb34f5 | 3290 | if (link->network->dhcp_use_dns && dhcp6_lease) { |
07bdc70d PF |
3291 | struct in6_addr *in6_addrs; |
3292 | ||
3293 | r = sd_dhcp6_lease_get_dns(dhcp6_lease, &in6_addrs); | |
3294 | if (r > 0) { | |
3295 | if (space) | |
3296 | fputc(' ', f); | |
3297 | serialize_in6_addrs(f, in6_addrs, r); | |
1e7a0e21 LP |
3298 | space = true; |
3299 | } | |
3300 | } | |
3301 | ||
3302 | /* Make sure to flush out old entries before we use the NDISC data */ | |
3303 | ndisc_vacuum(link); | |
3304 | ||
3305 | if (link->network->dhcp_use_dns && link->ndisc_rdnss) { | |
3306 | NDiscRDNSS *dd; | |
3307 | ||
3308 | SET_FOREACH(dd, link->ndisc_rdnss, i) { | |
3309 | if (space) | |
3310 | fputc(' ', f); | |
3311 | ||
3312 | serialize_in6_addrs(f, &dd->address, 1); | |
3313 | space = true; | |
b0e39c82 TG |
3314 | } |
3315 | } | |
3316 | ||
2ce40956 | 3317 | fputc('\n', f); |
b0e39c82 | 3318 | |
2ce40956 | 3319 | fputs("NTP=", f); |
ea352b40 | 3320 | space = false; |
3df9bec5 | 3321 | fputstrv(f, link->network->ntp, NULL, &space); |
d5314fff | 3322 | |
27cb34f5 | 3323 | if (link->network->dhcp_use_ntp && |
b0e39c82 TG |
3324 | link->dhcp_lease) { |
3325 | const struct in_addr *addresses; | |
3326 | ||
3327 | r = sd_dhcp_lease_get_ntp(link->dhcp_lease, &addresses); | |
3328 | if (r > 0) { | |
ea352b40 LP |
3329 | if (space) |
3330 | fputc(' ', f); | |
b0e39c82 | 3331 | serialize_in_addrs(f, addresses, r); |
07bdc70d PF |
3332 | space = true; |
3333 | } | |
3334 | } | |
3335 | ||
27cb34f5 | 3336 | if (link->network->dhcp_use_ntp && dhcp6_lease) { |
07bdc70d PF |
3337 | struct in6_addr *in6_addrs; |
3338 | char **hosts; | |
07bdc70d PF |
3339 | |
3340 | r = sd_dhcp6_lease_get_ntp_addrs(dhcp6_lease, | |
3341 | &in6_addrs); | |
3342 | if (r > 0) { | |
3343 | if (space) | |
3344 | fputc(' ', f); | |
3345 | serialize_in6_addrs(f, in6_addrs, r); | |
3346 | space = true; | |
3347 | } | |
3348 | ||
3349 | r = sd_dhcp6_lease_get_ntp_fqdn(dhcp6_lease, &hosts); | |
3df9bec5 LP |
3350 | if (r > 0) |
3351 | fputstrv(f, hosts, NULL, &space); | |
b0e39c82 TG |
3352 | } |
3353 | ||
2ce40956 | 3354 | fputc('\n', f); |
bd8f6538 | 3355 | |
b2a81c0b LP |
3356 | if (link->network->dhcp_use_domains != DHCP_USE_DOMAINS_NO) { |
3357 | if (link->dhcp_lease) | |
3358 | (void) sd_dhcp_lease_get_domainname(link->dhcp_lease, &dhcp_domainname); | |
b2a81c0b LP |
3359 | if (dhcp6_lease) |
3360 | (void) sd_dhcp6_lease_get_domains(dhcp6_lease, &dhcp6_domains); | |
07bdc70d PF |
3361 | } |
3362 | ||
b2a81c0b LP |
3363 | fputs("DOMAINS=", f); |
3364 | fputstrv(f, link->network->search_domains, NULL, &space); | |
07bdc70d | 3365 | |
1e7a0e21 LP |
3366 | if (link->network->dhcp_use_domains == DHCP_USE_DOMAINS_YES) { |
3367 | NDiscDNSSL *dd; | |
9b4d1882 | 3368 | |
1e7a0e21 LP |
3369 | if (dhcp_domainname) |
3370 | fputs_with_space(f, dhcp_domainname, NULL, &space); | |
3371 | if (dhcp6_domains) | |
3372 | fputstrv(f, dhcp6_domains, NULL, &space); | |
3373 | ||
3374 | SET_FOREACH(dd, link->ndisc_dnssl, i) | |
3375 | fputs_with_space(f, NDISC_DNSSL_DOMAIN(dd), NULL, &space); | |
3376 | } | |
b2a81c0b | 3377 | |
2ce40956 | 3378 | fputc('\n', f); |
6192b846 | 3379 | |
3df9bec5 LP |
3380 | fputs("ROUTE_DOMAINS=", f); |
3381 | fputstrv(f, link->network->route_domains, NULL, NULL); | |
b2a81c0b | 3382 | |
1e7a0e21 LP |
3383 | if (link->network->dhcp_use_domains == DHCP_USE_DOMAINS_ROUTE) { |
3384 | NDiscDNSSL *dd; | |
b2a81c0b | 3385 | |
1e7a0e21 LP |
3386 | if (dhcp_domainname) |
3387 | fputs_with_space(f, dhcp_domainname, NULL, &space); | |
3388 | if (dhcp6_domains) | |
3389 | fputstrv(f, dhcp6_domains, NULL, &space); | |
3390 | ||
3391 | SET_FOREACH(dd, link->ndisc_dnssl, i) | |
3392 | fputs_with_space(f, NDISC_DNSSL_DOMAIN(dd), NULL, &space); | |
3393 | } | |
b2a81c0b | 3394 | |
3df9bec5 | 3395 | fputc('\n', f); |
67272d15 | 3396 | |
3c9b8860 | 3397 | fprintf(f, "LLMNR=%s\n", |
a7e5da6e | 3398 | resolve_support_to_string(link->network->llmnr)); |
aaa297d4 LP |
3399 | fprintf(f, "MDNS=%s\n", |
3400 | resolve_support_to_string(link->network->mdns)); | |
e7780c8d | 3401 | |
ad6c0475 LP |
3402 | if (link->network->dnssec_mode != _DNSSEC_MODE_INVALID) |
3403 | fprintf(f, "DNSSEC=%s\n", | |
3404 | dnssec_mode_to_string(link->network->dnssec_mode)); | |
3405 | ||
8a516214 LP |
3406 | if (!set_isempty(link->network->dnssec_negative_trust_anchors)) { |
3407 | const char *n; | |
3408 | ||
3409 | fputs("DNSSEC_NTA=", f); | |
3410 | space = false; | |
d390f8ef LP |
3411 | SET_FOREACH(n, link->network->dnssec_negative_trust_anchors, i) |
3412 | fputs_with_space(f, n, NULL, &space); | |
8a516214 LP |
3413 | fputc('\n', f); |
3414 | } | |
3415 | ||
2ce40956 | 3416 | fputs("ADDRESSES=", f); |
e7780c8d TG |
3417 | space = false; |
3418 | SET_FOREACH(a, link->addresses, i) { | |
3419 | _cleanup_free_ char *address_str = NULL; | |
3420 | ||
3421 | r = in_addr_to_string(a->family, &a->in_addr, &address_str); | |
3422 | if (r < 0) | |
3423 | goto fail; | |
3424 | ||
e7780c8d TG |
3425 | fprintf(f, "%s%s/%u", space ? " " : "", address_str, a->prefixlen); |
3426 | space = true; | |
3427 | } | |
2ce40956 | 3428 | fputc('\n', f); |
c1eb9872 TG |
3429 | |
3430 | fputs("ROUTES=", f); | |
3431 | space = false; | |
3432 | SET_FOREACH(route, link->routes, i) { | |
3433 | _cleanup_free_ char *route_str = NULL; | |
3434 | ||
3435 | r = in_addr_to_string(route->family, &route->dst, &route_str); | |
3436 | if (r < 0) | |
3437 | goto fail; | |
3438 | ||
f833694d TG |
3439 | fprintf(f, "%s%s/%hhu/%hhu/%"PRIu32"/%hhu/"USEC_FMT, space ? " " : "", route_str, |
3440 | route->dst_prefixlen, route->tos, route->priority, route->table, route->lifetime); | |
c1eb9872 TG |
3441 | space = true; |
3442 | } | |
3443 | ||
3444 | fputc('\n', f); | |
bcb7a07e | 3445 | } |
7374f9d8 | 3446 | |
b295beea LP |
3447 | print_link_hashmap(f, "CARRIER_BOUND_TO=", link->bound_to_links); |
3448 | print_link_hashmap(f, "CARRIER_BOUND_BY=", link->bound_by_links); | |
0d4ad91d | 3449 | |
8eb9058d | 3450 | if (link->dhcp_lease) { |
0bc70f1d | 3451 | struct in_addr address; |
8eb9058d LP |
3452 | const char *tz = NULL; |
3453 | ||
0bc70f1d TG |
3454 | assert(link->network); |
3455 | ||
8eb9058d LP |
3456 | r = sd_dhcp_lease_get_timezone(link->dhcp_lease, &tz); |
3457 | if (r >= 0) | |
3458 | fprintf(f, "TIMEZONE=%s\n", tz); | |
8eb9058d | 3459 | |
0bc70f1d TG |
3460 | r = sd_dhcp_lease_get_address(link->dhcp_lease, &address); |
3461 | if (r >= 0) { | |
3462 | fputs("DHCP4_ADDRESS=", f); | |
3463 | serialize_in_addrs(f, &address, 1); | |
3464 | fputc('\n', f); | |
3465 | } | |
d9876a52 | 3466 | |
bd91b83e | 3467 | r = dhcp_lease_save(link->dhcp_lease, link->lease_file); |
fe8db0c5 | 3468 | if (r < 0) |
c2d6bd61 | 3469 | goto fail; |
fe8db0c5 | 3470 | |
7374f9d8 | 3471 | fprintf(f, |
b0e39c82 TG |
3472 | "DHCP_LEASE=%s\n", |
3473 | link->lease_file); | |
deb2e523 | 3474 | } else |
68a8723c | 3475 | unlink(link->lease_file); |
fe8db0c5 | 3476 | |
0bc70f1d TG |
3477 | if (link->ipv4ll) { |
3478 | struct in_addr address; | |
3479 | ||
3480 | r = sd_ipv4ll_get_address(link->ipv4ll, &address); | |
3481 | if (r >= 0) { | |
3482 | fputs("IPV4LL_ADDRESS=", f); | |
3483 | serialize_in_addrs(f, &address, 1); | |
3484 | fputc('\n', f); | |
3485 | } | |
3486 | } | |
3487 | ||
c2d6bd61 LP |
3488 | r = fflush_and_check(f); |
3489 | if (r < 0) | |
3490 | goto fail; | |
fe8db0c5 | 3491 | |
c2d6bd61 | 3492 | if (rename(temp_path, link->state_file) < 0) { |
fe8db0c5 | 3493 | r = -errno; |
c2d6bd61 | 3494 | goto fail; |
fe8db0c5 TG |
3495 | } |
3496 | ||
c2d6bd61 | 3497 | return 0; |
dacd6cee | 3498 | |
c2d6bd61 | 3499 | fail: |
6a7a4e4d | 3500 | (void) unlink(link->state_file); |
6a7a4e4d LP |
3501 | if (temp_path) |
3502 | (void) unlink(temp_path); | |
3503 | ||
dacd6cee | 3504 | return log_link_error_errno(link, r, "Failed to save link data to %s: %m", link->state_file); |
fe8db0c5 TG |
3505 | } |
3506 | ||
84de38c5 TG |
3507 | /* The serialized state in /run is no longer up-to-date. */ |
3508 | void link_dirty(Link *link) { | |
3509 | int r; | |
3510 | ||
3511 | assert(link); | |
3512 | ||
0c241a37 SS |
3513 | /* mark manager dirty as link is dirty */ |
3514 | manager_dirty(link->manager); | |
3515 | ||
84de38c5 TG |
3516 | r = set_ensure_allocated(&link->manager->dirty_links, NULL); |
3517 | if (r < 0) | |
3518 | /* allocation errors are ignored */ | |
3519 | return; | |
3520 | ||
3521 | r = set_put(link->manager->dirty_links, link); | |
0c241a37 SS |
3522 | if (r <= 0) |
3523 | /* don't take another ref if the link was already dirty */ | |
84de38c5 TG |
3524 | return; |
3525 | ||
3526 | link_ref(link); | |
3527 | } | |
3528 | ||
3529 | /* The serialized state in /run is up-to-date */ | |
3530 | void link_clean(Link *link) { | |
3531 | assert(link); | |
3532 | assert(link->manager); | |
3533 | ||
3534 | set_remove(link->manager->dirty_links, link); | |
3535 | link_unref(link); | |
3536 | } | |
3537 | ||
fe8db0c5 | 3538 | static const char* const link_state_table[_LINK_STATE_MAX] = { |
8434fd5c | 3539 | [LINK_STATE_PENDING] = "pending", |
fe8db0c5 TG |
3540 | [LINK_STATE_ENSLAVING] = "configuring", |
3541 | [LINK_STATE_SETTING_ADDRESSES] = "configuring", | |
3542 | [LINK_STATE_SETTING_ROUTES] = "configuring", | |
3543 | [LINK_STATE_CONFIGURED] = "configured", | |
57bd6899 | 3544 | [LINK_STATE_UNMANAGED] = "unmanaged", |
fe8db0c5 | 3545 | [LINK_STATE_FAILED] = "failed", |
370e9930 | 3546 | [LINK_STATE_LINGER] = "linger", |
fe8db0c5 TG |
3547 | }; |
3548 | ||
3549 | DEFINE_STRING_TABLE_LOOKUP(link_state, LinkState); | |
e375dcde TG |
3550 | |
3551 | static const char* const link_operstate_table[_LINK_OPERSTATE_MAX] = { | |
d3df0e39 TG |
3552 | [LINK_OPERSTATE_OFF] = "off", |
3553 | [LINK_OPERSTATE_NO_CARRIER] = "no-carrier", | |
e375dcde TG |
3554 | [LINK_OPERSTATE_DORMANT] = "dormant", |
3555 | [LINK_OPERSTATE_CARRIER] = "carrier", | |
3556 | [LINK_OPERSTATE_DEGRADED] = "degraded", | |
3557 | [LINK_OPERSTATE_ROUTABLE] = "routable", | |
3558 | }; | |
3559 | ||
3560 | DEFINE_STRING_TABLE_LOOKUP(link_operstate, LinkOperationalState); |