diff options
Diffstat (limited to 'proto/bmp/map.c')
-rw-r--r-- | proto/bmp/map.c | 74 |
1 files changed, 19 insertions, 55 deletions
diff --git a/proto/bmp/map.c b/proto/bmp/map.c index e9a37266..f8219dcc 100644 --- a/proto/bmp/map.c +++ b/proto/bmp/map.c @@ -7,7 +7,6 @@ */ #include "proto/bmp/map.h" -#include "proto/bmp/utils.h" /* Peer Index Table */ #define PEER_KEY(n) (n)->peer_as, (n)->peer_ip @@ -23,18 +22,11 @@ HASH_DEFINE_REHASH_FN(PEER, struct bmp_peer_map_key) #define PEER_INIT_ORDER 6 -enum bmp_result +void bmp_peer_map_init(struct bmp_peer_map *map, pool *mpool) { - if (IS_NULL(map) || IS_NULL(mpool)) - { - return BMP_E_NULL_REF; - } - map->mpool = mpool; HASH_INIT(map->peer_hash, map->mpool, PEER_INIT_ORDER); - - return BMP_E_NONE; } struct bmp_peer_map_key @@ -48,14 +40,9 @@ bmp_peer_map_key_create(const ip_addr peer_ip, const u32 peer_as) return key; } -enum bmp_result +void bmp_peer_map_flush(struct bmp_peer_map *map) { - if (IS_NULL(map)) - { - return BMP_E_NULL_REF; - } - struct bmp_peer_map_entry *entry; HASH_WALK_DELSAFE(map->peer_hash, next, e) { @@ -67,78 +54,55 @@ bmp_peer_map_flush(struct bmp_peer_map *map) HASH_WALK_DELSAFE_END; HASH_MAY_RESIZE_DOWN(map->peer_hash, PEER, map->mpool); - return BMP_E_NONE; } -enum bmp_result +void bmp_peer_map_free(struct bmp_peer_map *map) { - if (IS_NULL(map)) - { - return BMP_E_NULL_REF; - } - - IF_BMP_FAILED_RETURN_RC(bmp_peer_map_flush(map)); + bmp_peer_map_flush(map); HASH_FREE(map->peer_hash); - - return BMP_E_NONE; } -enum bmp_result +void bmp_peer_map_insert(struct bmp_peer_map *map, const struct bmp_peer_map_key key, const byte *data, const size_t data_size) { - if (IS_NULL(map)) - { - return BMP_E_NULL_REF; - } + struct bmp_peer_map_entry *entry + = (void *) HASH_FIND(map->peer_hash, PEER, PEER_KEY(&key)); - if (HASH_FIND(map->peer_hash, PEER, PEER_KEY(&key))) + if (entry) { - return BMP_E_EXISTS; + mb_free(entry->data.buf); + entry->data.buf = mb_alloc(map->mpool, data_size); + memcpy(entry->data.buf, data, data_size); + entry->data.buf_size = data_size; + return; } - struct bmp_peer_map_entry *entry = mb_alloc(map->mpool, - sizeof (struct bmp_peer_map_entry)); + entry = mb_alloc(map->mpool, sizeof (struct bmp_peer_map_entry)); entry->data.buf = mb_alloc(map->mpool, data_size); memcpy(entry->data.buf, data, data_size); entry->data.buf_size = data_size; entry->key = key; HASH_INSERT2(map->peer_hash, PEER, map->mpool, &entry->key); - - return BMP_E_NONE; } -enum bmp_result +void bmp_peer_map_remove(struct bmp_peer_map *map, const struct bmp_peer_map_key key) { - if (IS_NULL(map)) - { - return BMP_E_NULL_REF; - } - struct bmp_peer_map_entry *entry - = (struct bmp_peer_map_entry *) HASH_FIND(map->peer_hash, PEER, PEER_KEY(&key)); - if (IS_NULL(entry)) - { - return BMP_E_NOT_EXISTS; - } + = (void *) HASH_DELETE(map->peer_hash, PEER, PEER_KEY(&key)); + + if (!entry) + return; mb_free(entry->data.buf); - HASH_DELETE(map->peer_hash, PEER, PEER_KEY(&entry->key)); mb_free(entry); - - return BMP_E_NONE; } const struct bmp_peer_map_entry * bmp_peer_map_get(struct bmp_peer_map *map, const struct bmp_peer_map_key key) { - if (IS_NULL(map)) - { - return NULL; - } - return (struct bmp_peer_map_entry *) HASH_FIND(map->peer_hash, PEER, PEER_KEY(&key)); } |