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

📄 ipcidrroutetable_interface.c

📁 snmp的源代码,已经在我的ubuntu下编译通过
💻 C
📖 第 1 页 / 共 5 页
字号:
 * * @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){    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");    } else {        if (NULL != data) {            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;    rowreq_ctx->ipCidrRouteTable_reg = ipCidrRouteTable_if_ctx.user_ctx;    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);    if (rowreq_ctx->data)        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 =        ipCidrRouteTable_pre_request(ipCidrRouteTable_if_ctx.user_ctx);    if (MFD_SUCCESS != rc) {        /*         * nothing we can do about it but log it         */        DEBUGMSGTL(("internal: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;    int             rc =        ipCidrRouteTable_post_request(ipCidrRouteTable_if_ctx.user_ctx);    if (MFD_SUCCESS != rc) {        /*         * nothing we can do about it but log it         */        DEBUGMSGTL(("internal:ipCidrRouteTable", "error %d from "                    "ipCidrRouteTable_post_request\n", rc));    }    /*     * if it was set, clear row created flag.     */    rowreq_ctx = netsnmp_container_table_row_extract(requests);    if ((NULL != rowreq_ctx)        && (rowreq_ctx->rowreq_flags & MFD_ROW_CREATED))        rowreq_ctx->rowreq_flags &= ~MFD_ROW_CREATED;    return SNMP_ERR_NOERROR;}                               /* _mfd_ipCidrRouteTable_post_request *//** * @internal * wrapper */static int_mfd_ipCidrRouteTable_object_lookup(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);    DEBUGMSGTL(("internal:ipCidrRouteTable:_mfd_ipCidrRouteTable_object_lookup", "called\n"));    /*     * get our context from mfd     * ipCidrRouteTable_interface_ctx *if_ctx =     *             (ipCidrRouteTable_interface_ctx *)reginfo->my_reg_void;     */    if (NULL == rowreq_ctx) {        int             rc = MFD_SUCCESS;        netsnmp_table_request_info *tblreq_info;        netsnmp_index   oid_idx;        ipCidrRouteTable_mib_index mib_idx;        tblreq_info = netsnmp_extract_table_info(requests);        if (NULL == tblreq_info) {            snmp_log(LOG_ERR, "request had no table info\n");            return MFD_ERROR;        }        /*         * try to parse oid         */        oid_idx.oids = tblreq_info->index_oid;        oid_idx.len = tblreq_info->index_oid_len;        rc = ipCidrRouteTable_index_from_oid(&oid_idx, &mib_idx);        if (MFD_SUCCESS != rc) {            DEBUGMSGT(("ipCidrRouteTable", "error parsing index\n"));            netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc));        } else {            /*             * allocate new context             */            rowreq_ctx = ipCidrRouteTable_allocate_rowreq_ctx(NULL);            if (NULL == rowreq_ctx)                return MFD_ERROR;       /* msg already logged */            memcpy(&rowreq_ctx->tbl_idx, &mib_idx, sizeof(mib_idx));            /*             * check indexes             */            rc = _ipCidrRouteTable_check_indexes(rowreq_ctx);            if (MFD_SUCCESS != rc) {                netsnmp_assert((rc == SNMP_ERR_NOCREATION) ||                               (rc == SNMP_ERR_INCONSISTENTNAME));                netsnmp_request_set_error_all(requests,                                              SNMP_VALIDATE_ERR(rc));                ipCidrRouteTable_release_rowreq_ctx(rowreq_ctx);            } else {                rowreq_ctx->rowreq_flags |= MFD_ROW_CREATED;                netsnmp_container_table_row_insert(requests, rowreq_ctx);            }        }    } else {        ipCidrRouteTable_row_prep(rowreq_ctx);    }    return SNMP_ERR_NOERROR;}                               /* _mfd_ipCidrRouteTable_object_lookup *//*********************************************************************** * * GET processing * ***********************************************************************//* * @internal * Retrieve the value for a particular column */NETSNMP_STATIC_INLINE int_ipCidrRouteTable_get_column(ipCidrRouteTable_rowreq_ctx * rowreq_ctx,                             netsnmp_variable_list * var, int column){    int             rc = SNMPERR_SUCCESS;    DEBUGMSGTL(("internal:ipCidrRouteTable:_mfd_ipCidrRouteTable_get_column", "called\n"));    netsnmp_assert(NULL != rowreq_ctx);    switch (column) {        /*         * (INDEX) ipCidrRouteDest(1)/IPADDR/ASN_IPADDRESS/u_long(u_long)//l/A/w/e/r/d/h          */    case COLUMN_IPCIDRROUTEDEST:        var->type = ASN_IPADDRESS;        var->val_len = sizeof(u_long);        (*var->val.integer) = rowreq_ctx->tbl_idx.ipCidrRouteDest;        break;        /*         * (INDEX) ipCidrRouteMask(2)/IPADDR/ASN_IPADDRESS/u_long(u_long)//l/A/w/e/r/d/h          */    case COLUMN_IPCIDRROUTEMASK:        var->type = ASN_IPADDRESS;        var->val_len = sizeof(u_long);        (*var->val.integer) = rowreq_ctx->tbl_idx.ipCidrRouteMask;        break;        /*         * (INDEX) ipCidrRouteTos(3)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/R/d/h          */    case COLUMN_IPCIDRROUTETOS:        var->type = ASN_INTEGER;        var->val_len = sizeof(long);        (*var->val.integer) = rowreq_ctx->tbl_idx.ipCidrRouteTos;        break;        /*         * (INDEX) ipCidrRouteNextHop(4)/IPADDR/ASN_IPADDRESS/u_long(u_long)//l/A/w/e/r/d/h          */    case COLUMN_IPCIDRROUTENEXTHOP:        var->type = ASN_IPADDRESS;        var->val_len = sizeof(u_long);        (*var->val.integer) = rowreq_ctx->tbl_idx.ipCidrRouteNextHop;        break;        /*         * ipCidrRouteIfIndex(5)/INTEGER32/ASN_INTEGER/long(long)//l/A/W/e/r/D/h          */    case COLUMN_IPCIDRROUTEIFINDEX:        var->val_len = sizeof(long);        var->type = ASN_INTEGER;        rc = ipCidrRouteIfIndex_get(rowreq_ctx, (long *) var->val.string);        break;        /*         * ipCidrRouteType(6)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h          */    case COLUMN_IPCIDRROUTETYPE:        var->val_len = sizeof(u_long);        var->type = ASN_INTEGER;        rc = ipCidrRouteType_get(rowreq_ctx, (u_long *) var->val.string);        break;        /*         * ipCidrRouteProto(7)/INTEGER/ASN_INTEGER/long(u_long)//l/A/w/E/r/d/h          */    case COLUMN_IPCIDRROUTEPROTO:        var->val_len = sizeof(u_long);        var->type = ASN_INTEGER;        rc = ipCidrRouteProto_get(rowreq_ctx, (u_long *) var->val.string);        break;        /*         * ipCidrRouteAge(8)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/r/D/h          */    case COLUMN_IPCIDRROUTEAGE:        var->val_len = sizeof(long);        var->type = ASN_INTEGER;        rc = ipCidrRouteAge_get(rowreq_ctx, (long *) var->val.string);        break;        /*         * ipCidrRouteInfo(9)/OBJECTID/ASN_OBJECT_ID/oid(oid)//L/A/W/e/r/d/h          */    case COLUMN_IPCIDRROUTEINFO:        var->type = ASN_OBJECT_ID;        rc = ipCidrRouteInfo_get(rowreq_ctx, (oid **) & var->val.string,                                 &var->val_len);

⌨️ 快捷键说明

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