summaryrefslogtreecommitdiff
path: root/src/network/networkd-address.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-06-03 19:14:12 +0200
committerLennart Poettering <lennart@poettering.net>2016-06-03 19:14:12 +0200
commit8c34b963076a1ce7c9102802a13502be82a02cc7 (patch)
treeeac34c1df2a831905e52b198eb13d6c001f85ab9 /src/network/networkd-address.c
parentf3e43635932c14f8f0aea078adf3bfe09a9ba683 (diff)
networkd: enforce a limit on the number of statically assigned addresses/routes/fdb entries
We should put a limit on everything, hence also on these resources.
Diffstat (limited to 'src/network/networkd-address.c')
-rw-r--r--src/network/networkd-address.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
index 367c340e08..4cdb500bd6 100644
--- a/src/network/networkd-address.c
+++ b/src/network/networkd-address.c
@@ -32,6 +32,8 @@
#include "utf8.h"
#include "util.h"
+#define STATIC_ADDRESSES_PER_NETWORK_MAX 1024U
+
int address_new(Address **ret) {
_cleanup_address_free_ Address *address = NULL;
@@ -54,6 +56,9 @@ int address_new_static(Network *network, unsigned section, Address **ret) {
_cleanup_address_free_ Address *address = NULL;
int r;
+ assert(network);
+ assert(ret);
+
if (section) {
address = hashmap_get(network->addresses_by_section, UINT_TO_PTR(section));
if (address) {
@@ -64,18 +69,21 @@ int address_new_static(Network *network, unsigned section, Address **ret) {
}
}
+ if (network->n_static_addresses >= STATIC_ADDRESSES_PER_NETWORK_MAX)
+ return -E2BIG;
+
r = address_new(&address);
if (r < 0)
return r;
if (section) {
address->section = section;
- hashmap_put(network->addresses_by_section,
- UINT_TO_PTR(address->section), address);
+ hashmap_put(network->addresses_by_section, UINT_TO_PTR(address->section), address);
}
address->network = network;
LIST_APPEND(addresses, network->static_addresses, address);
+ network->n_static_addresses++;
*ret = address;
address = NULL;
@@ -89,10 +97,11 @@ void address_free(Address *address) {
if (address->network) {
LIST_REMOVE(addresses, address->network->static_addresses, address);
+ assert(address->network->n_static_addresses > 0);
+ address->network->n_static_addresses--;
if (address->section)
- hashmap_remove(address->network->addresses_by_section,
- UINT_TO_PTR(address->section));
+ hashmap_remove(address->network->addresses_by_section, UINT_TO_PTR(address->section));
}
if (address->link) {