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

📄 iftable_interface.c

📁 开发snmp的开发包有两个开放的SNMP开发库
💻 C
📖 第 1 页 / 共 4 页
字号:
        /*         * get column data         */        tri = netsnmp_extract_table_info(requests);        if (NULL == tri)            continue;        rc = _ifTable_get_column(rowreq_ctx, requests->requestvb,                                 tri->colnum);        if (rc) {            if (MFD_SKIP == rc) {                requests->requestvb->type = SNMP_NOSUCHINSTANCE;                rc = SNMP_ERR_NOERROR;            }        } else if (NULL == requests->requestvb->val.string) {            snmp_log(LOG_ERR, "NULL varbind data pointer!\n");            rc = SNMP_ERR_GENERR;        }        if (rc)            netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc));        /*         * if the buffer wasn't used previously for the old data (i.e. it         * was allcoated memory)  and the get routine replaced the pointer,         * we need to free the previous pointer.         */        if (old_string && (old_string != requests->requestvb->buf) &&            (requests->requestvb->val.string != old_string)) {            if (dataFreeHook)                (*dataFreeHook) (old_string);            else                free(old_string);        }    }                           /* for results */    return SNMP_ERR_NOERROR;}                               /* _mfd_ifTable_get_values *//*********************************************************************** * * SET processing * ***********************************************************************//*---------------------------------------------------------------------- * * SET: Syntax checks * *---------------------------------------------------------------------*//* * @internal * Check the syntax for a particular column */NETSNMP_STATIC_INLINE int_ifTable_check_column(ifTable_rowreq_ctx * rowreq_ctx,                      netsnmp_variable_list * var, int column){    int             rc = SNMPERR_SUCCESS;    DEBUGMSGTL(("internal:ifTable:_ifTable_check_column",                "called for %d\n", column));    netsnmp_assert(NULL != rowreq_ctx);    switch (column) {        /*         * (INDEX) ifIndex(1)/InterfaceIndex/ASN_INTEGER/long(long)//l/A/w/e/R/d/H          */    case COLUMN_IFINDEX:        rc = SNMP_ERR_NOTWRITABLE;      /* can not change index of active row */        break;        /*         * ifDescr(2)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H          */    case COLUMN_IFDESCR:        rc = SNMP_ERR_NOTWRITABLE;        break;        /*         * ifType(3)/IANAifType/ASN_INTEGER/long(u_long)//l/A/w/E/r/d/h          */    case COLUMN_IFTYPE:        rc = SNMP_ERR_NOTWRITABLE;        break;        /*         * ifMtu(4)/INTEGER32/ASN_INTEGER/long(long)//l/A/w/e/r/d/h          */    case COLUMN_IFMTU:        rc = SNMP_ERR_NOTWRITABLE;        break;        /*         * ifSpeed(5)/GAUGE/ASN_GAUGE/u_long(u_long)//l/A/w/e/r/d/h          */    case COLUMN_IFSPEED:        rc = SNMP_ERR_NOTWRITABLE;        break;        /*         * ifPhysAddress(6)/PhysAddress/ASN_OCTET_STR/char(char)//L/A/w/e/r/d/H          */    case COLUMN_IFPHYSADDRESS:        rc = SNMP_ERR_NOTWRITABLE;        break;        /*         * ifAdminStatus(7)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h          */    case COLUMN_IFADMINSTATUS:        /** special case: we are using exernal storage w/smaller data size         ** for storage, so we can't use sizeof on data context. So we         ** just check that it's the expected size. The enum tests below         ** will ensure that there is no data overflow. */        rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER,                                            sizeof(u_long));        /*         * check that the value is one of defined enums          */        if ((SNMPERR_SUCCESS == rc)            && (*var->val.integer != IFADMINSTATUS_UP)            && (*var->val.integer != IFADMINSTATUS_DOWN)            && (*var->val.integer != IFADMINSTATUS_TESTING)            ) {            rc = SNMP_ERR_WRONGVALUE;        }        if (SNMPERR_SUCCESS != rc) {            DEBUGMSGTL(("ifTable:_ifTable_check_column:ifAdminStatus",                        "varbind validation failed (eg bad type or size)\n"));        } else {            rc = ifAdminStatus_check_value(rowreq_ctx,                                           *((u_long *) var->val.string));            if ((MFD_SUCCESS != rc) && (MFD_NOT_VALID_EVER != rc)                && (MFD_NOT_VALID_NOW != rc)) {                snmp_log(LOG_ERR,                         "bad rc %d from ifAdminStatus_check_value\n", rc);                rc = SNMP_ERR_GENERR;            }        }        break;        /*         * ifOperStatus(8)/INTEGER/ASN_INTEGER/long(u_long)//l/A/w/E/r/d/h          */    case COLUMN_IFOPERSTATUS:        rc = SNMP_ERR_NOTWRITABLE;        break;        /*         * ifLastChange(9)/TICKS/ASN_TIMETICKS/u_long(u_long)//l/A/w/e/r/d/h          */    case COLUMN_IFLASTCHANGE:        rc = SNMP_ERR_NOTWRITABLE;        break;        /*         * ifInOctets(10)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h          */    case COLUMN_IFINOCTETS:        rc = SNMP_ERR_NOTWRITABLE;        break;        /*         * ifInUcastPkts(11)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h          */    case COLUMN_IFINUCASTPKTS:        rc = SNMP_ERR_NOTWRITABLE;        break;        /*         * ifInNUcastPkts(12)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h          */    case COLUMN_IFINNUCASTPKTS:        rc = SNMP_ERR_NOTWRITABLE;        break;        /*         * ifInDiscards(13)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h          */    case COLUMN_IFINDISCARDS:        rc = SNMP_ERR_NOTWRITABLE;        break;        /*         * ifInErrors(14)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h          */    case COLUMN_IFINERRORS:        rc = SNMP_ERR_NOTWRITABLE;        break;        /*         * ifInUnknownProtos(15)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h          */    case COLUMN_IFINUNKNOWNPROTOS:        rc = SNMP_ERR_NOTWRITABLE;        break;        /*         * ifOutOctets(16)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h          */    case COLUMN_IFOUTOCTETS:        rc = SNMP_ERR_NOTWRITABLE;        break;        /*         * ifOutUcastPkts(17)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h          */    case COLUMN_IFOUTUCASTPKTS:        rc = SNMP_ERR_NOTWRITABLE;        break;        /*         * ifOutNUcastPkts(18)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h          */    case COLUMN_IFOUTNUCASTPKTS:        rc = SNMP_ERR_NOTWRITABLE;        break;        /*         * ifOutDiscards(19)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h          */    case COLUMN_IFOUTDISCARDS:        rc = SNMP_ERR_NOTWRITABLE;        break;        /*         * ifOutErrors(20)/COUNTER/ASN_COUNTER/u_long(u_long)//l/A/w/e/r/d/h          */    case COLUMN_IFOUTERRORS:        rc = SNMP_ERR_NOTWRITABLE;        break;        /*         * ifOutQLen(21)/GAUGE/ASN_GAUGE/u_long(u_long)//l/A/w/e/r/d/h          */    case COLUMN_IFOUTQLEN:        rc = SNMP_ERR_NOTWRITABLE;        break;        /*         * ifSpecific(22)/OBJECTID/ASN_OBJECT_ID/oid(oid)//L/A/w/e/r/d/h          */    case COLUMN_IFSPECIFIC:        rc = SNMP_ERR_NOTWRITABLE;        break;    default:   /** We shouldn't get here */        rc = SNMP_ERR_GENERR;        snmp_log(LOG_ERR, "unknown column %d in _ifTable_check_column\n",                 column);    }    return rc;}                               /* _ifTable_check_column */int_mfd_ifTable_check_objects(netsnmp_mib_handler *handler,                           netsnmp_handler_registration *reginfo,                           netsnmp_agent_request_info *agtreq_info,                           netsnmp_request_info *requests){    ifTable_rowreq_ctx *rowreq_ctx =        netsnmp_container_table_row_extract(requests);    netsnmp_table_request_info *tri;    int             rc;    DEBUGMSGTL(("internal:ifTable:_mfd_ifTable_check_objects",                "called\n"));    netsnmp_assert(NULL != rowreq_ctx);    for (; requests; requests = requests->next) {        /*         * get column number from table request info, and check that column         */        tri = netsnmp_extract_table_info(requests);        if (NULL == tri)            continue;        rc = _ifTable_check_column(rowreq_ctx, requests->requestvb,                                   tri->colnum);        if (rc) {            netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc));            break;        }    }                           /* for results */    return SNMP_ERR_NOERROR;}                               /* _mfd_ifTable_check_objects *//*---------------------------------------------------------------------- * * SET: check dependencies * *---------------------------------------------------------------------*//* * @internal * Check dependencies wrapper */static int_mfd_ifTable_check_dependencies(netsnmp_mib_handler *handler,                                netsnmp_handler_registration *reginfo,                                netsnmp_agent_request_info *agtreq_info,                                netsnmp_request_info *requests){    int             rc;    ifTable_rowreq_ctx *rowreq_ctx =        netsnmp_container_table_row_extract(requests);    DEBUGMSGTL(("internal:ifTable:_mfd_ifTable_check_dependencies",                "called\n"));    netsnmp_assert(NULL != rowreq_ctx);    rc = ifTable_check_dependencies(rowreq_ctx);    if (rc) {        DEBUGMSGTL(("ifTable:mfd", "error %d from "                    "ifTable_check_dependencies\n", rc));        netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc));    }    return SNMP_ERR_NOERROR;}                               /* _mfd_ifTable_check_dependencies *//*---------------------------------------------------------------------- * * SET: Undo setup * *---------------------------------------------------------------------*//* * @internal * Set the value for a particular column */NETSNMP_STATIC_INLINE int_ifTable_undo_setup_column(ifTable_rowreq_ctx * rowreq_ctx, int column){    int             rc = SNMPERR_SUCCESS;    DEBUGMSGTL(("internal:ifTable:_ifTable_undo_setup_column",                "called for %d\n", column));    netsnmp_assert(NULL != rowreq_ctx);    switch (column) {        /*         * ifAdminStatus(7)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h          */    case COLUMN_IFADMINSTATUS:        rowreq_ctx->column_set_flags |= COLUMN_IFADMINSTATUS_FLAG;        rc = ifAdminStatus_undo_setup(rowreq_ctx);        break;    default:        snmp_log(LOG_ERR,                 "unknown column %d in _ifTable_undo_setup_column\n",                 column);        break;    }    return rc;}                               /* _ifTable_undo_setup_column */int_mfd_ifTable_undo_setup_allocate(ifTable_rowreq_ctx *rowreq_ctx){    int             rc = MFD_SUCCESS;    if (NULL == rowreq_ctx)        return MFD_ERROR;    /*     * other tables share our container/context and call     * this function. so we need to check and see if     * someone else already allocated the ifentry     */    if (NULL == rowreq_ctx->undo) {        rowreq_ctx->undo = ifTable_allocate_data();        if (NULL == rowreq_ctx->undo) {            /** msg already logged */            rc = SNMP_ERR_RESOURCEUNAVAILABLE;        }        else {            rowreq_ctx->undo->ifentry =                netsnmp_access_interface_entry_create(rowreq_ctx->data.ifentry->                                                      name,                                                      rowreq_ctx->data.ifentry->                                                      index);            if (NULL == rowreq_ctx->undo->ifentry) {                rc = SNMP_ERR_RESOURCEUNAVAILABLE;                ifTable_release_data(rowreq_ctx->undo);                rowreq_ctx->undo = NULL;            }            else {                netsnmp_access_interface_entry_copy(rowreq_ctx->undo->ifentry,                                                    rowreq_ctx->data.ifentry);                netsnmp_assert(0 == rowreq_ctx->undo_ref_count);            }        }    }    ++rowreq_ctx->undo_ref_count;    DEBUGMSGTL(("internal:ifTable:_mfd_ifTable_undo_setup_allocate",                "++undo_refcount = %d\n",rowreq_ctx->undo_ref_count));    return rc;}/** * @internal * undo setup */int_mfd_ifTable_undo_setup(netsnmp_mib_handler *handler,                        netsnmp_handler_registration *reginfo,                        netsnmp_agent_request_info *agtreq_info,                        netsnmp_request_info *requests){    int             rc;    ifTable_rowreq_ctx *rowreq_ctx =        netsnmp_container_table_row_extract(requests);    DEBUGMSGTL(("internal:ifTable:_mfd_ifTable_undo_setup", "called\n"));    netsnmp_assert(NULL != rowreq_ctx);    /*     * allocate undo context     */    rc = _mfd_ifTable_undo_setup_allocate(rowreq_ctx);    if (MFD_SUCCESS != rc) {        netsnmp_request_set_error_all(requests, rc);        return SNMP_ERR_NOERROR;    }    /*     * row undo setup     */    rc = ifTable_undo_setup(rowreq_ctx);    if (MFD_SUCCESS != rc) {        DEBUGMSGTL(("ifTable:mfd", "error %d from "                    "ifTable_undo_setup\n", rc));        netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc));    } else {        /*         * column undo setup         */        netsnmp_table_request_info *tri;        for (; requests; requests = requests->next) {            /*             * set column data             */            tri = netsnmp_extract_table_info(requests);            if (NULL == tri)                continue;            rc = _ifTable_undo_setup_column(rowreq_ctx, tri->colnum);            if (MFD_SUCCESS != rc) {                DEBUGMSGTL(("ifTable:mfd", "error %d from "                            "ifTable_undo_setup_column\n", rc));                netsnmp_set_request_error(agtreq_info, requests,                                          SNMP_VALIDATE_ERR(rc));            }        }                       /* for results */    }    return SNMP_ERR_NOERROR;}                               /* _mfd_ifTable_undo_setup */void_mfd_ifTable_undo_setup_release(ifTable_rowreq_ctx *rowreq_ctx){    netsnmp_assert(rowreq_ctx->undo_ref_count > 0);    --rowreq_ctx->undo_ref_count;    snmp_log(LOG_ERR, "undo_refcount at %d\n", rowreq_ctx->undo_ref_count);    if (0 == rowreq_ctx->undo_ref_count) {        netsnmp_access_interface_entry_free(rowreq_ctx->undo->ifentry);        ifTable_release_data(rowreq_ctx->undo);        rowreq_ctx->undo = NULL;    }}/** * @internal * undo setup */int_mfd_ifTable_undo_cleanup(netsnmp_mib_handler *handler,                          netsnmp_handler_registration *reginfo,                          netsnmp_agent_request_info *agtreq_info,                          netsnmp_request_info *requests)

⌨️ 快捷键说明

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