/*
 * Remove all entries from sctpAssocLocalAddrTable, which are not marked as valid.
 * All valid entries are then marked as invalid (to delete them in next cache
 * load, if the entry is not updated). 
 */
void
sctpAssocLocalAddrTable_delete_invalid(netsnmp_container *localAddrTable)
{
    netsnmp_container *to_delete = netsnmp_container_find("lifo");

    CONTAINER_FOR_EACH(localAddrTable,
                       sctpAssocLocalAddrTable_collect_invalid, to_delete);

    while (CONTAINER_SIZE(to_delete)) {
        sctpAssocLocalAddrTable_entry *entry = CONTAINER_FIRST(to_delete);
        CONTAINER_REMOVE(localAddrTable, entry);
        sctpAssocLocalAddrTable_entry_free(entry);
        CONTAINER_REMOVE(to_delete, NULL);
    }
    CONTAINER_FREE(to_delete);
}
int
sctpAssocLocalAddrTable_add_or_update(netsnmp_container *localAddrTable,
                                      sctpAssocLocalAddrTable_entry *
                                      entry)
{
    /*
     * we have full sctpAssocLocalAddrTable entry, update or add it in the container 
     */
    sctpAssocLocalAddrTable_entry *old;

    entry->valid = 1;

    /*
     * try to find it in the container 
     */
    sctpAssocLocalAddrTable_entry_update_index(entry);
    old = CONTAINER_FIND(localAddrTable, entry);

    if (old != NULL) {
        /*
         * update existing entry, don't overwrite the timestamp
         */
        time_t          timestamp = old->sctpAssocLocalAddrStartTime;
        if (timestamp == 0 && entry->sctpAssocLocalAddrStartTime == 0)
            timestamp = netsnmp_get_agent_uptime();     /* set the timestamp if it was not set before */
        sctpAssocLocalAddrTable_entry_copy(entry, old);
        old->sctpAssocLocalAddrStartTime = timestamp;
        sctpAssocLocalAddrTable_entry_free(entry);

    } else {
        /*
         * the entry is new, add it there 
         */
        if (entry->sctpAssocLocalAddrStartTime == 0) {
            entry->sctpAssocLocalAddrStartTime =
                netsnmp_get_agent_uptime();
        }
        CONTAINER_INSERT(localAddrTable, entry);
    }

    return SNMP_ERR_NOERROR;
}
static void
sctpAssocLocalAddrTable_entry_clear(void *what, void *magic)
{
    sctpAssocLocalAddrTable_entry_free(what);
}