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