return 0;
}
-int address_pool_new_from_string(
+static int address_pool_new_from_string(
Manager *m,
AddressPool **ret,
int family,
free(p);
}
+int address_pool_setup_default(Manager *m) {
+ AddressPool *p;
+ int r;
+
+ assert(m);
+
+ /* Add in the well-known private address ranges. */
+
+ r = address_pool_new_from_string(m, &p, AF_INET6, "fd00::", 8);
+ if (r < 0)
+ return r;
+
+ r = address_pool_new_from_string(m, &p, AF_INET, "10.0.0.0", 8);
+ if (r < 0)
+ return r;
+
+ r = address_pool_new_from_string(m, &p, AF_INET, "172.16.0.0", 12);
+ if (r < 0)
+ return r;
+
+ r = address_pool_new_from_string(m, &p, AF_INET, "192.168.0.0", 16);
+ if (r < 0)
+ return r;
+
+ return 0;
+}
+
static bool address_pool_prefix_is_taken(
AddressPool *p,
const union in_addr_union *u,
return false;
}
-int address_pool_acquire(AddressPool *p, unsigned prefixlen, union in_addr_union *found) {
+static int address_pool_acquire_one(AddressPool *p, int family, unsigned prefixlen, union in_addr_union *found) {
union in_addr_union u;
unsigned i;
int r;
assert(prefixlen > 0);
assert(found);
+ if (p->family != family)
+ return 0;
+
if (p->prefixlen >= prefixlen)
return 0;
return 0;
}
+
+int address_pool_acquire(Manager *m, int family, unsigned prefixlen, union in_addr_union *found) {
+ AddressPool *p;
+ int r;
+
+ assert(m);
+ assert(IN_SET(family, AF_INET, AF_INET6));
+ assert(prefixlen > 0);
+ assert(found);
+
+ LIST_FOREACH(address_pools, p, m->address_pools) {
+ r = address_pool_acquire_one(p, family, prefixlen, found);
+ if (r != 0)
+ return r;
+ }
+
+ return 0;
+}
LIST_FIELDS(AddressPool, address_pools);
};
-int address_pool_new_from_string(Manager *m, AddressPool **ret, int family, const char *p, unsigned prefixlen);
void address_pool_free(AddressPool *p);
-int address_pool_acquire(AddressPool *p, unsigned prefixlen, union in_addr_union *found);
+int address_pool_setup_default(Manager *m);
+int address_pool_acquire(Manager *m, int family, unsigned prefixlen, union in_addr_union *found);
/* The address is configured to be 0.0.0.0 or [::] by the user?
* Then let's acquire something more useful from the pool. */
- r = manager_address_pool_acquire(link->manager, original->family, original->prefixlen, &in_addr);
+ r = address_pool_acquire(link->manager, original->family, original->prefixlen, &in_addr);
if (r < 0)
return r;
if (r == 0)
/* use 128 MB for receive socket kernel queue. */
#define RCVBUF_SIZE (128*1024*1024)
-static int setup_default_address_pool(Manager *m) {
- AddressPool *p;
- int r;
-
- assert(m);
-
- /* Add in the well-known private address ranges. */
-
- r = address_pool_new_from_string(m, &p, AF_INET6, "fd00::", 8);
- if (r < 0)
- return r;
-
- r = address_pool_new_from_string(m, &p, AF_INET, "10.0.0.0", 8);
- if (r < 0)
- return r;
-
- r = address_pool_new_from_string(m, &p, AF_INET, "172.16.0.0", 12);
- if (r < 0)
- return r;
-
- r = address_pool_new_from_string(m, &p, AF_INET, "192.168.0.0", 16);
- if (r < 0)
- return r;
-
- return 0;
-}
-
static int manager_reset_all(Manager *m) {
Link *link;
int r;
if (r < 0)
return r;
- r = setup_default_address_pool(m);
+ r = address_pool_setup_default(m);
if (r < 0)
return r;
return 0;
}
-int manager_address_pool_acquire(Manager *m, int family, unsigned prefixlen, union in_addr_union *found) {
- AddressPool *p;
- int r;
-
- assert(m);
- assert(prefixlen > 0);
- assert(found);
-
- LIST_FOREACH(address_pools, p, m->address_pools) {
- if (p->family != family)
- continue;
-
- r = address_pool_acquire(p, prefixlen, found);
- if (r != 0)
- return r;
- }
-
- return 0;
-}
-
Link* manager_find_uplink(Manager *m, Link *exclude) {
_cleanup_free_ struct local_address *gateways = NULL;
int n, i;
void manager_dirty(Manager *m);
-int manager_address_pool_acquire(Manager *m, int family, unsigned prefixlen, union in_addr_union *found);
-
Link* manager_find_uplink(Manager *m, Link *exclude);
int manager_set_hostname(Manager *m, const char *hostname);