mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-22 17:51:53 +00:00
ID Map: Introducing a maximum limit for the ID
This commit is contained in:
parent
4e27fb34a1
commit
0972274dc3
@ -196,7 +196,7 @@ ca_lookup(pool *p, const char *name, int f_type)
|
|||||||
|
|
||||||
static int inited = 0;
|
static int inited = 0;
|
||||||
if (!inited) {
|
if (!inited) {
|
||||||
idm_init(&ca_idm, &root_pool, 8);
|
idm_init(&ca_idm, &root_pool, 8, EA_CUSTOM_BIT);
|
||||||
HASH_INIT(ca_hash, &root_pool, CA_ORDER);
|
HASH_INIT(ca_hash, &root_pool, CA_ORDER);
|
||||||
|
|
||||||
ca_storage_max = 256;
|
ca_storage_max = 256;
|
||||||
@ -212,7 +212,7 @@ ca_lookup(pool *p, const char *name, int f_type)
|
|||||||
|
|
||||||
uint id = idm_alloc(&ca_idm);
|
uint id = idm_alloc(&ca_idm);
|
||||||
|
|
||||||
if (id >= EA_CUSTOM_BIT)
|
if (!id)
|
||||||
cf_error("Too many custom attributes.");
|
cf_error("Too many custom attributes.");
|
||||||
|
|
||||||
if (id >= ca_storage_max) {
|
if (id >= ca_storage_max) {
|
||||||
|
27
lib/idm.c
27
lib/idm.c
@ -16,11 +16,12 @@
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
idm_init(struct idm *m, pool *p, uint size)
|
idm_init(struct idm *m, pool *p, u64 size, u64 max)
|
||||||
{
|
{
|
||||||
m->pos = 0;
|
m->pos = 0;
|
||||||
m->used = 1;
|
m->used = 1;
|
||||||
m->size = size;
|
m->size = size;
|
||||||
|
m->max = max;
|
||||||
m->data = mb_allocz(p, m->size * sizeof(u32));
|
m->data = mb_allocz(p, m->size * sizeof(u32));
|
||||||
|
|
||||||
/* ID 0 is reserved */
|
/* ID 0 is reserved */
|
||||||
@ -29,17 +30,17 @@ idm_init(struct idm *m, pool *p, uint size)
|
|||||||
|
|
||||||
static inline int u32_cto(uint x) { return ffs(~x) - 1; }
|
static inline int u32_cto(uint x) { return ffs(~x) - 1; }
|
||||||
|
|
||||||
u32
|
u64
|
||||||
idm_alloc(struct idm *m)
|
idm_alloc(struct idm *m)
|
||||||
{
|
{
|
||||||
uint i, j;
|
u64 i, j;
|
||||||
|
|
||||||
for (i = m->pos; i < m->size; i++)
|
for (i = m->pos; i < m->size; i++)
|
||||||
if (m->data[i] != 0xffffffff)
|
if (m->data[i] != 0xffffffff)
|
||||||
goto found;
|
goto found;
|
||||||
|
|
||||||
/* If we are at least 7/8 full, expand */
|
/* If we are at least 7/8 full, expand (if we are allowed to) */
|
||||||
if (m->used > (m->size * 28))
|
if ((m->used * 32 < m->max) && (m->used > m->size * 28))
|
||||||
{
|
{
|
||||||
m->size *= 2;
|
m->size *= 2;
|
||||||
m->data = mb_realloc(m->data, m->size * sizeof(u32));
|
m->data = mb_realloc(m->data, m->size * sizeof(u32));
|
||||||
@ -51,24 +52,26 @@ idm_alloc(struct idm *m)
|
|||||||
if (m->data[i] != 0xffffffff)
|
if (m->data[i] != 0xffffffff)
|
||||||
goto found;
|
goto found;
|
||||||
|
|
||||||
ASSERT(0);
|
return 0;
|
||||||
|
|
||||||
found:
|
found:
|
||||||
ASSERT(i < 0x8000000);
|
|
||||||
|
|
||||||
m->pos = i;
|
m->pos = i;
|
||||||
j = u32_cto(m->data[i]);
|
j = u32_cto(m->data[i]);
|
||||||
|
|
||||||
|
u64 id = 32 * i + j;
|
||||||
|
|
||||||
|
ASSERT(id < m->max);
|
||||||
|
|
||||||
m->data[i] |= (1 << j);
|
m->data[i] |= (1 << j);
|
||||||
m->used++;
|
m->used++;
|
||||||
return 32 * i + j;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
idm_free(struct idm *m, u32 id)
|
idm_free(struct idm *m, u64 id)
|
||||||
{
|
{
|
||||||
uint i = id / 32;
|
u64 i = id / 32;
|
||||||
uint j = id % 32;
|
u64 j = id % 32;
|
||||||
|
|
||||||
ASSERT((i < m->size) && (m->data[i] & (1 << j)));
|
ASSERT((i < m->size) && (m->data[i] & (1 << j)));
|
||||||
m->data[i] &= ~(1 << j);
|
m->data[i] &= ~(1 << j);
|
||||||
|
13
lib/idm.h
13
lib/idm.h
@ -13,13 +13,14 @@
|
|||||||
struct idm
|
struct idm
|
||||||
{
|
{
|
||||||
u32 *data;
|
u32 *data;
|
||||||
u32 pos;
|
u64 pos;
|
||||||
u32 used;
|
u64 used;
|
||||||
u32 size;
|
u64 size;
|
||||||
|
u64 max;
|
||||||
};
|
};
|
||||||
|
|
||||||
void idm_init(struct idm *m, pool *p, uint size);
|
void idm_init(struct idm *m, pool *p, u64 size, u64 max);
|
||||||
u32 idm_alloc(struct idm *m);
|
u64 idm_alloc(struct idm *m);
|
||||||
void idm_free(struct idm *m, u32 id);
|
void idm_free(struct idm *m, u64 id);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -40,7 +40,7 @@ tindex_new(pool *p)
|
|||||||
ti->unit_size = TI_MIN_UNIT_SIZE;
|
ti->unit_size = TI_MIN_UNIT_SIZE;
|
||||||
ti->address_size = TI_MIN_ADDRESS_SIZE;
|
ti->address_size = TI_MIN_ADDRESS_SIZE;
|
||||||
ti->index_data = mb_allocz(p, ti->unit_size * (1 << ti->address_size));
|
ti->index_data = mb_allocz(p, ti->unit_size * (1 << ti->address_size));
|
||||||
idm_init(&(ti->idm), p, (1 << ti->address_size));
|
idm_init(&(ti->idm), p, (1 << (ti->address_size - 5)), (1 << ti->address_size));
|
||||||
u32 rootnode = idm_alloc(&(ti->idm));
|
u32 rootnode = idm_alloc(&(ti->idm));
|
||||||
ASSERT(rootnode == 1);
|
ASSERT(rootnode == 1);
|
||||||
return ti;
|
return ti;
|
||||||
|
@ -111,7 +111,7 @@ rte_src_init(void)
|
|||||||
{
|
{
|
||||||
rte_src_slab = sl_new(rta_pool, sizeof(struct rte_src));
|
rte_src_slab = sl_new(rta_pool, sizeof(struct rte_src));
|
||||||
|
|
||||||
idm_init(&src_ids, rta_pool, SRC_ID_INIT_SIZE);
|
idm_init(&src_ids, rta_pool, SRC_ID_INIT_SIZE, 1ULL << 32);
|
||||||
|
|
||||||
HASH_INIT(src_hash, rta_pool, RSH_INIT_ORDER);
|
HASH_INIT(src_hash, rta_pool, RSH_INIT_ORDER);
|
||||||
}
|
}
|
||||||
@ -137,6 +137,7 @@ rt_get_source(struct proto *p, u32 id)
|
|||||||
src->proto = p;
|
src->proto = p;
|
||||||
src->private_id = id;
|
src->private_id = id;
|
||||||
src->global_id = idm_alloc(&src_ids);
|
src->global_id = idm_alloc(&src_ids);
|
||||||
|
ASSERT(src->global_id);
|
||||||
src->uc = 0;
|
src->uc = 0;
|
||||||
|
|
||||||
HASH_INSERT2(src_hash, RSH, rta_pool, src);
|
HASH_INSERT2(src_hash, RSH, rta_pool, src);
|
||||||
|
@ -257,7 +257,7 @@ ospf_start(struct proto *P)
|
|||||||
init_list(&(p->area_list));
|
init_list(&(p->area_list));
|
||||||
fib_init(&p->rtf, P->pool, ospf_get_af(p), sizeof(ort), OFFSETOF(ort, fn), 0, NULL);
|
fib_init(&p->rtf, P->pool, ospf_get_af(p), sizeof(ort), OFFSETOF(ort, fn), 0, NULL);
|
||||||
if (ospf_is_v3(p))
|
if (ospf_is_v3(p))
|
||||||
idm_init(&p->idm, P->pool, 16);
|
idm_init(&p->idm, P->pool, 16, 1ULL << 32);
|
||||||
p->areano = 0;
|
p->areano = 0;
|
||||||
p->gr = ospf_top_new(p, P->pool);
|
p->gr = ospf_top_new(p, P->pool);
|
||||||
s_init_list(&(p->lsal));
|
s_init_list(&(p->lsal));
|
||||||
|
@ -563,6 +563,7 @@ ort_to_lsaid(struct ospf_proto *p, ort *nf)
|
|||||||
if (!nf->lsa_id)
|
if (!nf->lsa_id)
|
||||||
nf->lsa_id = idm_alloc(&p->idm);
|
nf->lsa_id = idm_alloc(&p->idm);
|
||||||
|
|
||||||
|
ASSERT(nf->lsa_id);
|
||||||
return nf->lsa_id;
|
return nf->lsa_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user