Ejemplo n.º 1
0
/**
 * add new entry
 */
static void
_add_new(netsnmp_systemstats_entry *systemstats_entry,
         netsnmp_container *container)
{
    ipSystemStatsTable_rowreq_ctx *rowreq_ctx;

    DEBUGMSGTL(("ipSystemStatsTable:access", "creating new entry\n"));

    netsnmp_assert(NULL != systemstats_entry);
    netsnmp_assert(NULL != container);

    /*
     * allocate an row context and set the index(es)
     */
    rowreq_ctx =
        ipSystemStatsTable_allocate_rowreq_ctx(systemstats_entry, NULL);
    if ((NULL != rowreq_ctx)
        && (MFD_SUCCESS ==
            ipSystemStatsTable_indexes_set(rowreq_ctx,
                                           systemstats_entry->
                                           index[0]))) {
        rowreq_ctx->ipSystemStatsRefreshRate = ipss_cache_refresh * 1000;       /* milli-seconds */
        CONTAINER_INSERT(container, rowreq_ctx);
    } else {
        if (NULL != rowreq_ctx) {
            snmp_log(LOG_ERR, "error setting index while loading "
                     "ipSystemStatsTable cache.\n");
            ipSystemStatsTable_release_rowreq_ctx(rowreq_ctx);
        } else {
            snmp_log(LOG_ERR, "memory allocation failed while loading "
                     "ipSystemStatsTable cache.\n");
            netsnmp_access_systemstats_entry_free(systemstats_entry);
        }
    }
}
/**
 * @internal
 */
static void
_container_item_free(ipSystemStatsTable_rowreq_ctx * rowreq_ctx,
                     void *context)
{
    DEBUGMSGTL(("internal:ipSystemStatsTable:_container_item_free",
                "called\n"));

    if (NULL == rowreq_ctx)
        return;

    ipSystemStatsTable_release_rowreq_ctx(rowreq_ctx);
}                               /* _container_item_free */
/*
 *********************************************************************
 * @internal
 * allocate resources for a ipSystemStatsTable_rowreq_ctx
 */
ipSystemStatsTable_rowreq_ctx *
ipSystemStatsTable_allocate_rowreq_ctx(ipSystemStatsTable_data * data,
                                       void *user_init_ctx)
{
    ipSystemStatsTable_rowreq_ctx *rowreq_ctx =
        SNMP_MALLOC_TYPEDEF(ipSystemStatsTable_rowreq_ctx);

    DEBUGMSGTL(("internal:ipSystemStatsTable:ipSystemStatsTable_allocate_rowreq_ctx", "called\n"));

    if (NULL == rowreq_ctx) {
        snmp_log(LOG_ERR, "Couldn't allocate memory for a "
                 "ipSystemStatsTable_rowreq_ctx.\n");
        return NULL;
    } else {
        if (NULL != data) {
            /*
             * track if we got data from user
             */
            rowreq_ctx->rowreq_flags |= MFD_ROW_DATA_FROM_USER;
            rowreq_ctx->data = data;
        } else if (NULL ==
                   (rowreq_ctx->data =
                    ipSystemStatsTable_allocate_data())) {
            SNMP_FREE(rowreq_ctx);
            return NULL;
        }
    }

    /*
     * undo context will be allocated when needed (in *_undo_setup)
     */

    rowreq_ctx->oid_idx.oids = rowreq_ctx->oid_tmp;

    rowreq_ctx->ipSystemStatsTable_data_list = NULL;

    /*
     * if we allocated data, call init routine
     */
    if (!(rowreq_ctx->rowreq_flags & MFD_ROW_DATA_FROM_USER)) {
        if (SNMPERR_SUCCESS !=
            ipSystemStatsTable_rowreq_ctx_init(rowreq_ctx,
                                               user_init_ctx)) {
            ipSystemStatsTable_release_rowreq_ctx(rowreq_ctx);
            rowreq_ctx = NULL;
        }
    }

    return rowreq_ctx;
}                               /* ipSystemStatsTable_allocate_rowreq_ctx */
/**
 * @internal
 * wrapper
 */
static int
_mfd_ipSystemStatsTable_post_request(netsnmp_mib_handler *handler,
                                     netsnmp_handler_registration *reginfo,
                                     netsnmp_agent_request_info
                                     *agtreq_info,
                                     netsnmp_request_info *requests)
{
    ipSystemStatsTable_rowreq_ctx *rowreq_ctx =
        netsnmp_container_table_row_extract(requests);
    int             rc, packet_rc;

    DEBUGMSGTL(("internal:ipSystemStatsTable:_mfd_ipSystemStatsTable_post_request", "called\n"));

    /*
     * release row context, if deleted
     */
    if (rowreq_ctx && (rowreq_ctx->rowreq_flags & MFD_ROW_DELETED))
        ipSystemStatsTable_release_rowreq_ctx(rowreq_ctx);

    /*
     * wait for last call before calling user
     */
    if (1 != netsnmp_row_merge_status_last(reginfo, agtreq_info)) {
        DEBUGMSGTL(("internal:ipSystemStatsTable",
                    "waiting for last post_request\n"));
        return SNMP_ERR_NOERROR;
    }

    packet_rc = netsnmp_check_all_requests_error(agtreq_info->asp, 0);
    rc = ipSystemStatsTable_post_request(ipSystemStatsTable_if_ctx.
                                         user_ctx, packet_rc);
    if (MFD_SUCCESS != rc) {
        /*
         * nothing we can do about it but log it
         */
        DEBUGMSGTL(("ipSystemStatsTable", "error %d from "
                    "ipSystemStatsTable_post_request\n", rc));
    }

    return SNMP_ERR_NOERROR;
}                               /* _mfd_ipSystemStatsTable_post_request */