Lines Matching refs:link
359 Link *link_free(Link *link) { in link_free() argument
360 if (!link) in link_free()
363 sd_device_unref(link->device); in link_free()
364 free(link->kind); in link_free()
365 free(link->driver); in link_free()
366 return mfree(link); in link_free()
370 _cleanup_(link_freep) Link *link = NULL; in link_new()
378 link = new(Link, 1); in link_new()
379 if (!link) in link_new()
382 *link = (Link) { in link_new()
386 r = sd_device_get_sysname(device, &link->ifname); in link_new()
390 r = sd_device_get_ifindex(device, &link->ifindex); in link_new()
394 r = sd_device_get_action(device, &link->action); in link_new()
398 r = device_unsigned_attribute(device, "name_assign_type", &link->name_assign_type); in link_new()
400 … log_link_debug_errno(link, r, "Failed to get \"name_assign_type\" attribute, ignoring: %m"); in link_new()
402 r = device_unsigned_attribute(device, "addr_assign_type", &link->addr_assign_type); in link_new()
404 … log_link_debug_errno(link, r, "Failed to get \"addr_assign_type\" attribute, ignoring: %m"); in link_new()
406 r = rtnl_get_link_info(rtnl, link->ifindex, &link->iftype, &link->flags, in link_new()
407 &link->kind, &link->hw_addr, &link->permanent_hw_addr); in link_new()
411 if (link->hw_addr.length > 0 && link->permanent_hw_addr.length == 0) { in link_new()
412 … r = ethtool_get_permanent_hw_addr(&ctx->ethtool_fd, link->ifname, &link->permanent_hw_addr); in link_new()
414 … log_link_debug_errno(link, r, "Failed to get permanent hardware address, ignoring: %m"); in link_new()
417 r = ethtool_get_driver(&ctx->ethtool_fd, link->ifname, &link->driver); in link_new()
419 log_link_debug_errno(link, r, "Failed to get driver, ignoring: %m"); in link_new()
421 *ret = TAKE_PTR(link); in link_new()
425 int link_get_config(LinkConfigContext *ctx, Link *link) { in link_get_config() argument
429 assert(link); in link_get_config()
432 if (link->flags & IFF_LOOPBACK) in link_get_config()
438 link->device, in link_get_config()
439 &link->hw_addr, in link_get_config()
440 &link->permanent_hw_addr, in link_get_config()
441 link->driver, in link_get_config()
442 link->iftype, in link_get_config()
443 link->kind, in link_get_config()
444 link->ifname, in link_get_config()
454 …if (config->match.ifname && !strv_contains(config->match.ifname, "*") && link->name_assign_type ==… in link_get_config()
455 …log_link_warning(link, "Config file %s is applied to device based on potentially unpredictable int… in link_get_config()
458 log_link_debug(link, "Config file %s is applied", config->filename); in link_get_config()
460 link->config = config; in link_get_config()
467 static int link_apply_ethtool_settings(Link *link, int *ethtool_fd) { in link_apply_ethtool_settings() argument
472 assert(link); in link_apply_ethtool_settings()
473 assert(link->config); in link_apply_ethtool_settings()
476 config = link->config; in link_apply_ethtool_settings()
477 name = link->ifname; in link_apply_ethtool_settings()
484 … log_link_warning_errno(link, r, "Could not %s auto negotiation, ignoring: %m", in link_apply_ethtool_settings()
488 … log_link_warning_errno(link, r, "Could not set advertise mode, ignoring: %m"); in link_apply_ethtool_settings()
491 … log_link_warning_errno(link, r, "Could not set speed to %"PRIu64"Mbps, ignoring: %m", in link_apply_ethtool_settings()
495 log_link_warning_errno(link, r, "Could not set duplex to %s, ignoring: %m", in link_apply_ethtool_settings()
499 log_link_warning_errno(link, r, "Could not set port to '%s', ignoring: %m", in link_apply_ethtool_settings()
503 log_link_warning_errno(link, r, "Could not set MDI-X to '%s', ignoring: %m", in link_apply_ethtool_settings()
512 log_link_warning_errno(link, r, "Could not set WakeOnLan%s%s, ignoring: %m", in link_apply_ethtool_settings()
518 log_link_warning_errno(link, r, "Could not set offload features, ignoring: %m"); in link_apply_ethtool_settings()
522 log_link_warning_errno(link, r, "Could not set channels, ignoring: %m"); in link_apply_ethtool_settings()
526 log_link_warning_errno(link, r, "Could not set ring buffer, ignoring: %m"); in link_apply_ethtool_settings()
530 log_link_warning_errno(link, r, "Could not set flow control, ignoring: %m"); in link_apply_ethtool_settings()
534 log_link_warning_errno(link, r, "Could not set coalesce settings, ignoring: %m"); in link_apply_ethtool_settings()
539 static bool hw_addr_is_valid(Link *link, const struct hw_addr_data *hw_addr) { in hw_addr_is_valid() argument
540 assert(link); in hw_addr_is_valid()
543 switch (link->iftype) { in hw_addr_is_valid()
559 static int link_generate_new_hw_addr(Link *link, struct hw_addr_data *ret) { in link_generate_new_hw_addr() argument
566 assert(link); in link_generate_new_hw_addr()
567 assert(link->config); in link_generate_new_hw_addr()
568 assert(link->device); in link_generate_new_hw_addr()
571 if (link->hw_addr.length == 0) in link_generate_new_hw_addr()
574 if (link->config->mac_address_policy == MAC_ADDRESS_POLICY_NONE) { in link_generate_new_hw_addr()
575 log_link_debug(link, "Using static MAC address."); in link_generate_new_hw_addr()
576 hw_addr = link->config->hw_addr; in link_generate_new_hw_addr()
581 if (!IN_SET(link->iftype, ARPHRD_ETHER, ARPHRD_INFINIBAND)) in link_generate_new_hw_addr()
584 switch (link->addr_assign_type) { in link_generate_new_hw_addr()
586 log_link_debug(link, "MAC address on the device already set by userspace."); in link_generate_new_hw_addr()
589 … log_link_debug(link, "MAC address on the device already set based on another device."); in link_generate_new_hw_addr()
595 … log_link_warning(link, "Unknown addr_assign_type %u, ignoring", link->addr_assign_type); in link_generate_new_hw_addr()
599 …if ((link->config->mac_address_policy == MAC_ADDRESS_POLICY_RANDOM) == (link->addr_assign_type == … in link_generate_new_hw_addr()
600 log_link_debug(link, "MAC address on the device already matches policy \"%s\".", in link_generate_new_hw_addr()
601 mac_address_policy_to_string(link->config->mac_address_policy)); in link_generate_new_hw_addr()
606 .length = arphrd_to_hw_addr_len(link->iftype), in link_generate_new_hw_addr()
609 switch (link->iftype) { in link_generate_new_hw_addr()
622 if (link->config->mac_address_policy == MAC_ADDRESS_POLICY_RANDOM) in link_generate_new_hw_addr()
628 …return log_link_warning_errno(link, r, "Failed to acquire random data to generate MAC address: %m"… in link_generate_new_hw_addr()
630 if (hw_addr_is_valid(link, &hw_addr)) in link_generate_new_hw_addr()
637 r = net_get_unique_predictable_data(link->device, in link_generate_new_hw_addr()
641 … return log_link_warning_errno(link, r, "Could not generate persistent MAC address: %m"); in link_generate_new_hw_addr()
645 if (!hw_addr_is_valid(link, &hw_addr)) in link_generate_new_hw_addr()
646 return log_link_warning_errno(link, SYNTHETIC_ERRNO(EINVAL), in link_generate_new_hw_addr()
652 … r = net_verify_hardware_address(link->ifname, is_static, link->iftype, &link->hw_addr, &hw_addr); in link_generate_new_hw_addr()
656 if (hw_addr_equal(&link->hw_addr, &hw_addr)) { in link_generate_new_hw_addr()
662 log_link_debug(link, "Applying %s MAC address: %s", in link_generate_new_hw_addr()
663 … link->config->mac_address_policy == MAC_ADDRESS_POLICY_NONE ? "static" : in link_generate_new_hw_addr()
664 mac_address_policy_to_string(link->config->mac_address_policy), in link_generate_new_hw_addr()
671 static int link_apply_rtnl_settings(Link *link, sd_netlink **rtnl) { in link_apply_rtnl_settings() argument
676 assert(link); in link_apply_rtnl_settings()
677 assert(link->config); in link_apply_rtnl_settings()
680 config = link->config; in link_apply_rtnl_settings()
682 (void) link_generate_new_hw_addr(link, &hw_addr); in link_apply_rtnl_settings()
684 r = rtnl_set_link_properties(rtnl, link->ifindex, config->alias, &hw_addr, in link_apply_rtnl_settings()
688 log_link_warning_errno(link, r, in link_apply_rtnl_settings()
717 static int link_generate_new_name(Link *link) { in link_generate_new_name() argument
721 assert(link); in link_generate_new_name()
722 assert(link->config); in link_generate_new_name()
723 assert(link->device); in link_generate_new_name()
725 config = link->config; in link_generate_new_name()
726 device = link->device; in link_generate_new_name()
728 if (link->action == SD_DEVICE_MOVE) { in link_generate_new_name()
729 log_link_debug(link, "Skipping to apply Name= and NamePolicy= on '%s' uevent.", in link_generate_new_name()
730 device_action_to_string(link->action)); in link_generate_new_name()
734 if (IN_SET(link->name_assign_type, NET_NAME_USER, NET_NAME_RENAMED) && in link_generate_new_name()
736 log_link_debug(link, "Device already has a name given by userspace, not renaming."); in link_generate_new_name()
746 if (link->name_assign_type != NET_NAME_PREDICTABLE) in link_generate_new_name()
750 log_link_debug(link, "Policy *%s*: keeping predictable kernel name", in link_generate_new_name()
754 … if (!IN_SET(link->name_assign_type, NET_NAME_USER, NET_NAME_RENAMED)) in link_generate_new_name()
757 log_link_debug(link, "Policy *%s*: keeping existing userspace name", in link_generate_new_name()
779 … log_link_debug(link, "Policy *%s* yields \"%s\".", name_policy_to_string(*policy), new_name); in link_generate_new_name()
780 link->new_name = new_name; in link_generate_new_name()
785 if (link->config->name) { in link_generate_new_name()
786 …log_link_debug(link, "Policies didn't yield a name, using specified Name=%s.", link->config->name); in link_generate_new_name()
787 link->new_name = link->config->name; in link_generate_new_name()
791 log_link_debug(link, "Policies didn't yield a name and Name= is not given, not renaming."); in link_generate_new_name()
793 link->new_name = link->ifname; in link_generate_new_name()
797 static int link_apply_alternative_names(Link *link, sd_netlink **rtnl) { in link_apply_alternative_names() argument
803 assert(link); in link_apply_alternative_names()
804 assert(link->config); in link_apply_alternative_names()
805 assert(link->device); in link_apply_alternative_names()
808 config = link->config; in link_apply_alternative_names()
809 device = link->device; in link_apply_alternative_names()
847 if (link->new_name) in link_apply_alternative_names()
848 strv_remove(altnames, link->new_name); in link_apply_alternative_names()
849 strv_remove(altnames, link->ifname); in link_apply_alternative_names()
851 r = rtnl_get_link_alternative_names(rtnl, link->ifindex, ¤t_altnames); in link_apply_alternative_names()
853 log_link_debug_errno(link, r, "Failed to get alternative names, ignoring: %m"); in link_apply_alternative_names()
860 r = rtnl_set_link_alternative_names(rtnl, link->ifindex, altnames); in link_apply_alternative_names()
862 log_link_full_errno(link, r == -EOPNOTSUPP ? LOG_DEBUG : LOG_WARNING, r, in link_apply_alternative_names()
868 static int sr_iov_configure(Link *link, sd_netlink **rtnl, SRIOV *sr_iov) { in sr_iov_configure() argument
872 assert(link); in sr_iov_configure()
874 assert(link->ifindex > 0); in sr_iov_configure()
882 r = sd_rtnl_message_new_link(*rtnl, &req, RTM_SETLINK, link->ifindex); in sr_iov_configure()
897 static int link_apply_sr_iov_config(Link *link, sd_netlink **rtnl) { in link_apply_sr_iov_config() argument
902 assert(link); in link_apply_sr_iov_config()
903 assert(link->config); in link_apply_sr_iov_config()
904 assert(link->device); in link_apply_sr_iov_config()
906 …r = sr_iov_set_num_vfs(link->device, link->config->sr_iov_num_vfs, link->config->sr_iov_by_section… in link_apply_sr_iov_config()
908 …log_link_warning_errno(link, r, "Failed to set the number of SR-IOV virtual functions, ignoring: %… in link_apply_sr_iov_config()
910 if (ordered_hashmap_isempty(link->config->sr_iov_by_section)) in link_apply_sr_iov_config()
913 r = sr_iov_get_num_vfs(link->device, &n); in link_apply_sr_iov_config()
915 …log_link_warning_errno(link, r, "Failed to get the number of SR-IOV virtual functions, ignoring [S… in link_apply_sr_iov_config()
919 … log_link_warning(link, "No SR-IOV virtual function exists, ignoring [SR-IOV] sections: %m"); in link_apply_sr_iov_config()
923 ORDERED_HASHMAP_FOREACH(sr_iov, link->config->sr_iov_by_section) { in link_apply_sr_iov_config()
925 … log_link_warning(link, "SR-IOV virtual function %"PRIu32" does not exist, ignoring.", sr_iov->vf); in link_apply_sr_iov_config()
929 r = sr_iov_configure(link, rtnl, sr_iov); in link_apply_sr_iov_config()
931 log_link_warning_errno(link, r, in link_apply_sr_iov_config()
939 int link_apply_config(LinkConfigContext *ctx, sd_netlink **rtnl, Link *link) { in link_apply_config() argument
944 assert(link); in link_apply_config()
946 if (!IN_SET(link->action, SD_DEVICE_ADD, SD_DEVICE_BIND, SD_DEVICE_MOVE)) { in link_apply_config()
947 log_link_debug(link, "Skipping to apply .link settings on '%s' uevent.", in link_apply_config()
948 device_action_to_string(link->action)); in link_apply_config()
950 link->new_name = link->ifname; in link_apply_config()
954 r = link_apply_ethtool_settings(link, &ctx->ethtool_fd); in link_apply_config()
958 r = link_apply_rtnl_settings(link, rtnl); in link_apply_config()
962 r = link_generate_new_name(link); in link_apply_config()
966 r = link_apply_alternative_names(link, rtnl); in link_apply_config()
970 r = link_apply_sr_iov_config(link, rtnl); in link_apply_config()