* Connection Manager
*
* Copyright (C) 2007-2013 Intel Corporation. All rights reserved.
- * Copyright (C) 2012-2013 BMW Car IT GmbH. All rights reserved.
+ * Copyright (C) 2012-2014 BMW Car IT GmbH.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-#include <sys/errno.h>
#include <sys/socket.h>
#include "connman.h"
};
struct connman_ippool {
- unsigned int refcount;
-
struct address_info *info;
char *gateway;
};
GSList *allocated_blocks;
-GHashTable *pool_hash;
static uint32_t last_block;
static uint32_t block_16_bits;
static uint32_t block_24_bits;
static uint32_t subnet_mask_24;
-struct connman_ippool *
-__connman_ippool_ref_debug(struct connman_ippool *pool,
- const char *file, int line, const char *caller)
-{
- DBG("%p ref %d by %s:%d:%s()", pool, pool->refcount + 1,
- file, line, caller);
-
- __sync_fetch_and_add(&pool->refcount, 1);
-
- return pool;
-}
-
-void __connman_ippool_unref_debug(struct connman_ippool *pool,
- const char *file, int line, const char *caller)
+void __connman_ippool_free(struct connman_ippool *pool)
{
if (!pool)
return;
- DBG("%p ref %d by %s:%d:%s()", pool, pool->refcount - 1,
- file, line, caller);
+ if (pool->info) {
+ allocated_blocks = g_slist_remove(allocated_blocks, pool->info);
+ g_free(pool->info);
+ }
- if (__sync_fetch_and_sub(&pool->refcount, 1) != 1)
- return;
+ g_free(pool->gateway);
+ g_free(pool->broadcast);
+ g_free(pool->start_ip);
+ g_free(pool->end_ip);
+ g_free(pool->subnet_mask);
- g_hash_table_remove(pool_hash, pool);
+ g_free(pool);
}
static char *get_ip(uint32_t ip)
* 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;
info->start = block;
info->end = block + range;
- pool->refcount = 1;
pool->info = info;
pool->collision_cb = collision_cb;
pool->user_data = user_data;
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;
}
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("");
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;
}
{
DBG("");
- g_hash_table_destroy(pool_hash);
- pool_hash = NULL;
-
g_slist_free_full(allocated_blocks, g_free);
last_block = 0;
allocated_blocks = NULL;