const union in_addr_union *u,
unsigned prefixlen) {
- AddressPool *p;
+ _cleanup_free_ AddressPool *p = NULL;
+ int r;
assert(m);
assert(u);
.in_addr = *u,
};
- LIST_PREPEND(address_pools, m->address_pools, p);
+ r = ordered_set_ensure_put(&m->address_pools, NULL, p);
+ if (r < 0)
+ return r;
+ TAKE_PTR(p);
return 0;
}
return address_pool_new(m, family, &u, prefixlen);
}
-void address_pool_free(AddressPool *p) {
-
- if (!p)
- return;
-
- if (p->manager)
- LIST_REMOVE(address_pools, p->manager->address_pools, p);
-
- free(p);
-}
-
int address_pool_setup_default(Manager *m) {
int r;
if (r < 0)
return r;
- r = address_pool_new_from_string(m, AF_INET, "10.0.0.0", 8);
+ r = address_pool_new_from_string(m, AF_INET, "192.168.0.0", 16);
if (r < 0)
return r;
if (r < 0)
return r;
- r = address_pool_new_from_string(m, AF_INET, "192.168.0.0", 16);
+ r = address_pool_new_from_string(m, AF_INET, "10.0.0.0", 8);
if (r < 0)
return r;
assert(prefixlen > 0);
assert(found);
- LIST_FOREACH(address_pools, p, m->address_pools) {
+ ORDERED_SET_FOREACH(p, m->address_pools) {
r = address_pool_acquire_one(p, family, prefixlen, found);
if (r != 0)
return r;
/* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once
-typedef struct AddressPool AddressPool;
-
#include "in-addr-util.h"
-#include "list.h"
typedef struct Manager Manager;
-struct AddressPool {
+typedef struct AddressPool {
Manager *manager;
int family;
unsigned prefixlen;
-
union in_addr_union in_addr;
-
- LIST_FIELDS(AddressPool, address_pools);
-};
-
-void address_pool_free(AddressPool *p);
+} AddressPool;
int address_pool_setup_default(Manager *m);
int address_pool_acquire(Manager *m, int family, unsigned prefixlen, union in_addr_union *found);
#include "firewall-util.h"
#include "memory-util.h"
#include "netlink-util.h"
+#include "networkd-address-pool.h"
#include "networkd-address.h"
#include "networkd-manager.h"
#include "networkd-network.h"
#include "local-addresses.h"
#include "netlink-util.h"
#include "network-internal.h"
+#include "networkd-address-pool.h"
#include "networkd-dhcp-server-bus.h"
#include "networkd-dhcp6.h"
#include "networkd-link-bus.h"
}
void manager_free(Manager *m) {
- AddressPool *pool;
Link *link;
if (!m)
m->netdevs = hashmap_free_with_destructor(m->netdevs, netdev_unref);
- while ((pool = m->address_pools))
- address_pool_free(pool);
+ ordered_set_free_free(m->address_pools);
/* routing_policy_rule_free() access m->rules and m->rules_foreign.
* So, it is necessary to set NULL after the sets are freed. */
#include "dhcp-identifier.h"
#include "hashmap.h"
-#include "list.h"
-#include "time-util.h"
-
-#include "networkd-address-pool.h"
#include "networkd-link.h"
#include "networkd-network.h"
+#include "ordered-set.h"
+#include "set.h"
+#include "time-util.h"
struct Manager {
sd_netlink *rtnl;
OrderedHashmap *networks;
Hashmap *dhcp6_prefixes;
Set *dhcp6_pd_prefixes;
- LIST_HEAD(AddressPool, address_pools);
+ OrderedSet *address_pools;
usec_t network_dirs_ts_usec;