diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2019-05-04 13:02:18 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2019-05-07 16:55:19 +0200 |
commit | 715d398e612b3b9965771e238d6a49207f9709de (patch) | |
tree | a262b87b3d2a4698dd6c6e8b3304d3f62f75d01a | |
parent | d4df6326740e1fabb356299875d154de89589211 (diff) | |
download | systemd-715d398e612b3b9965771e238d6a49207f9709de.tar.gz systemd-715d398e612b3b9965771e238d6a49207f9709de.tar.bz2 systemd-715d398e612b3b9965771e238d6a49207f9709de.zip |
network: drop list fields in Network object
-rw-r--r-- | src/network/networkd-address-pool.c | 2 | ||||
-rw-r--r-- | src/network/networkd-manager.c | 4 | ||||
-rw-r--r-- | src/network/networkd-manager.h | 3 | ||||
-rw-r--r-- | src/network/networkd-network-bus.c | 3 | ||||
-rw-r--r-- | src/network/networkd-network.c | 27 | ||||
-rw-r--r-- | src/network/networkd-network.h | 2 |
6 files changed, 15 insertions, 26 deletions
diff --git a/src/network/networkd-address-pool.c b/src/network/networkd-address-pool.c index eaf056d118..db6c1456dc 100644 --- a/src/network/networkd-address-pool.c +++ b/src/network/networkd-address-pool.c @@ -106,7 +106,7 @@ static bool address_pool_prefix_is_taken( } /* And don't clash with configured but un-assigned addresses either */ - LIST_FOREACH(networks, n, p->manager->networks) { + ORDERED_HASHMAP_FOREACH(n, p->manager->networks, i) { Address *a; LIST_FOREACH(addresses, a, n->static_addresses) { diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index 047296cbf0..98d7259782 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -1402,8 +1402,6 @@ int manager_new(Manager **ret) { if (r < 0) return r; - LIST_HEAD_INIT(m->networks); - r = sd_resolve_default(&m->resolve); if (r < 0) return r; @@ -1452,7 +1450,7 @@ void manager_free(Manager *m) { m->links = hashmap_free_with_destructor(m->links, link_unref); m->duids_requesting_uuid = set_free(m->duids_requesting_uuid); - m->networks_by_name = hashmap_free_with_destructor(m->networks_by_name, network_unref); + m->networks = ordered_hashmap_free_with_destructor(m->networks, network_unref); m->netdevs = hashmap_free_with_destructor(m->netdevs, netdev_unref); diff --git a/src/network/networkd-manager.h b/src/network/networkd-manager.h index 35ab6bedb1..1084a3a60b 100644 --- a/src/network/networkd-manager.h +++ b/src/network/networkd-manager.h @@ -37,9 +37,8 @@ struct Manager { Hashmap *links; Hashmap *netdevs; - Hashmap *networks_by_name; + OrderedHashmap *networks; Hashmap *dhcp6_prefixes; - LIST_HEAD(Network, networks); LIST_HEAD(AddressPool, address_pools); usec_t network_dirs_ts_usec; diff --git a/src/network/networkd-network-bus.c b/src/network/networkd-network-bus.c index 07e453cc80..e3ba148ce1 100644 --- a/src/network/networkd-network-bus.c +++ b/src/network/networkd-network-bus.c @@ -87,6 +87,7 @@ int network_node_enumerator(sd_bus *bus, const char *path, void *userdata, char _cleanup_strv_free_ char **l = NULL; Manager *m = userdata; Network *network; + Iterator i; int r; assert(bus); @@ -94,7 +95,7 @@ int network_node_enumerator(sd_bus *bus, const char *path, void *userdata, char assert(m); assert(nodes); - LIST_FOREACH(networks, network, m->networks) { + ORDERED_HASHMAP_FOREACH(network, m->networks, i) { char *p; p = network_bus_path(network); diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index c0ef2c6edf..0b8cf5a43b 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -344,6 +344,7 @@ int network_load_one(Manager *manager, const char *filename) { .filename = TAKE_PTR(fname), .name = TAKE_PTR(name), + .manager = manager, .n_ref = 1, .required_for_online = true, @@ -448,14 +449,11 @@ int network_load_one(Manager *manager, const char *filename) { if (r < 0) log_warning_errno(r, "%s: Failed to add IPv4LL route, ignoring: %m", network->filename); - LIST_PREPEND(networks, manager->networks, network); - network->manager = manager; - - r = hashmap_ensure_allocated(&manager->networks_by_name, &string_hash_ops); + r = ordered_hashmap_ensure_allocated(&manager->networks, &string_hash_ops); if (r < 0) return r; - r = hashmap_put(manager->networks_by_name, network->name, network); + r = ordered_hashmap_put(manager->networks, network->name, network); if (r < 0) return r; @@ -467,21 +465,19 @@ int network_load_one(Manager *manager, const char *filename) { } int network_load(Manager *manager) { - Network *network; _cleanup_strv_free_ char **files = NULL; char **f; int r; assert(manager); - while ((network = manager->networks)) - network_unref(network); + ordered_hashmap_clear_with_destructor(manager->networks, network_unref); r = conf_files_list_strv(&files, ".network", NULL, 0, NETWORK_DIRS); if (r < 0) return log_error_errno(r, "Failed to enumerate network files: %m"); - STRV_FOREACH_BACKWARDS(f, files) { + STRV_FOREACH(f, files) { r = network_load_one(manager, *f); if (r < 0) return r; @@ -570,11 +566,8 @@ static Network *network_free(Network *network) { hashmap_free(network->rules_by_section); if (network->manager) { - if (network->manager->networks) - LIST_REMOVE(networks, network->manager->networks, network); - - if (network->manager->networks_by_name && network->name) - hashmap_remove(network->manager->networks_by_name, network->name); + if (network->manager->networks && network->name) + ordered_hashmap_remove(network->manager->networks, network->name); if (network->manager->duids_requesting_uuid) set_remove(network->manager->duids_requesting_uuid, &network->duid); @@ -600,7 +593,7 @@ int network_get_by_name(Manager *manager, const char *name, Network **ret) { assert(name); assert(ret); - network = hashmap_get(manager->networks_by_name, name); + network = ordered_hashmap_get(manager->networks, name); if (!network) return -ENOENT; @@ -614,6 +607,7 @@ int network_get(Manager *manager, sd_device *device, Network **ret) { const char *path = NULL, *driver = NULL, *devtype = NULL; Network *network; + Iterator i; assert(manager); assert(ret); @@ -626,7 +620,7 @@ int network_get(Manager *manager, sd_device *device, (void) sd_device_get_devtype(device, &devtype); } - LIST_FOREACH(networks, network, manager->networks) { + ORDERED_HASHMAP_FOREACH(network, manager->networks, i) if (net_match_config(network->match_mac, network->match_path, network->match_driver, network->match_type, network->match_name, @@ -649,7 +643,6 @@ int network_get(Manager *manager, sd_device *device, *ret = network; return 0; } - } *ret = NULL; diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h index 782dd491a8..dfaf43c206 100644 --- a/src/network/networkd-network.h +++ b/src/network/networkd-network.h @@ -276,8 +276,6 @@ struct Network { char **ntp; char **bind_carrier; - - LIST_FIELDS(Network, networks); }; Network *network_ref(Network *network); |