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