Lines Matching refs:link

18 static int get_link_default_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {  in get_link_default_handler()  argument
19 return link_getlink_handler_internal(rtnl, m, link, "Failed to sync link information"); in get_link_default_handler()
22 static int get_link_master_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) { in get_link_master_handler() argument
23 if (get_link_default_handler(rtnl, m, link) > 0) in get_link_master_handler()
24 link->master_set = true; in get_link_master_handler()
28 static int get_link_update_flag_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) { in get_link_update_flag_handler() argument
29 assert(link); in get_link_update_flag_handler()
30 assert(link->set_flags_messages > 0); in get_link_update_flag_handler()
32 link->set_flags_messages--; in get_link_update_flag_handler()
34 return get_link_default_handler(rtnl, m, link); in get_link_update_flag_handler()
41 Link *link, in set_link_handler_internal() argument
49 assert(link); in set_link_handler_internal()
56 log_link_message_warning_errno(link, m, r, error_msg); in set_link_handler_internal()
59 link_enter_failed(link); in set_link_handler_internal()
63 log_link_debug(link, "%s set.", request_type_to_string(req->type)); in set_link_handler_internal()
66 r = link_call_getlink(link, get_link_handler); in set_link_handler_internal()
68 link_enter_failed(link); in set_link_handler_internal()
73 if (link->set_link_messages == 0) in set_link_handler_internal()
74 link_check_ready(link); in set_link_handler_internal()
79 …n_mode_handler(sd_netlink *rtnl, sd_netlink_message *m, Request *req, Link *link, void *userdata) { in link_set_addrgen_mode_handler() argument
82 r = set_link_handler_internal(rtnl, m, req, link, /* ignore = */ true, NULL); in link_set_addrgen_mode_handler()
86 r = link_drop_ipv6ll_addresses(link); in link_set_addrgen_mode_handler()
88 log_link_warning_errno(link, r, "Failed to drop IPv6LL addresses: %m"); in link_set_addrgen_mode_handler()
89 link_enter_failed(link); in link_set_addrgen_mode_handler()
95 static int link_set_bond_handler(sd_netlink *rtnl, sd_netlink_message *m, Request *req, Link *link,… in link_set_bond_handler() argument
96 return set_link_handler_internal(rtnl, m, req, link, /* ignore = */ false, NULL); in link_set_bond_handler()
99 …bridge_handler(sd_netlink *rtnl, sd_netlink_message *m, Request *req, Link *link, void *userdata) { in link_set_bridge_handler() argument
100 return set_link_handler_internal(rtnl, m, req, link, /* ignore = */ true, NULL); in link_set_bridge_handler()
103 …e_vlan_handler(sd_netlink *rtnl, sd_netlink_message *m, Request *req, Link *link, void *userdata) { in link_set_bridge_vlan_handler() argument
104 return set_link_handler_internal(rtnl, m, req, link, /* ignore = */ false, NULL); in link_set_bridge_vlan_handler()
107 static int link_set_can_handler(sd_netlink *rtnl, sd_netlink_message *m, Request *req, Link *link, … in link_set_can_handler() argument
108 return set_link_handler_internal(rtnl, m, req, link, /* ignore = */ false, NULL); in link_set_can_handler()
111 static int link_set_flags_handler(sd_netlink *rtnl, sd_netlink_message *m, Request *req, Link *link in link_set_flags_handler() argument
112 …return set_link_handler_internal(rtnl, m, req, link, /* ignore = */ false, get_link_default_handle… in link_set_flags_handler()
115 static int link_set_group_handler(sd_netlink *rtnl, sd_netlink_message *m, Request *req, Link *link in link_set_group_handler() argument
116 return set_link_handler_internal(rtnl, m, req, link, /* ignore = */ false, NULL); in link_set_group_handler()
119 static int link_set_ipoib_handler(sd_netlink *rtnl, sd_netlink_message *m, Request *req, Link *link in link_set_ipoib_handler() argument
120 return set_link_handler_internal(rtnl, m, req, link, /* ignore = */ true, NULL); in link_set_ipoib_handler()
123 static int link_set_mac_handler(sd_netlink *rtnl, sd_netlink_message *m, Request *req, Link *link, … in link_set_mac_handler() argument
124 …return set_link_handler_internal(rtnl, m, req, link, /* ignore = */ true, get_link_default_handler… in link_set_mac_handler()
127 …_retry_handler(sd_netlink *rtnl, sd_netlink_message *m, Request *req, Link *link, void *userdata) { in link_set_mac_allow_retry_handler() argument
131 assert(link); in link_set_mac_allow_retry_handler()
139 … log_link_message_debug_errno(link, m, r, "Failed to set MAC address, retrying again: %m"); in link_set_mac_allow_retry_handler()
141 r = link_request_to_set_mac(link, /* allow_retry = */ false); in link_set_mac_allow_retry_handler()
143 link_enter_failed(link); in link_set_mac_allow_retry_handler()
148 return link_set_mac_handler(rtnl, m, req, link, userdata); in link_set_mac_allow_retry_handler()
151 …master_handler(sd_netlink *rtnl, sd_netlink_message *m, Request *req, Link *link, void *userdata) { in link_set_master_handler() argument
152 …return set_link_handler_internal(rtnl, m, req, link, /* ignore = */ false, get_link_master_handler… in link_set_master_handler()
155 …master_handler(sd_netlink *rtnl, sd_netlink_message *m, Request *req, Link *link, void *userdata) { in link_unset_master_handler() argument
157 …return set_link_handler_internal(rtnl, m, req, link, /* ignore = */ true, get_link_master_handler); in link_unset_master_handler()
160 static int link_set_mtu_handler(sd_netlink *rtnl, sd_netlink_message *m, Request *req, Link *link, … in link_set_mtu_handler() argument
163 … r = set_link_handler_internal(rtnl, m, req, link, /* ignore = */ true, get_link_default_handler); in link_set_mtu_handler()
169 r = link_set_ipv6_mtu(link); in link_set_mtu_handler()
171 log_link_warning_errno(link, r, "Failed to set IPv6 MTU, ignoring: %m"); in link_set_mtu_handler()
177 Link *link, in link_configure_fill_message() argument
202 if (link->network->active_slave) { in link_configure_fill_message()
203 … r = sd_netlink_message_append_u32(req, IFLA_BOND_ACTIVE_SLAVE, link->ifindex); in link_configure_fill_message()
208 if (link->network->primary_slave) { in link_configure_fill_message()
209 r = sd_netlink_message_append_u32(req, IFLA_BOND_PRIMARY, link->ifindex); in link_configure_fill_message()
232 if (link->network->use_bpdu >= 0) { in link_configure_fill_message()
233 … r = sd_netlink_message_append_u8(req, IFLA_BRPORT_GUARD, link->network->use_bpdu); in link_configure_fill_message()
238 if (link->network->hairpin >= 0) { in link_configure_fill_message()
239 … r = sd_netlink_message_append_u8(req, IFLA_BRPORT_MODE, link->network->hairpin); in link_configure_fill_message()
244 if (link->network->isolated >= 0) { in link_configure_fill_message()
245 … r = sd_netlink_message_append_u8(req, IFLA_BRPORT_ISOLATED, link->network->isolated); in link_configure_fill_message()
250 if (link->network->fast_leave >= 0) { in link_configure_fill_message()
251 … r = sd_netlink_message_append_u8(req, IFLA_BRPORT_FAST_LEAVE, link->network->fast_leave); in link_configure_fill_message()
256 if (link->network->allow_port_to_be_root >= 0) { in link_configure_fill_message()
257 … r = sd_netlink_message_append_u8(req, IFLA_BRPORT_PROTECT, link->network->allow_port_to_be_root); in link_configure_fill_message()
262 if (link->network->unicast_flood >= 0) { in link_configure_fill_message()
263 … r = sd_netlink_message_append_u8(req, IFLA_BRPORT_UNICAST_FLOOD, link->network->unicast_flood); in link_configure_fill_message()
268 if (link->network->multicast_flood >= 0) { in link_configure_fill_message()
269 … r = sd_netlink_message_append_u8(req, IFLA_BRPORT_MCAST_FLOOD, link->network->multicast_flood); in link_configure_fill_message()
274 if (link->network->multicast_to_unicast >= 0) { in link_configure_fill_message()
275 …r = sd_netlink_message_append_u8(req, IFLA_BRPORT_MCAST_TO_UCAST, link->network->multicast_to_unic… in link_configure_fill_message()
280 if (link->network->neighbor_suppression >= 0) { in link_configure_fill_message()
281 …r = sd_netlink_message_append_u8(req, IFLA_BRPORT_NEIGH_SUPPRESS, link->network->neighbor_suppress… in link_configure_fill_message()
286 if (link->network->learning >= 0) { in link_configure_fill_message()
287 … r = sd_netlink_message_append_u8(req, IFLA_BRPORT_LEARNING, link->network->learning); in link_configure_fill_message()
292 if (link->network->bridge_proxy_arp >= 0) { in link_configure_fill_message()
293 … r = sd_netlink_message_append_u8(req, IFLA_BRPORT_PROXYARP, link->network->bridge_proxy_arp); in link_configure_fill_message()
298 if (link->network->bridge_proxy_arp_wifi >= 0) { in link_configure_fill_message()
299 …r = sd_netlink_message_append_u8(req, IFLA_BRPORT_PROXYARP_WIFI, link->network->bridge_proxy_arp_w… in link_configure_fill_message()
304 if (link->network->cost != 0) { in link_configure_fill_message()
305 … r = sd_netlink_message_append_u32(req, IFLA_BRPORT_COST, link->network->cost); in link_configure_fill_message()
310 if (link->network->priority != LINK_BRIDGE_PORT_PRIORITY_INVALID) { in link_configure_fill_message()
311 … r = sd_netlink_message_append_u16(req, IFLA_BRPORT_PRIORITY, link->network->priority); in link_configure_fill_message()
316 if (link->network->multicast_router != _MULTICAST_ROUTER_INVALID) { in link_configure_fill_message()
317 …r = sd_netlink_message_append_u8(req, IFLA_BRPORT_MULTICAST_ROUTER, link->network->multicast_route… in link_configure_fill_message()
335 if (link->master_ifindex <= 0) { in link_configure_fill_message()
342 …r = bridge_vlan_append_info(link, req, link->network->pvid, link->network->br_vid_bitmap, link->ne… in link_configure_fill_message()
352 r = can_set_netlink_message(link, req); in link_configure_fill_message()
359 if (link->network->arp >= 0) { in link_configure_fill_message()
361 SET_FLAG(ifi_flags, IFF_NOARP, link->network->arp == 0); in link_configure_fill_message()
364 if (link->network->multicast >= 0) { in link_configure_fill_message()
366 SET_FLAG(ifi_flags, IFF_MULTICAST, link->network->multicast); in link_configure_fill_message()
369 if (link->network->allmulticast >= 0) { in link_configure_fill_message()
371 SET_FLAG(ifi_flags, IFF_ALLMULTI, link->network->allmulticast); in link_configure_fill_message()
374 if (link->network->promiscuous >= 0) { in link_configure_fill_message()
376 SET_FLAG(ifi_flags, IFF_PROMISC, link->network->promiscuous); in link_configure_fill_message()
386 r = sd_netlink_message_append_u32(req, IFLA_GROUP, (uint32_t) link->network->group); in link_configure_fill_message()
391 r = netlink_message_append_hw_addr(req, IFLA_ADDRESS, &link->requested_hw_addr); in link_configure_fill_message()
396 r = ipoib_set_netlink_message(link, req); in link_configure_fill_message()
417 static int link_configure(Link *link, Request *req) { in link_configure() argument
421 assert(link); in link_configure()
422 assert(link->manager); in link_configure()
425 log_link_debug(link, "Setting %s", request_type_to_string(req->type)); in link_configure()
428 … r = sd_rtnl_message_new_link(link->manager->rtnl, &m, RTM_NEWLINK, link->master_ifindex); in link_configure()
430 r = sd_rtnl_message_new_link(link->manager->rtnl, &m, RTM_NEWLINK, link->ifindex); in link_configure()
432 r = sd_rtnl_message_new_link(link->manager->rtnl, &m, RTM_SETLINK, link->ifindex); in link_configure()
436 r = link_configure_fill_message(link, m, req->type, req->userdata); in link_configure()
440 return request_call_netlink_async(link->manager->rtnl, m, req); in link_configure()
454 static int link_is_ready_to_set_link(Link *link, Request *req) { in link_is_ready_to_set_link() argument
457 assert(link); in link_is_ready_to_set_link()
458 assert(link->manager); in link_is_ready_to_set_link()
459 assert(link->network); in link_is_ready_to_set_link()
462 if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED)) in link_is_ready_to_set_link()
468 if (!link->master_set) in link_is_ready_to_set_link()
471 if (link->network->keep_master && link->master_ifindex <= 0) in link_is_ready_to_set_link()
476 if (!link->master_set) in link_is_ready_to_set_link()
479 … if (link->network->keep_master && link->master_ifindex <= 0 && !streq_ptr(link->kind, "bridge")) in link_is_ready_to_set_link()
487 if (FLAGS_SET(link->flags, IFF_UP)) { in link_is_ready_to_set_link()
489 r = link_down_now(link); in link_is_ready_to_set_link()
500 r = link_down_now(link); in link_is_ready_to_set_link()
509 .link = link, in link_is_ready_to_set_link()
513 if (link->network->batadv) { in link_is_ready_to_set_link()
514 if (!netdev_is_ready(link->network->batadv)) in link_is_ready_to_set_link()
516 m = link->network->batadv->ifindex; in link_is_ready_to_set_link()
517 } else if (link->network->bond) { in link_is_ready_to_set_link()
518 if (ordered_set_contains(link->manager->request_queue, &req_mac)) in link_is_ready_to_set_link()
520 if (!netdev_is_ready(link->network->bond)) in link_is_ready_to_set_link()
522 m = link->network->bond->ifindex; in link_is_ready_to_set_link()
526 if (FLAGS_SET(link->flags, IFF_UP)) { in link_is_ready_to_set_link()
528 r = link_down_now(link); in link_is_ready_to_set_link()
532 } else if (link->network->bridge) { in link_is_ready_to_set_link()
533 if (ordered_set_contains(link->manager->request_queue, &req_mac)) in link_is_ready_to_set_link()
535 if (!netdev_is_ready(link->network->bridge)) in link_is_ready_to_set_link()
537 m = link->network->bridge->ifindex; in link_is_ready_to_set_link()
538 } else if (link->network->vrf) { in link_is_ready_to_set_link()
539 if (!netdev_is_ready(link->network->vrf)) in link_is_ready_to_set_link()
541 m = link->network->vrf->ifindex; in link_is_ready_to_set_link()
549 .link = link, in link_is_ready_to_set_link()
553 return !ordered_set_contains(link->manager->request_queue, &req_ipoib); in link_is_ready_to_set_link()
562 static int link_process_set_link(Request *req, Link *link, void *userdata) { in link_process_set_link() argument
566 assert(link); in link_process_set_link()
568 r = link_is_ready_to_set_link(link, req); in link_process_set_link()
572 r = link_configure(link, req); in link_process_set_link()
574 … return log_link_warning_errno(link, r, "Failed to set %s", request_type_to_string(req->type)); in link_process_set_link()
580 Link *link, in link_request_set_link() argument
588 assert(link); in link_request_set_link()
590 r = link_queue_request_full(link, type, NULL, NULL, NULL, NULL, in link_request_set_link()
592 &link->set_link_messages, in link_request_set_link()
596 return log_link_warning_errno(link, r, "Failed to request to set %s: %m", in link_request_set_link()
599 log_link_debug(link, "Requested to set %s", request_type_to_string(type)); in link_request_set_link()
606 int link_request_to_set_addrgen_mode(Link *link) { in link_request_to_set_addrgen_mode() argument
611 assert(link); in link_request_to_set_addrgen_mode()
612 assert(link->network); in link_request_to_set_addrgen_mode()
617 mode = link_get_ipv6ll_addrgen_mode(link); in link_request_to_set_addrgen_mode()
619 if (mode == link->ipv6ll_address_gen_mode) in link_request_to_set_addrgen_mode()
627 FLAGS_SET(link->flags, IFF_UP)) { in link_request_to_set_addrgen_mode()
628 r = link_set_ipv6ll_addrgen_mode(link, mode); in link_request_to_set_addrgen_mode()
630 … log_link_warning_errno(link, r, "Cannot set IPv6 address generation mode, ignoring: %m"); in link_request_to_set_addrgen_mode()
635 r = link_request_set_link(link, REQUEST_TYPE_SET_LINK_ADDRESS_GENERATION_MODE, in link_request_to_set_addrgen_mode()
645 int link_request_to_set_bond(Link *link) { in link_request_to_set_bond() argument
646 assert(link); in link_request_to_set_bond()
647 assert(link->network); in link_request_to_set_bond()
649 if (!link->network->bond) { in link_request_to_set_bond()
652 if (!link->network->keep_master) in link_request_to_set_bond()
655 if (link_get_master(link, &master) < 0) in link_request_to_set_bond()
662 return link_request_set_link(link, REQUEST_TYPE_SET_LINK_BOND, in link_request_to_set_bond()
666 int link_request_to_set_bridge(Link *link) { in link_request_to_set_bridge() argument
667 assert(link); in link_request_to_set_bridge()
668 assert(link->network); in link_request_to_set_bridge()
670 if (!link->network->bridge) { in link_request_to_set_bridge()
673 if (!link->network->keep_master) in link_request_to_set_bridge()
676 if (link_get_master(link, &master) < 0) in link_request_to_set_bridge()
683 return link_request_set_link(link, REQUEST_TYPE_SET_LINK_BRIDGE, in link_request_to_set_bridge()
688 int link_request_to_set_bridge_vlan(Link *link) { in link_request_to_set_bridge_vlan() argument
689 assert(link); in link_request_to_set_bridge_vlan()
690 assert(link->network); in link_request_to_set_bridge_vlan()
692 if (!link->network->use_br_vlan) in link_request_to_set_bridge_vlan()
695 if (!link->network->bridge && !streq_ptr(link->kind, "bridge")) { in link_request_to_set_bridge_vlan()
698 if (!link->network->keep_master) in link_request_to_set_bridge_vlan()
701 if (link_get_master(link, &master) < 0) in link_request_to_set_bridge_vlan()
708 return link_request_set_link(link, REQUEST_TYPE_SET_LINK_BRIDGE_VLAN, in link_request_to_set_bridge_vlan()
713 int link_request_to_set_can(Link *link) { in link_request_to_set_can() argument
714 assert(link); in link_request_to_set_can()
715 assert(link->network); in link_request_to_set_can()
717 if (link->iftype != ARPHRD_CAN) in link_request_to_set_can()
720 if (!streq_ptr(link->kind, "can")) in link_request_to_set_can()
723 return link_request_set_link(link, REQUEST_TYPE_SET_LINK_CAN, in link_request_to_set_can()
728 int link_request_to_set_flags(Link *link) { in link_request_to_set_flags() argument
729 assert(link); in link_request_to_set_flags()
730 assert(link->network); in link_request_to_set_flags()
732 if (link->network->arp < 0 && in link_request_to_set_flags()
733 link->network->multicast < 0 && in link_request_to_set_flags()
734 link->network->allmulticast < 0 && in link_request_to_set_flags()
735 link->network->promiscuous < 0) in link_request_to_set_flags()
738 return link_request_set_link(link, REQUEST_TYPE_SET_LINK_FLAGS, in link_request_to_set_flags()
743 int link_request_to_set_group(Link *link) { in link_request_to_set_group() argument
744 assert(link); in link_request_to_set_group()
745 assert(link->network); in link_request_to_set_group()
747 if (link->network->group < 0) in link_request_to_set_group()
750 return link_request_set_link(link, REQUEST_TYPE_SET_LINK_GROUP, in link_request_to_set_group()
755 int link_request_to_set_mac(Link *link, bool allow_retry) { in link_request_to_set_mac() argument
758 assert(link); in link_request_to_set_mac()
759 assert(link->network); in link_request_to_set_mac()
761 if (link->network->hw_addr.length == 0) in link_request_to_set_mac()
764 link->requested_hw_addr = link->network->hw_addr; in link_request_to_set_mac()
765 r = net_verify_hardware_address(link->ifname, /* is_static = */ true, in link_request_to_set_mac()
766 link->iftype, &link->hw_addr, &link->requested_hw_addr); in link_request_to_set_mac()
770 if (hw_addr_equal(&link->hw_addr, &link->requested_hw_addr)) in link_request_to_set_mac()
773 return link_request_set_link(link, REQUEST_TYPE_SET_LINK_MAC, in link_request_to_set_mac()
778 int link_request_to_set_ipoib(Link *link) { in link_request_to_set_ipoib() argument
779 assert(link); in link_request_to_set_ipoib()
780 assert(link->network); in link_request_to_set_ipoib()
782 if (link->iftype != ARPHRD_INFINIBAND) in link_request_to_set_ipoib()
785 if (link->network->ipoib_mode < 0 && in link_request_to_set_ipoib()
786 link->network->ipoib_umcast < 0) in link_request_to_set_ipoib()
789 return link_request_set_link(link, REQUEST_TYPE_SET_LINK_IPOIB, in link_request_to_set_ipoib()
794 int link_request_to_set_master(Link *link) { in link_request_to_set_master() argument
795 assert(link); in link_request_to_set_master()
796 assert(link->network); in link_request_to_set_master()
798 if (link->network->keep_master) { in link_request_to_set_master()
799 link->master_set = true; in link_request_to_set_master()
803 link->master_set = false; in link_request_to_set_master()
805 … if (link->network->batadv || link->network->bond || link->network->bridge || link->network->vrf) in link_request_to_set_master()
806 return link_request_set_link(link, REQUEST_TYPE_SET_LINK_MASTER, in link_request_to_set_master()
810 return link_request_set_link(link, REQUEST_TYPE_SET_LINK_MASTER, in link_request_to_set_master()
815 int link_request_to_set_mtu(Link *link, uint32_t mtu) { in link_request_to_set_mtu() argument
821 assert(link); in link_request_to_set_mtu()
822 assert(link->network); in link_request_to_set_mtu()
824 min_mtu = link->min_mtu; in link_request_to_set_mtu()
826 if (link_ipv6_enabled(link)) { in link_request_to_set_mtu()
833 if (min_mtu < link->network->ipv6_mtu) { in link_request_to_set_mtu()
834 min_mtu = link->network->ipv6_mtu; in link_request_to_set_mtu()
840 log_link_warning(link, "Bumping the requested MTU %"PRIu32" to %s (%"PRIu32")", in link_request_to_set_mtu()
845 if (mtu > link->max_mtu) { in link_request_to_set_mtu()
846 …log_link_warning(link, "Reducing the requested MTU %"PRIu32" to the interface's maximum MTU %"PRIu… in link_request_to_set_mtu()
847 mtu, link->max_mtu); in link_request_to_set_mtu()
848 mtu = link->max_mtu; in link_request_to_set_mtu()
851 if (link->mtu == mtu) in link_request_to_set_mtu()
854 r = link_request_set_link(link, REQUEST_TYPE_SET_LINK_MTU, in link_request_to_set_mtu()
864 static bool link_reduces_vlan_mtu(Link *link) { in link_reduces_vlan_mtu() argument
866 return streq_ptr(link->kind, "macsec"); in link_reduces_vlan_mtu()
869 static uint32_t link_get_requested_mtu_by_stacked_netdevs(Link *link) { in link_get_requested_mtu_by_stacked_netdevs() argument
873 HASHMAP_FOREACH(dev, link->network->stacked_netdevs) in link_get_requested_mtu_by_stacked_netdevs()
876 mtu = MAX(mtu, link_reduces_vlan_mtu(link) ? dev->mtu + 4 : dev->mtu); in link_get_requested_mtu_by_stacked_netdevs()
885 int link_configure_mtu(Link *link) { in link_configure_mtu() argument
888 assert(link); in link_configure_mtu()
889 assert(link->network); in link_configure_mtu()
891 if (link->network->mtu > 0) in link_configure_mtu()
892 return link_request_to_set_mtu(link, link->network->mtu); in link_configure_mtu()
894 mtu = link_get_requested_mtu_by_stacked_netdevs(link); in link_configure_mtu()
895 if (link->mtu >= mtu) in link_configure_mtu()
898 … log_link_notice(link, "Bumping MTU bytes from %"PRIu32" to %"PRIu32" because of stacked device. " in link_configure_mtu()
900 link->mtu, mtu); in link_configure_mtu()
902 return link_request_to_set_mtu(link, mtu); in link_configure_mtu()
905 static int link_up_dsa_slave(Link *link) { in link_up_dsa_slave() argument
909 assert(link); in link_up_dsa_slave()
916 if (link->dsa_master_ifindex <= 0) in link_up_dsa_slave()
919 if (!streq_ptr(link->driver, "dsa")) in link_up_dsa_slave()
922 if (link_get_by_index(link->manager, link->dsa_master_ifindex, &master) < 0) in link_up_dsa_slave()
933 r = link_request_to_bring_up_or_down(link, /* up = */ true); in link_up_dsa_slave()
940 …r_down_handler(sd_netlink *rtnl, sd_netlink_message *m, Request *req, Link *link, void *userdata) { in link_up_or_down_handler() argument
946 assert(link); in link_up_or_down_handler()
952 if (r == -ENETDOWN && up && link_up_dsa_slave(link) > 0) in link_up_or_down_handler()
953 …log_link_message_debug_errno(link, m, r, "Could not bring up dsa slave, retrying again after dsa m… in link_up_or_down_handler()
961 log_link_message_warning_errno(link, m, r, error_msg); in link_up_or_down_handler()
966 r = link_call_getlink(link, get_link_update_flag_handler); in link_up_or_down_handler()
968 link_enter_failed(link); in link_up_or_down_handler()
972 link->set_flags_messages++; in link_up_or_down_handler()
975 link->activated = true; in link_up_or_down_handler()
976 link_check_ready(link); in link_up_or_down_handler()
986 static int link_up_or_down(Link *link, bool up, Request *req) { in link_up_or_down() argument
990 assert(link); in link_up_or_down()
991 assert(link->manager); in link_up_or_down()
992 assert(link->manager->rtnl); in link_up_or_down()
995 log_link_debug(link, "Bringing link %s", up_or_down(up)); in link_up_or_down()
997 r = sd_rtnl_message_new_link(link->manager->rtnl, &m, RTM_SETLINK, link->ifindex); in link_up_or_down()
1005 return request_call_netlink_async(link->manager->rtnl, m, req); in link_up_or_down()
1008 static bool link_is_ready_to_activate(Link *link) { in link_is_ready_to_activate() argument
1009 assert(link); in link_is_ready_to_activate()
1011 if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED)) in link_is_ready_to_activate()
1014 if (link->set_link_messages > 0) in link_is_ready_to_activate()
1020 static int link_process_activation(Request *req, Link *link, void *userdata) { in link_process_activation() argument
1025 assert(link); in link_process_activation()
1027 if (!link_is_ready_to_activate(link)) in link_process_activation()
1030 r = link_up_or_down(link, up, req); in link_process_activation()
1032 return log_link_warning_errno(link, r, "Failed to activate link: %m"); in link_process_activation()
1037 int link_request_to_activate(Link *link) { in link_request_to_activate() argument
1041 assert(link); in link_request_to_activate()
1042 assert(link->network); in link_request_to_activate()
1044 switch (link->network->activation_policy) { in link_request_to_activate()
1046 r = link_handle_bound_to_list(link); in link_request_to_activate()
1051 link->activated = true; in link_request_to_activate()
1052 link_check_ready(link); in link_request_to_activate()
1066 link->activated = false; in link_request_to_activate()
1068 r = link_queue_request_full(link, REQUEST_TYPE_ACTIVATE_LINK, in link_request_to_activate()
1071 &link->set_flags_messages, in link_request_to_activate()
1074 return log_link_error_errno(link, r, "Failed to request to activate link: %m"); in link_request_to_activate()
1076 log_link_debug(link, "Requested to activate link"); in link_request_to_activate()
1080 static bool link_is_ready_to_bring_up_or_down(Link *link, bool up) { in link_is_ready_to_bring_up_or_down() argument
1081 assert(link); in link_is_ready_to_bring_up_or_down()
1083 if (up && link->dsa_master_ifindex > 0) { in link_is_ready_to_bring_up_or_down()
1088 if (link_get_by_index(link->manager, link->dsa_master_ifindex, &master) < 0) in link_is_ready_to_bring_up_or_down()
1095 if (link->state == LINK_STATE_UNMANAGED) in link_is_ready_to_bring_up_or_down()
1098 if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED)) in link_is_ready_to_bring_up_or_down()
1101 if (link->set_link_messages > 0) in link_is_ready_to_bring_up_or_down()
1104 if (!link->activated) in link_is_ready_to_bring_up_or_down()
1110 static int link_process_up_or_down(Request *req, Link *link, void *userdata) { in link_process_up_or_down() argument
1115 assert(link); in link_process_up_or_down()
1117 if (!link_is_ready_to_bring_up_or_down(link, up)) in link_process_up_or_down()
1120 r = link_up_or_down(link, up, req); in link_process_up_or_down()
1122 … return log_link_warning_errno(link, r, "Failed to bring link %s: %m", up_or_down(up)); in link_process_up_or_down()
1127 int link_request_to_bring_up_or_down(Link *link, bool up) { in link_request_to_bring_up_or_down() argument
1130 assert(link); in link_request_to_bring_up_or_down()
1132 r = link_queue_request_full(link, REQUEST_TYPE_UP_DOWN, in link_request_to_bring_up_or_down()
1135 &link->set_flags_messages, in link_request_to_bring_up_or_down()
1138 return log_link_warning_errno(link, r, "Failed to request to bring link %s: %m", in link_request_to_bring_up_or_down()
1141 log_link_debug(link, "Requested to bring link %s", up_or_down(up)); in link_request_to_bring_up_or_down()
1145 static int link_down_now_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) { in link_down_now_handler() argument
1149 assert(link); in link_down_now_handler()
1150 assert(link->set_flags_messages > 0); in link_down_now_handler()
1152 link->set_flags_messages--; in link_down_now_handler()
1154 if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) in link_down_now_handler()
1159 … log_link_message_warning_errno(link, m, r, "Could not bring down interface, ignoring"); in link_down_now_handler()
1161 r = link_call_getlink(link, get_link_update_flag_handler); in link_down_now_handler()
1163 link_enter_failed(link); in link_down_now_handler()
1167 link->set_flags_messages++; in link_down_now_handler()
1171 int link_down_now(Link *link) { in link_down_now() argument
1175 assert(link); in link_down_now()
1176 assert(link->manager); in link_down_now()
1177 assert(link->manager->rtnl); in link_down_now()
1179 log_link_debug(link, "Bringing link down"); in link_down_now()
1181 r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_SETLINK, link->ifindex); in link_down_now()
1183 … return log_link_warning_errno(link, r, "Could not allocate RTM_SETLINK message: %m"); in link_down_now()
1187 return log_link_warning_errno(link, r, "Could not set link flags: %m"); in link_down_now()
1189 r = netlink_call_async(link->manager->rtnl, NULL, req, link_down_now_handler, in link_down_now()
1190 link_netlink_destroy_callback, link); in link_down_now()
1192 return log_link_warning_errno(link, r, "Could not send rtnetlink message: %m"); in link_down_now()
1194 link->set_flags_messages++; in link_down_now()
1195 link_ref(link); in link_down_now()
1199 static int link_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) { in link_remove_handler() argument
1203 assert(link); in link_remove_handler()
1205 if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) in link_remove_handler()
1210 log_link_message_warning_errno(link, m, r, "Could not remove interface, ignoring"); in link_remove_handler()
1215 int link_remove(Link *link) { in link_remove() argument
1219 assert(link); in link_remove()
1220 assert(link->manager); in link_remove()
1221 assert(link->manager->rtnl); in link_remove()
1223 log_link_debug(link, "Removing link."); in link_remove()
1225 r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_DELLINK, link->ifindex); in link_remove()
1227 return log_link_debug_errno(link, r, "Could not allocate RTM_DELLINK message: %m"); in link_remove()
1229 r = netlink_call_async(link->manager->rtnl, NULL, req, link_remove_handler, in link_remove()
1230 link_netlink_destroy_callback, link); in link_remove()
1232 return log_link_debug_errno(link, r, "Could not send rtnetlink message: %m"); in link_remove()
1234 link_ref(link); in link_remove()