⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ipcidrroutetable_interface.c

📁 开发snmp的开发包有两个开放的SNMP开发库
💻 C
📖 第 1 页 / 共 5 页
字号:
    /*     * ipCidrRouteNextHop(4)/IPADDR/ASN_IPADDRESS/u_long(u_long)//l/A/w/e/r/d/h     */    netsnmp_variable_list var_ipCidrRouteNextHop;    /*     * set up varbinds     */    memset(&var_ipCidrRouteDest, 0x00, sizeof(var_ipCidrRouteDest));    var_ipCidrRouteDest.type = ASN_PRIV_IMPLIED_OCTET_STR;    memset(&var_ipCidrRouteMask, 0x00, sizeof(var_ipCidrRouteMask));    var_ipCidrRouteMask.type = ASN_PRIV_IMPLIED_OCTET_STR;    memset(&var_ipCidrRouteTos, 0x00, sizeof(var_ipCidrRouteTos));    var_ipCidrRouteTos.type = ASN_INTEGER;    memset(&var_ipCidrRouteNextHop, 0x00, sizeof(var_ipCidrRouteNextHop));    var_ipCidrRouteNextHop.type = ASN_PRIV_IMPLIED_OCTET_STR;    /*     * chain temp index varbinds together     */    var_ipCidrRouteDest.next_variable = &var_ipCidrRouteMask;    var_ipCidrRouteMask.next_variable = &var_ipCidrRouteTos;    var_ipCidrRouteTos.next_variable = &var_ipCidrRouteNextHop;    var_ipCidrRouteNextHop.next_variable = NULL;    DEBUGMSGTL(("verbose:ipCidrRouteTable:ipCidrRouteTable_index_to_oid",                "called\n"));    /*     * ipCidrRouteDest(1)/IPADDR/ASN_IPADDRESS/u_long(u_long)//l/A/w/e/r/d/h      */    snmp_set_var_value(&var_ipCidrRouteDest,                       (u_char *) & mib_idx->ipCidrRouteDest,                       sizeof(mib_idx->ipCidrRouteDest));    /*     * ipCidrRouteMask(2)/IPADDR/ASN_IPADDRESS/u_long(u_long)//l/A/w/e/r/d/h      */    snmp_set_var_value(&var_ipCidrRouteMask,                       (u_char *) & mib_idx->ipCidrRouteMask,                       sizeof(mib_idx->ipCidrRouteMask));    /*     * ipCidrRouteTos(3)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/R/d/h      */    snmp_set_var_value(&var_ipCidrRouteTos,                       (u_char *) & mib_idx->ipCidrRouteTos,                       sizeof(mib_idx->ipCidrRouteTos));    /*     * ipCidrRouteNextHop(4)/IPADDR/ASN_IPADDRESS/u_long(u_long)//l/A/w/e/r/d/h      */    snmp_set_var_value(&var_ipCidrRouteNextHop,                       (u_char *) & mib_idx->ipCidrRouteNextHop,                       sizeof(mib_idx->ipCidrRouteNextHop));    err = build_oid_noalloc(oid_idx->oids, oid_idx->len, &oid_idx->len,                            NULL, 0, &var_ipCidrRouteDest);    if (err)        snmp_log(LOG_ERR, "error %d converting index to oid\n", err);    /*     * parsing may have allocated memory. free it.     */    snmp_reset_var_buffers(&var_ipCidrRouteDest);    return err;}                               /* ipCidrRouteTable_index_to_oid *//** * extract ipCidrRouteTable indexes from a netsnmp_index * * @retval SNMP_ERR_NOERROR  : no error * @retval SNMP_ERR_GENERR   : error */intipCidrRouteTable_index_from_oid(netsnmp_index * oid_idx,                                ipCidrRouteTable_mib_index * mib_idx){    int             err = SNMP_ERR_NOERROR;    /*     * temp storage for parsing indexes     */    /*     * ipCidrRouteDest(1)/IPADDR/ASN_IPADDRESS/u_long(u_long)//l/A/w/e/r/d/h     */    netsnmp_variable_list var_ipCidrRouteDest;    /*     * ipCidrRouteMask(2)/IPADDR/ASN_IPADDRESS/u_long(u_long)//l/A/w/e/r/d/h     */    netsnmp_variable_list var_ipCidrRouteMask;    /*     * ipCidrRouteTos(3)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/R/d/h     */    netsnmp_variable_list var_ipCidrRouteTos;    /*     * ipCidrRouteNextHop(4)/IPADDR/ASN_IPADDRESS/u_long(u_long)//l/A/w/e/r/d/h     */    netsnmp_variable_list var_ipCidrRouteNextHop;    /*     * set up varbinds     */    memset(&var_ipCidrRouteDest, 0x00, sizeof(var_ipCidrRouteDest));    var_ipCidrRouteDest.type = ASN_IPADDRESS;    memset(&var_ipCidrRouteMask, 0x00, sizeof(var_ipCidrRouteMask));    var_ipCidrRouteMask.type = ASN_IPADDRESS;    memset(&var_ipCidrRouteTos, 0x00, sizeof(var_ipCidrRouteTos));    var_ipCidrRouteTos.type = ASN_INTEGER;    memset(&var_ipCidrRouteNextHop, 0x00, sizeof(var_ipCidrRouteNextHop));    var_ipCidrRouteNextHop.type = ASN_IPADDRESS;    /*     * chain temp index varbinds together     */    var_ipCidrRouteDest.next_variable = &var_ipCidrRouteMask;    var_ipCidrRouteMask.next_variable = &var_ipCidrRouteTos;    var_ipCidrRouteTos.next_variable = &var_ipCidrRouteNextHop;    var_ipCidrRouteNextHop.next_variable = NULL;    DEBUGMSGTL(("verbose:ipCidrRouteTable:ipCidrRouteTable_index_from_oid",                "called\n"));    /*     * parse the oid into the individual index components     */    err = parse_oid_indexes(oid_idx->oids, oid_idx->len,                            &var_ipCidrRouteDest);    if (err == SNMP_ERR_NOERROR) {        /*         * copy out values         */        mib_idx->ipCidrRouteDest =            *((u_long *) var_ipCidrRouteDest.val.string);        mib_idx->ipCidrRouteMask =            *((u_long *) var_ipCidrRouteMask.val.string);        mib_idx->ipCidrRouteTos =            *((long *) var_ipCidrRouteTos.val.string);        mib_idx->ipCidrRouteNextHop =            *((u_long *) var_ipCidrRouteNextHop.val.string);    }    /*     * parsing may have allocated memory. free it.     */    snmp_reset_var_buffers(&var_ipCidrRouteDest);    return err;}                               /* ipCidrRouteTable_index_from_oid *//* ********************************************************************* * @internal * allocate resources for a ipCidrRouteTable_rowreq_ctx */ipCidrRouteTable_rowreq_ctx *ipCidrRouteTable_allocate_rowreq_ctx(ipCidrRouteTable_data * data,                                     void *user_init_ctx){    ipCidrRouteTable_rowreq_ctx *rowreq_ctx =        SNMP_MALLOC_TYPEDEF(ipCidrRouteTable_rowreq_ctx);    DEBUGMSGTL(("internal:ipCidrRouteTable:ipCidrRouteTable_allocate_rowreq_ctx", "called\n"));    if (NULL == rowreq_ctx) {        snmp_log(LOG_ERR, "Couldn't allocate memory for a "                 "ipCidrRouteTable_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 = ipCidrRouteTable_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->ipCidrRouteTable_data_list = NULL;    /*     * if we allocated data, call init routine     */    if (!(rowreq_ctx->rowreq_flags & MFD_ROW_DATA_FROM_USER)) {        if (SNMPERR_SUCCESS !=            ipCidrRouteTable_rowreq_ctx_init(rowreq_ctx, user_init_ctx)) {            ipCidrRouteTable_release_rowreq_ctx(rowreq_ctx);            rowreq_ctx = NULL;        }    }    return rowreq_ctx;}                               /* ipCidrRouteTable_allocate_rowreq_ctx *//* * @internal * release resources for a ipCidrRouteTable_rowreq_ctx */voidipCidrRouteTable_release_rowreq_ctx(ipCidrRouteTable_rowreq_ctx *                                    rowreq_ctx){    DEBUGMSGTL(("internal:ipCidrRouteTable:ipCidrRouteTable_release_rowreq_ctx", "called\n"));    netsnmp_assert(NULL != rowreq_ctx);    ipCidrRouteTable_rowreq_ctx_cleanup(rowreq_ctx);    /*     * for non-transient data, don't free data we got from the user     */    if ((rowreq_ctx->data) &&        !(rowreq_ctx->rowreq_flags & MFD_ROW_DATA_FROM_USER))        ipCidrRouteTable_release_data(rowreq_ctx->data);    if (rowreq_ctx->undo)        ipCidrRouteTable_release_data(rowreq_ctx->undo);    /*     * free index oid pointer     */    if (rowreq_ctx->oid_idx.oids != rowreq_ctx->oid_tmp)        free(rowreq_ctx->oid_idx.oids);    SNMP_FREE(rowreq_ctx);}                               /* ipCidrRouteTable_release_rowreq_ctx *//** * @internal * wrapper */static int_mfd_ipCidrRouteTable_pre_request(netsnmp_mib_handler *handler,                                  netsnmp_handler_registration *reginfo,                                  netsnmp_agent_request_info *agtreq_info,                                  netsnmp_request_info *requests){    int             rc;    DEBUGMSGTL(("internal:ipCidrRouteTable:_mfd_ipCidrRouteTable_pre_request", "called\n"));    if (1 != netsnmp_row_merge_status_first(reginfo, agtreq_info)) {        DEBUGMSGTL(("internal:ipCidrRouteTable",                    "skipping additional pre_request\n"));        return SNMP_ERR_NOERROR;    }    rc = ipCidrRouteTable_pre_request(ipCidrRouteTable_if_ctx.user_ctx);    if (MFD_SUCCESS != rc) {        /*         * nothing we can do about it but log it         */        DEBUGMSGTL(("ipCidrRouteTable", "error %d from "                    "ipCidrRouteTable_pre_request\n", rc));        netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc));    }    return SNMP_ERR_NOERROR;}                               /* _mfd_ipCidrRouteTable_pre_request *//** * @internal * wrapper */static int_mfd_ipCidrRouteTable_post_request(netsnmp_mib_handler *handler,                                   netsnmp_handler_registration *reginfo,                                   netsnmp_agent_request_info *agtreq_info,                                   netsnmp_request_info *requests){    ipCidrRouteTable_rowreq_ctx *rowreq_ctx =        netsnmp_container_table_row_extract(requests);    int             rc, packet_rc;    DEBUGMSGTL(("internal:ipCidrRouteTable:_mfd_ipCidrRouteTable_post_request", "called\n"));    /*     * release row context, if deleted     */    if (rowreq_ctx && (rowreq_ctx->rowreq_flags & MFD_ROW_DELETED))        ipCidrRouteTable_release_rowreq_ctx(rowreq_ctx);    /*     * wait for last call before calling user     */    if (1 != netsnmp_row_merge_status_last(reginfo, agtreq_info)) {        DEBUGMSGTL(("internal:ipCidrRouteTable",                    "waiting for last post_request\n"));        return SNMP_ERR_NOERROR;    }    packet_rc = netsnmp_check_all_requests_error(agtreq_info->asp, 0);    if ((MFD_SUCCESS != packet_rc) && ipCidrRouteTable_dirty_get()) {        /*         * we shouldn't get here. the undo steps should also clear         * the dirty flags.         */        snmp_log(LOG_WARNING,                 "ipCidrRouteTable dirty flag set in post_request "                 "but status != SUCCESS.\n");    }    rc = ipCidrRouteTable_post_request(ipCidrRouteTable_if_ctx.user_ctx,                                       packet_rc);    if (MFD_SUCCESS != rc) {        /*         * nothing we can do about it but log it         */        DEBUGMSGTL(("ipCidrRouteTable", "error %d from "                    "ipCidrRouteTable_post_request\n", rc));    }    return SNMP_ERR_NOERROR;}                               /* _mfd_ipCidrRouteTable_post_request *//** * @internal * wrapper */static ipCidrRouteTable_rowreq_ctx *_mfd_ipCidrRouteTable_rowreq_from_index(netsnmp_index * oid_idx,                                        int *rc_ptr){    ipCidrRouteTable_rowreq_ctx *rowreq_ctx;    ipCidrRouteTable_mib_index mib_idx;    int             rc;    DEBUGMSGTL(("internal:ipCidrRouteTable:_mfd_ipCidrRouteTable_rowreq_from_index", "called\n"));    if (NULL == rc_ptr)        rc_ptr = &rc;    *rc_ptr = MFD_SUCCESS;    memset(&mib_idx, 0x0, sizeof(mib_idx));    /*     * try to parse oid     */    *rc_ptr = ipCidrRouteTable_index_from_oid(oid_idx, &mib_idx);    if (MFD_SUCCESS != *rc_ptr) {        DEBUGMSGT(("ipCidrRouteTable", "error parsing index\n"));        return NULL;    }    /*     * allocate new context     */    rowreq_ctx = ipCidrRouteTable_allocate_rowreq_ctx(NULL, NULL);    if (NULL == rowreq_ctx) {        *rc_ptr = MFD_ERROR;        return NULL;            /* msg already logged */    }    memcpy(&rowreq_ctx->tbl_idx, &mib_idx, sizeof(mib_idx));    /*     * check indexes     */    *rc_ptr = _ipCidrRouteTable_check_indexes(rowreq_ctx);    if (MFD_SUCCESS != *rc_ptr) {        netsnmp_assert((*rc_ptr == SNMP_ERR_NOCREATION) ||                       (*rc_ptr == SNMP_ERR_INCONSISTENTNAME));        ipCidrRouteTable_release_rowreq_ctx(rowreq_ctx);        return NULL;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -