1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-27 03:21:32 +03:00

network: drop list fields in Network object

This commit is contained in:
Yu Watanabe 2019-05-04 13:02:18 +02:00
parent d4df632674
commit 715d398e61
6 changed files with 15 additions and 26 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -276,8 +276,6 @@ struct Network {
char **ntp;
char **bind_carrier;
LIST_FIELDS(Network, networks);
};
Network *network_ref(Network *network);