Esempio n. 1
0
void
vr_fragment_table_exit(struct vrouter *router)
{
    vr_fragment_table_scanner_exit(router);

    if (router->vr_fragment_table)
        vr_btable_free(router->vr_fragment_table);
    if (router->vr_fragment_otable)
        vr_btable_free(router->vr_fragment_otable);

    return;
}
Esempio n. 2
0
void
vr_mpls_exit(struct vrouter *router, bool soft_reset)
{
    unsigned int i;
    struct vr_nexthop *nh;

    if (!router->vr_max_labels || !router->vr_ilm)
        return;

    for (i = 0; i < router->vr_max_labels; i++) {
        nh = __vrouter_get_label(router, i);
        if (nh) {
            vrouter_put_nexthop(nh);
            __vrouter_set_label(router, i, NULL);
        }
    }

    if (soft_reset == false) {
        vr_btable_free(router->vr_ilm);
        router->vr_ilm = NULL;
        router->vr_max_labels = 0;
    }

    return;
}
Esempio n. 3
0
static void
vr_flow_table_destroy(struct vrouter *router)
{
    if (router->vr_flow_table) {
        vr_btable_free(router->vr_flow_table);
        router->vr_flow_table = NULL;
    }

    if (router->vr_oflow_table) {
        vr_btable_free(router->vr_oflow_table);
        router->vr_oflow_table = NULL;
    }

    vr_flow_table_info_destroy(router);

    return;
}
Esempio n. 4
0
void
vr_htable_delete(vr_htable_t htable)
{
    struct vr_htable *table = (struct vr_htable *)htable;

    if (!table)
        return;

    if (table->ht_htable)
        vr_btable_free(table->ht_htable);

    if (table->ht_otable)
        vr_btable_free(table->ht_otable);

    if (table->ht_dtable)
        vr_btable_free(table->ht_dtable);

    vr_free(table, VR_HTABLE_OBJECT);

    return;
}
Esempio n. 5
0
struct vr_btable *
vr_btable_alloc(unsigned int num_entries, unsigned int entry_size)
{
    unsigned int i = 0, num_parts, remainder;
    unsigned int total_parts;
    uint64_t total_mem;
    struct vr_btable *table;
    unsigned int offset = 0;

    total_mem = num_entries * entry_size;

    num_parts = total_mem / VR_SINGLE_ALLOC_LIMIT;
    remainder = total_mem % VR_SINGLE_ALLOC_LIMIT;

    total_parts = num_parts;
    /*
     * anything left over that is not a multiple of VR_SINGLE_ALLOC_LIMIT
     * gets accomodated in the remainder, and hence an extra partition has
     * to be given
     */
    if (remainder)
        total_parts++;

    if (num_parts) {
        /*
         * the entry size has to be a factor of VR_SINGLE_ALLOC limit.
         * otherwise, we might access memory beyond the allocated chunk
         * while accessing the last entry
         */
        if (VR_SINGLE_ALLOC_LIMIT % entry_size)
            return NULL;
    }

    if (!total_parts)
        return NULL;

    table = vr_zalloc(sizeof(*table));
    if (!table)
        return NULL;

    table->vb_mem = vr_zalloc(total_parts * sizeof(void *));
    table->vb_table_info = vr_zalloc(total_parts *
            sizeof(struct vr_btable_partition));
    if (!table->vb_mem || !table->vb_table_info)
        goto exit_alloc;

    if (num_parts) {
        for (i = 0; i < num_parts; i++) {
            table->vb_mem[i] = vr_page_alloc(VR_SINGLE_ALLOC_LIMIT);
            if (!table->vb_mem[i])
                goto exit_alloc;
            table->vb_table_info[i].vb_mem_size = VR_SINGLE_ALLOC_LIMIT;
            table->vb_table_info[i].vb_offset = offset;
            offset += table->vb_table_info[i].vb_mem_size;
            table->vb_partitions++;
        }
    }

    if (remainder) {
        table->vb_mem[i] = vr_page_alloc(remainder);
        if (!table->vb_mem[i])
            goto exit_alloc;
        table->vb_table_info[i].vb_mem_size = remainder;
        table->vb_table_info[i].vb_offset = offset;
        table->vb_partitions++;
    }

    table->vb_entries = num_entries;
    table->vb_esize = entry_size;

    return table;

exit_alloc:
    vr_btable_free(table);
    return NULL;
}
Esempio n. 6
0
struct vr_btable *
vr_btable_alloc(unsigned int num_entries, unsigned int entry_size)
{
    unsigned int i = 0, num_parts, remainder;
    uint64_t total_mem;
    struct vr_btable *table;
    unsigned int offset = 0;

    total_mem = num_entries * entry_size;
    /* need more testing. that's all */
    if (total_mem > VR_KNOWN_BIG_MEM_LIMIT)
        return NULL;

    table = vr_zalloc(sizeof(*table));
    if (!table)
        return NULL;

    num_parts = total_mem / VR_SINGLE_ALLOC_LIMIT;
    remainder = total_mem % VR_SINGLE_ALLOC_LIMIT;
    if (num_parts + !!remainder > VR_MAX_BTABLE_ENTRIES)
        return NULL;

    if (num_parts) {
        /*
         * the entry size has to be a factor of VR_SINGLE_ALLOC limit.
         * otherwise, we might access memory beyond the allocated chunk
         * while accessing the last entry
         */
        if (VR_SINGLE_ALLOC_LIMIT % entry_size)
            return NULL;
    }

    if (num_parts) {
        for (i = 0; i < num_parts; i++) {
            table->vb_mem[i] = vr_page_alloc(VR_SINGLE_ALLOC_LIMIT);
            if (!table->vb_mem[i])
                goto exit_alloc;
            table->vb_table_info[i].vb_mem_size = VR_SINGLE_ALLOC_LIMIT;
            table->vb_table_info[i].vb_offset = offset;
            offset += table->vb_table_info[i].vb_mem_size;
        }
        table->vb_partitions = num_parts;
    }

    if (remainder) {
        table->vb_mem[i] = vr_page_alloc(remainder);
        if (!table->vb_mem[i])
            goto exit_alloc;
        table->vb_table_info[i].vb_mem_size = remainder;
        table->vb_table_info[i].vb_offset = offset;
        table->vb_partitions++;
    }

    table->vb_entries = num_entries;
    table->vb_esize = entry_size;

    return table;

exit_alloc:
    vr_btable_free(table);
    return NULL;
}