From: Yu Watanabe Date: Fri, 25 Jun 2021 06:58:30 +0000 (+0900) Subject: network: rename Manager::links -> Manager::links_by_index X-Git-Tag: v249-rc3~17^2~13 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6eab614db805504cec3af0c1c7b21ae6275a89a6;p=thirdparty%2Fsystemd.git network: rename Manager::links -> Manager::links_by_index This also renames link_get() -> link_get_by_index(). --- diff --git a/src/network/networkd-address-pool.c b/src/network/networkd-address-pool.c index 79a1c1b847d..e1cefbefbdd 100644 --- a/src/network/networkd-address-pool.c +++ b/src/network/networkd-address-pool.c @@ -95,7 +95,7 @@ static bool address_pool_prefix_is_taken( assert(p); assert(u); - HASHMAP_FOREACH(l, p->manager->links) { + HASHMAP_FOREACH(l, p->manager->links_by_index) { Address *a; /* Don't clash with assigned addresses */ diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c index 04ad2aa69d4..2b0967d914f 100644 --- a/src/network/networkd-address.c +++ b/src/network/networkd-address.c @@ -598,7 +598,7 @@ int manager_has_address(Manager *manager, int family, const union in_addr_union assert(address); if (family == AF_INET) { - HASHMAP_FOREACH(link, manager->links) + HASHMAP_FOREACH(link, manager->links_by_index) if (link_get_ipv4_address(link, &address->in, 0, &a) >= 0) return !check_ready || address_is_ready(a); } else { @@ -611,7 +611,7 @@ int manager_has_address(Manager *manager, int family, const union in_addr_union tmp->family = family; tmp->in_addr = *address; - HASHMAP_FOREACH(link, manager->links) + HASHMAP_FOREACH(link, manager->links_by_index) if (address_get(link, tmp, &a) >= 0) return !check_ready || address_is_ready(a); } @@ -1319,7 +1319,7 @@ int manager_rtnl_process_address(sd_netlink *rtnl, sd_netlink_message *message, return 0; } - r = link_get(m, ifindex, &link); + r = link_get_by_index(m, ifindex, &link); if (r < 0 || !link) { /* when enumerating we might be out of sync, but we will get the address again, so just * ignore it */ diff --git a/src/network/networkd-bridge-fdb.c b/src/network/networkd-bridge-fdb.c index 115ea5bb14a..ab1b766d483 100644 --- a/src/network/networkd-bridge-fdb.c +++ b/src/network/networkd-bridge-fdb.c @@ -228,7 +228,7 @@ static bool bridge_fdb_is_ready_to_configure(BridgeFDB *fdb, Link *link) { fdb->outgoing_ifindex = out->ifindex; } else if (fdb->outgoing_ifindex > 0) { - if (link_get(link->manager, fdb->outgoing_ifindex, &out) < 0) + if (link_get_by_index(link->manager, fdb->outgoing_ifindex, &out) < 0) return false; } if (out && !link_is_ready_to_configure(out, false)) diff --git a/src/network/networkd-bridge-mdb.c b/src/network/networkd-bridge-mdb.c index faf3dbd0b7b..0f808fb515d 100644 --- a/src/network/networkd-bridge-mdb.c +++ b/src/network/networkd-bridge-mdb.c @@ -249,7 +249,7 @@ static bool bridge_mdb_is_ready_to_configure(Link *link) { if (link->master_ifindex != link->network->bridge->ifindex) return false; - if (link_get(link->manager, link->master_ifindex, &master) < 0) + if (link_get_by_index(link->manager, link->master_ifindex, &master) < 0) return false; if (!streq_ptr(master->kind, "bridge")) diff --git a/src/network/networkd-dhcp-server.c b/src/network/networkd-dhcp-server.c index 8c0cd37f3fa..9e2faa56753 100644 --- a/src/network/networkd-dhcp-server.c +++ b/src/network/networkd-dhcp-server.c @@ -104,7 +104,7 @@ static int dhcp_server_find_uplink(Link *link, Link **ret) { return link_get_by_name(link->manager, link->network->dhcp_server_uplink_name, ret); if (link->network->dhcp_server_uplink_index > 0) - return link_get(link->manager, link->network->dhcp_server_uplink_index, ret); + return link_get_by_index(link->manager, link->network->dhcp_server_uplink_index, ret); if (link->network->dhcp_server_uplink_index == 0) { /* It is not necessary to propagate error in automatic selection. */ diff --git a/src/network/networkd-dhcp6.c b/src/network/networkd-dhcp6.c index e2c314514bd..e850e595e37 100644 --- a/src/network/networkd-dhcp6.c +++ b/src/network/networkd-dhcp6.c @@ -602,7 +602,7 @@ static void dhcp6_pd_prefix_distribute(Link *dhcp6_link, assert(masked_pd_prefix); assert(pd_prefix_len <= 64); - HASHMAP_FOREACH(link, dhcp6_link->manager->links) { + HASHMAP_FOREACH(link, dhcp6_link->manager->links_by_index) { _cleanup_free_ char *assigned_buf = NULL; struct in6_addr assigned_prefix; @@ -706,7 +706,7 @@ static void dhcp6_pd_prefix_lost(Link *dhcp6_link) { assert(dhcp6_link); assert(dhcp6_link->manager); - HASHMAP_FOREACH(link, dhcp6_link->manager->links) { + HASHMAP_FOREACH(link, dhcp6_link->manager->links_by_index) { if (link == dhcp6_link) continue; @@ -954,7 +954,7 @@ static int dhcp6_pd_prefix_acquired(Link *dhcp6_link) { assert(dhcp6_link); assert(dhcp6_link->dhcp6_lease); - HASHMAP_FOREACH(link, dhcp6_link->manager->links) { + HASHMAP_FOREACH(link, dhcp6_link->manager->links_by_index) { if (link == dhcp6_link) continue; @@ -1024,7 +1024,7 @@ static int dhcp6_pd_prefix_acquired(Link *dhcp6_link) { false); } - HASHMAP_FOREACH(link, dhcp6_link->manager->links) { + HASHMAP_FOREACH(link, dhcp6_link->manager->links_by_index) { if (link == dhcp6_link) continue; @@ -1450,7 +1450,7 @@ int dhcp6_request_prefix_delegation(Link *link) { log_link_debug(link, "Requesting DHCPv6 prefixes to be delegated for new link"); - HASHMAP_FOREACH(l, link->manager->links) { + HASHMAP_FOREACH(l, link->manager->links_by_index) { int r, enabled; if (l == link) @@ -1548,7 +1548,7 @@ static bool dhcp6_enable_prefix_delegation(Link *dhcp6_link) { assert(dhcp6_link); assert(dhcp6_link->manager); - HASHMAP_FOREACH(link, dhcp6_link->manager->links) { + HASHMAP_FOREACH(link, dhcp6_link->manager->links_by_index) { if (link == dhcp6_link) continue; diff --git a/src/network/networkd-json.c b/src/network/networkd-json.c index c78e653c0b0..2bae2f2913d 100644 --- a/src/network/networkd-json.c +++ b/src/network/networkd-json.c @@ -114,11 +114,11 @@ int manager_build_json(Manager *manager, JsonVariant **ret) { assert(manager); assert(ret); - elements = new(JsonVariant*, hashmap_size(manager->links)); + elements = new(JsonVariant*, hashmap_size(manager->links_by_index)); if (!elements) return -ENOMEM; - HASHMAP_FOREACH(link, manager->links) { + HASHMAP_FOREACH(link, manager->links_by_index) { r = link_build_json(link, elements + n); if (r < 0) goto finalize; diff --git a/src/network/networkd-link-bus.c b/src/network/networkd-link-bus.c index 50c3f600804..f4e35565174 100644 --- a/src/network/networkd-link-bus.c +++ b/src/network/networkd-link-bus.c @@ -834,11 +834,11 @@ int link_node_enumerator(sd_bus *bus, const char *path, void *userdata, char *** assert(m); assert(nodes); - l = new0(char*, hashmap_size(m->links) + 1); + l = new0(char*, hashmap_size(m->links_by_index) + 1); if (!l) return -ENOMEM; - HASHMAP_FOREACH(link, m->links) { + HASHMAP_FOREACH(link, m->links_by_index) { char *p; p = link_bus_path(link); @@ -874,7 +874,7 @@ int link_object_find(sd_bus *bus, const char *path, const char *interface, void if (ifindex < 0) return 0; - r = link_get(m, ifindex, &link); + r = link_get_by_index(m, ifindex, &link); if (r < 0) return 0; diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index c98f684bfd7..c3be8aa5c20 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -274,13 +274,13 @@ static Link *link_free(Link *link) { DEFINE_TRIVIAL_REF_UNREF_FUNC(Link, link, link_free); -int link_get(Manager *m, int ifindex, Link **ret) { +int link_get_by_index(Manager *m, int ifindex, Link **ret) { Link *link; assert(m); assert(ifindex > 0); - link = hashmap_get(m->links, INT_TO_PTR(ifindex)); + link = hashmap_get(m->links_by_index, INT_TO_PTR(ifindex)); if (!link) return -ENODEV; @@ -312,7 +312,7 @@ int link_get_master(Link *link, Link **ret) { if (link->master_ifindex <= 0 || link->master_ifindex == link->ifindex) return -ENODEV; - return link_get(link->manager, link->master_ifindex, ret); + return link_get_by_index(link->manager, link->master_ifindex, ret); } void link_set_state(Link *link, LinkState state) { @@ -774,7 +774,7 @@ static int link_new_bound_by_list(Link *link) { m = link->manager; - HASHMAP_FOREACH(carrier, m->links) { + HASHMAP_FOREACH(carrier, m->links_by_index) { if (!carrier->network) continue; @@ -813,7 +813,7 @@ static int link_new_bound_to_list(Link *link) { m = link->manager; - HASHMAP_FOREACH(carrier, m->links) { + HASHMAP_FOREACH(carrier, m->links_by_index) { if (strv_fnmatch(link->network->bind_carrier, carrier->ifname)) { r = link_put_carrier(link, carrier, &link->bound_to_links); if (r < 0) @@ -965,7 +965,7 @@ static Link *link_drop(Link *link) { hashmap_remove(link->manager->links_by_name, link->ifname); /* The following must be called at last. */ - assert_se(hashmap_remove(link->manager->links, INT_TO_PTR(link->ifindex)) == link); + assert_se(hashmap_remove(link->manager->links_by_index, INT_TO_PTR(link->ifindex)) == link); return link_unref(link); } @@ -1471,7 +1471,7 @@ int manager_udev_process_link(sd_device_monitor *monitor, sd_device *device, voi return 0; } - r = link_get(m, ifindex, &link); + r = link_get_by_index(m, ifindex, &link); if (r < 0) { log_device_debug_errno(device, r, "Failed to get link from ifindex %i, ignoring: %m", ifindex); return 0; @@ -2257,7 +2257,7 @@ static int link_new(Manager *manager, sd_netlink_message *message, Link **ret) { .dns_over_tls_mode = _DNS_OVER_TLS_MODE_INVALID, }; - r = hashmap_ensure_put(&manager->links, NULL, INT_TO_PTR(link->ifindex), link); + r = hashmap_ensure_put(&manager->links_by_index, NULL, INT_TO_PTR(link->ifindex), link); if (r < 0) return log_link_debug_errno(link, r, "Failed to store link into manager: %m"); @@ -2323,7 +2323,7 @@ int manager_rtnl_process_link(sd_netlink *rtnl, sd_netlink_message *message, Man return 0; } - (void) link_get(manager, ifindex, &link); + (void) link_get_by_index(manager, ifindex, &link); (void) netdev_get(manager, name, &netdev); switch (type) { diff --git a/src/network/networkd-link.h b/src/network/networkd-link.h index f5a2fc802b0..c133927fd66 100644 --- a/src/network/networkd-link.h +++ b/src/network/networkd-link.h @@ -218,7 +218,7 @@ Link *link_ref(Link *link); DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref); DEFINE_TRIVIAL_DESTRUCTOR(link_netlink_destroy_callback, Link, link_unref); -int link_get(Manager *m, int ifindex, Link **ret); +int link_get_by_index(Manager *m, int ifindex, Link **ret); int link_get_by_name(Manager *m, const char *ifname, Link **ret); int link_get_master(Link *link, Link **ret); diff --git a/src/network/networkd-manager-bus.c b/src/network/networkd-manager-bus.c index a1520240d71..8a5ad8eac3e 100644 --- a/src/network/networkd-manager-bus.c +++ b/src/network/networkd-manager-bus.c @@ -31,7 +31,7 @@ static int method_list_links(sd_bus_message *message, void *userdata, sd_bus_err if (r < 0) return r; - HASHMAP_FOREACH(link, manager->links) { + HASHMAP_FOREACH(link, manager->links_by_index) { _cleanup_free_ char *path = NULL; path = link_bus_path(link); @@ -95,8 +95,8 @@ static int method_get_link_by_index(sd_bus_message *message, void *userdata, sd_ if (r < 0) return r; - link = hashmap_get(manager->links, INT_TO_PTR(ifindex)); - if (!link) + r = link_get_by_index(manager, ifindex, &link); + if (r < 0) return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_LINK, "Link %i not known", ifindex); r = sd_bus_message_new_method_return(message, &reply); @@ -126,8 +126,8 @@ static int call_link_method(Manager *m, sd_bus_message *message, sd_bus_message_ if (r < 0) return r; - l = hashmap_get(m->links, INT_TO_PTR(ifindex)); - if (!l) + r = link_get_by_index(m, ifindex, &l); + if (r < 0) return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_LINK, "Link %i not known", ifindex); return handler(message, l, error); @@ -215,7 +215,7 @@ static int bus_method_reload(sd_bus_message *message, void *userdata, sd_bus_err if (r < 0) return r; - HASHMAP_FOREACH(link, manager->links) { + HASHMAP_FOREACH(link, manager->links_by_index) { r = link_reconfigure(link, /* force = */ false); if (r < 0) return r; diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index 5b6eefb7433..b95742f4907 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -58,7 +58,7 @@ static int manager_reset_all(Manager *m) { assert(m); - HASHMAP_FOREACH(link, m->links) { + HASHMAP_FOREACH(link, m->links_by_index) { r = link_carrier_reset(link); if (r < 0) { log_link_warning_errno(link, r, "Could not reset carrier: %m"); @@ -451,7 +451,7 @@ Manager* manager_free(Manager *m) { free(m->state_file); - HASHMAP_FOREACH(link, m->links) + HASHMAP_FOREACH(link, m->links_by_index) (void) link_stop_engines(link, true); m->request_queue = ordered_set_free(m->request_queue); @@ -462,7 +462,7 @@ Manager* manager_free(Manager *m) { m->dirty_links = set_free_with_destructor(m->dirty_links, link_unref); m->links_requesting_uuid = set_free_with_destructor(m->links_requesting_uuid, link_unref); m->links_by_name = hashmap_free(m->links_by_name); - m->links = hashmap_free_with_destructor(m->links, link_unref); + m->links_by_index = hashmap_free_with_destructor(m->links_by_index, link_unref); m->networks = ordered_hashmap_free_with_destructor(m->networks, network_unref); @@ -528,7 +528,7 @@ int manager_start(Manager *m) { if (r < 0) log_warning_errno(r, "Failed to update state file %s, ignoring: %m", m->state_file); - HASHMAP_FOREACH(link, m->links) { + HASHMAP_FOREACH(link, m->links_by_index) { r = link_save(link); if (r < 0) log_link_warning_errno(link, r, "Failed to update link state file %s, ignoring: %m", link->state_file); diff --git a/src/network/networkd-manager.h b/src/network/networkd-manager.h index 24845a55c2b..cef5eb889bc 100644 --- a/src/network/networkd-manager.h +++ b/src/network/networkd-manager.h @@ -44,7 +44,7 @@ struct Manager { LinkAddressState ipv6_address_state; LinkOnlineState online_state; - Hashmap *links; + Hashmap *links_by_index; Hashmap *links_by_name; Hashmap *netdevs; OrderedHashmap *networks; diff --git a/src/network/networkd-neighbor.c b/src/network/networkd-neighbor.c index 147dca7ef3b..b23f081bfb2 100644 --- a/src/network/networkd-neighbor.c +++ b/src/network/networkd-neighbor.c @@ -536,7 +536,7 @@ int manager_rtnl_process_neighbor(sd_netlink *rtnl, sd_netlink_message *message, return 0; } - r = link_get(m, ifindex, &link); + r = link_get_by_index(m, ifindex, &link); if (r < 0 || !link) { /* when enumerating we might be out of sync, but we will get the neighbor again. Also, * kernel sends messages about neighbors after a link is removed. So, just ignore it. */ diff --git a/src/network/networkd-nexthop.c b/src/network/networkd-nexthop.c index 4bc29ca0577..a52e5dcb16c 100644 --- a/src/network/networkd-nexthop.c +++ b/src/network/networkd-nexthop.c @@ -645,7 +645,7 @@ static bool links_have_nexthop(const Manager *manager, const NextHop *nexthop, c assert(manager); - HASHMAP_FOREACH(link, manager->links) { + HASHMAP_FOREACH(link, manager->links_by_index) { if (link == except) continue; @@ -765,7 +765,7 @@ static bool nexthop_is_ready_to_configure(Link *link, const NextHop *nexthop) { if (!FLAGS_SET(link->flags, IFF_UP)) return false; - HASHMAP_FOREACH(l, link->manager->links) { + HASHMAP_FOREACH(l, link->manager->links_by_index) { if (l->address_remove_messages > 0) return false; if (l->nexthop_remove_messages > 0) @@ -868,7 +868,7 @@ int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message, return 0; } - r = link_get(m, ifindex, &link); + r = link_get_by_index(m, ifindex, &link); if (r < 0 || !link) { if (!m->enumerating) log_warning("rtnl: received nexthop message for link (%"PRIu32") we do not know about, ignoring", ifindex); diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index 2893c0949d5..7b36b481419 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -753,7 +753,7 @@ bool manager_address_is_reachable(Manager *manager, int family, const union in_a assert(IN_SET(family, AF_INET, AF_INET6)); assert(address); - HASHMAP_FOREACH(link, manager->links) { + HASHMAP_FOREACH(link, manager->links_by_index) { Route *route; SET_FOREACH(route, link->routes) @@ -807,7 +807,7 @@ int manager_find_uplink(Manager *m, int family, Link *exclude, Link **ret) { /* Looks for a suitable "uplink", via black magic: an interface that is up and where the * default route with the highest priority points to. */ - HASHMAP_FOREACH(link, m->links) { + HASHMAP_FOREACH(link, m->links_by_index) { if (link == exclude) continue; @@ -1106,7 +1106,7 @@ static bool links_have_static_route(const Manager *manager, const Route *route, assert(manager); - HASHMAP_FOREACH(link, manager->links) { + HASHMAP_FOREACH(link, manager->links_by_index) { if (link == except) continue; @@ -1260,7 +1260,7 @@ static int route_add_and_setup_timer_one(Link *link, const Route *route, const M } else if (m && m->ifindex != 0 && m->ifindex != link->ifindex) { Link *link_gw; - r = link_get(link->manager, m->ifindex, &link_gw); + r = link_get_by_index(link->manager, m->ifindex, &link_gw); if (r < 0) return log_link_error_errno(link, r, "Failed to get link with ifindex %d: %m", m->ifindex); @@ -1685,7 +1685,7 @@ static int route_is_ready_to_configure(const Route *route, Link *link) { } else { Link *l; - HASHMAP_FOREACH(l, link->manager->links) { + HASHMAP_FOREACH(l, link->manager->links_by_index) { if (l->address_remove_messages > 0) return false; if (l->nexthop_remove_messages > 0) @@ -1720,7 +1720,7 @@ static int route_is_ready_to_configure(const Route *route, Link *link) { m->ifindex = l->ifindex; } else if (m->ifindex > 0) { - if (link_get(link->manager, m->ifindex, &l) < 0) + if (link_get_by_index(link->manager, m->ifindex, &l) < 0) return false; } if (l && !link_is_ready_to_configure(l, true)) @@ -1805,7 +1805,7 @@ static int process_route_one(Manager *manager, Link *link, uint16_t type, const return log_warning_errno(SYNTHETIC_ERRNO(EINVAL), "rtnl: received multipath route with invalid ifindex, ignoring."); - r = link_get(manager, m->ifindex, &link); + r = link_get_by_index(manager, m->ifindex, &link); if (r < 0) { log_warning_errno(r, "rtnl: received multipath route for link (%d) we do not know, ignoring: %m", m->ifindex); return 0; @@ -1898,7 +1898,7 @@ int manager_rtnl_process_route(sd_netlink *rtnl, sd_netlink_message *message, Ma return 0; } - r = link_get(m, ifindex, &link); + r = link_get_by_index(m, ifindex, &link); if (r < 0 || !link) { /* when enumerating we might be out of sync, but we will * get the route again, so just ignore it */ diff --git a/src/network/networkd-routing-policy-rule.c b/src/network/networkd-routing-policy-rule.c index 411022a24f6..af7e8a973cf 100644 --- a/src/network/networkd-routing-policy-rule.c +++ b/src/network/networkd-routing-policy-rule.c @@ -607,7 +607,7 @@ static int links_have_routing_policy_rule(const Manager *m, const RoutingPolicyR assert(m); assert(rule); - HASHMAP_FOREACH(link, m->links) { + HASHMAP_FOREACH(link, m->links_by_index) { RoutingPolicyRule *link_rule; if (link == except) diff --git a/src/network/networkd-speed-meter.c b/src/network/networkd-speed-meter.c index 97204c89e9b..6c3f97079ed 100644 --- a/src/network/networkd-speed-meter.c +++ b/src/network/networkd-speed-meter.c @@ -26,9 +26,9 @@ static int process_message(Manager *manager, sd_netlink_message *message) { if (r < 0) return r; - link = hashmap_get(manager->links, INT_TO_PTR(ifindex)); - if (!link) - return -ENODEV; + r = link_get_by_index(manager, ifindex, &link); + if (r < 0) + return r; link->stats_old = link->stats_new; @@ -62,7 +62,7 @@ static int speed_meter_handler(sd_event_source *s, uint64_t usec, void *userdata manager->speed_meter_usec_old = manager->speed_meter_usec_new; manager->speed_meter_usec_new = usec_now; - HASHMAP_FOREACH(link, manager->links) + HASHMAP_FOREACH(link, manager->links_by_index) link->stats_updated = false; r = sd_rtnl_message_new_link(manager->rtnl, &req, RTM_GETLINK, 0); diff --git a/src/network/networkd-state-file.c b/src/network/networkd-state-file.c index b9dab9b211f..745aa4a995e 100644 --- a/src/network/networkd-state-file.c +++ b/src/network/networkd-state-file.c @@ -121,7 +121,7 @@ int manager_save(Manager *m) { assert(m); assert(m->state_file); - HASHMAP_FOREACH(link, m->links) { + HASHMAP_FOREACH(link, m->links_by_index) { const struct in_addr *addresses; if (link->flags & IFF_LOOPBACK)