Discussion:
[PATCH 2/2] ippool: Remove unused hash table
(too old to reply)
Patrik Flykt
2015-10-23 11:38:14 UTC
Permalink
As IP pool structures were only added to and removed from the
ippool_hash hash table, remove it as being unnecessary. Move
freeing of pool data to the unref function.
---
src/ippool.c | 39 ++++++++++++---------------------------
1 file changed, 12 insertions(+), 27 deletions(-)

diff --git a/src/ippool.c b/src/ippool.c
index 06f3762..cea1dcc 100644
--- a/src/ippool.c
+++ b/src/ippool.c
@@ -58,7 +58,6 @@ struct connman_ippool {
};

GSList *allocated_blocks;
-GHashTable *pool_hash;

static uint32_t last_block;
static uint32_t block_16_bits;
@@ -90,7 +89,18 @@ void __connman_ippool_unref_debug(struct connman_ippool *pool,
if (__sync_fetch_and_sub(&pool->refcount, 1) != 1)
return;

- g_hash_table_remove(pool_hash, pool);
+ if (pool->info) {
+ allocated_blocks = g_slist_remove(allocated_blocks, pool->info);
+ g_free(pool->info);
+ }
+
+ g_free(pool->gateway);
+ g_free(pool->broadcast);
+ g_free(pool->start_ip);
+ g_free(pool->end_ip);
+ g_free(pool->subnet_mask);
+
+ g_free(pool);
}

static char *get_ip(uint32_t ip)
@@ -393,7 +403,6 @@ struct connman_ippool *__connman_ippool_create(int index,
pool->end_ip = get_ip(block + start + range);

allocated_blocks = g_slist_prepend(allocated_blocks, info);
- g_hash_table_insert(pool_hash, pool, pool);

return pool;
}
@@ -423,24 +432,6 @@ const char *__connman_ippool_get_subnet_mask(struct connman_ippool *pool)
return pool->subnet_mask;
}

-static void pool_free(gpointer data)
-{
- struct connman_ippool *pool = data;
-
- if (pool->info) {
- allocated_blocks = g_slist_remove(allocated_blocks, pool->info);
- g_free(pool->info);
- }
-
- g_free(pool->gateway);
- g_free(pool->broadcast);
- g_free(pool->start_ip);
- g_free(pool->end_ip);
- g_free(pool->subnet_mask);
-
- g_free(pool);
-}
-
int __connman_ippool_init(void)
{
DBG("");
@@ -450,9 +441,6 @@ int __connman_ippool_init(void)
block_24_bits = ntohl(inet_addr("10.0.0.0"));
subnet_mask_24 = ntohl(inet_addr("255.255.255.0"));

- pool_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL,
- pool_free);
-
return 0;
}

@@ -460,9 +448,6 @@ void __connman_ippool_cleanup(void)
{
DBG("");

- g_hash_table_destroy(pool_hash);
- pool_hash = NULL;
-
g_slist_free_full(allocated_blocks, g_free);
last_block = 0;
allocated_blocks = NULL;
--
2.1.4
Patrik Flykt
2015-10-23 11:38:13 UTC
Permalink
When enabling and disabling tethering, the next available class C
IPv4 subnet will be assigned and not the same one as last time.

Fix this by starting with the last allocated block instead of
unconditionally with the next free block. This way the subnet used
for tethering will be the same as the previous time unless the subnet
block is unavailable due to other reasons. Note that even with this
change the subnet user for tethering is not guaranteed to always
stay the same.

Fixes CM-666.
---
src/ippool.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/ippool.c b/src/ippool.c
index bb8568d..06f3762 100644
--- a/src/ippool.c
+++ b/src/ippool.c
@@ -181,10 +181,10 @@ static uint32_t get_free_block(unsigned int size)
* To only thing we have to make sure is that we terminated if
* there is no block left.
*/
- if (last_block == 0)
- block = block_16_bits;
+ if (last_block)
+ block = last_block;
else
- block = next_block(last_block);
+ block = block_16_bits;

do {
collision = false;
--
2.1.4
Patrik Flykt
2015-10-28 09:13:34 UTC
Permalink
Hi,
Here is a simple fix for reusing the same IPv4 subnet when tethering.
As before, the subnet is not guaranteed to always stay the same, but
with this change its previous value should be reused if nothing else
causes it to be changed.
The second patch removes an unused hash from ippool.c
Applied.

Patrik

Loading...