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

📄 ipaddresstable.c

📁 开发snmp的开发包有两个开放的SNMP开发库
💻 C
📖 第 1 页 / 共 5 页
字号:
/** * Cleanup up context undo information. * * This function will be called after set/commit processing. If you * allocated any resources in undo_setup, this is the place to release * those resources. * * This function is called regardless of the success or failure of the set * request. If you need to perform different steps for cleanup depending * on success or failure, you can add a flag to the rowreq_ctx. * * @param rowreq_ctx *        Pointer to the table context (ipAddressTable_rowreq_ctx) * * @retval MFD_SUCCESS : success * @retval MFD_ERROR   : error */intipAddressTable_undo_cleanup(ipAddressTable_rowreq_ctx * rowreq_ctx){    int             rc = MFD_SUCCESS;    DEBUGMSGTL(("verbose:ipAddressTable:ipAddressTable_undo_cleanup",                "called\n"));    /** we should have a non-NULL pointer */    netsnmp_assert(NULL != rowreq_ctx);    /*     * TODO:452:M: |-> Cleanup ipAddressTable undo.     * Undo storage is in (* ipAddressStorageType_val_ptr )*     */    rowreq_ctx->ipAddressLastChanged =        rowreq_ctx->ipAddressLastChanged_undo;    return rc;}                               /* ipAddressTable_undo_cleanup *//** * commit new values. * * At this point, you should have done everything you can to ensure that * this commit will not fail. * * Should you need different behavior depending on which columns were * set, rowreq_ctx->column_set_flags will indicate which writeable columns were * set. The definitions for the COLUMN_*_FLAG bits can be found in * ipAddressTable.h. * A new row will have the MFD_ROW_CREATED bit set in rowreq_flags. * * @param rowreq_ctx *        Pointer to the users context. * * @retval MFD_SUCCESS : success * @retval MFD_ERROR   : error */intipAddressTable_commit(ipAddressTable_rowreq_ctx * rowreq_ctx){    int             rc = MFD_SUCCESS;    int             save_flags;    DEBUGMSGTL(("verbose:ipAddressTable:ipAddressTable_commit",                "called\n"));    /** we should have a non-NULL pointer */    netsnmp_assert(NULL != rowreq_ctx);    /*     * save flags, then clear until we actually do something     */    save_flags = rowreq_ctx->column_set_flags;    rowreq_ctx->column_set_flags = 0;    /*     * commit ipAddressTable data     * 1) check the column's flag in save_flags to see if it was set.     * 2) clear the flag when you handle that column     * 3) set the column's flag in column_set_flags if it needs undo     *    processing in case of a failure.     */    /*     * did anything change?     */    if (0 == save_flags) {        DEBUGMSGTL(("ipAddressTable:ipAddressTable_commit",                    "no change\n"));        return MFD_SUCCESS;    }    /*     * pass everything to data access     * let data access know what columns are set     */    rowreq_ctx->data->flags = save_flags;    if (save_flags & COLUMN_IPADDRESSROWSTATUS_FLAG) {        if (rowreq_ctx->rowreq_flags & MFD_ROW_CREATED) {            netsnmp_assert(ROWSTATUS_CREATEANDGO ==                           rowreq_ctx->ipAddressRowStatus);            rowreq_ctx->data->flags |= NETSNMP_ACCESS_IPADDRESS_CREATE;            rowreq_ctx->ipAddressCreated = netsnmp_get_agent_uptime();        } else if (ROWSTATUS_DESTROY == rowreq_ctx->ipAddressRowStatus) {            rowreq_ctx->data->flags |= NETSNMP_ACCESS_IPADDRESS_DELETE;        } else            rowreq_ctx->data->flags |= NETSNMP_ACCESS_IPADDRESS_CHANGE;    } else        rowreq_ctx->data->flags |= NETSNMP_ACCESS_IPADDRESS_CHANGE;    /*     * do it     */    rc = netsnmp_access_ipaddress_entry_set(rowreq_ctx->data);    if (rc) {        DEBUGMSGTL(("ipAddressTable",                    "bad rc %d from IP address data access\n", rc));        rc = MFD_ERROR;    } else {        rowreq_ctx->ipAddressLastChanged = netsnmp_get_agent_uptime();        /*         * set flag, in case we need to undo         */        rowreq_ctx->column_set_flags |= save_flags;    }    /*     * if we successfully commited this row, set the dirty flag.     */    if (MFD_SUCCESS == rc) {        rowreq_ctx->rowreq_flags |= MFD_ROW_DIRTY;    }    if (save_flags) {        snmp_log(LOG_ERR, "unhandled columns (0x%x) in commit\n",                 save_flags);        return MFD_ERROR;    }    return rc;}                               /* ipAddressTable_commit *//** * undo commit new values. * * Should you need different behavior depending on which columns were * set, rowreq_ctx->column_set_flags will indicate which writeable columns were * set. The definitions for the COLUMN_*_FLAG bits can be found in * ipAddressTable.h. * A new row will have the MFD_ROW_CREATED bit set in rowreq_flags. * * @param rowreq_ctx *        Pointer to the users context. * * @retval MFD_SUCCESS : success * @retval MFD_ERROR   : error */intipAddressTable_undo_commit(ipAddressTable_rowreq_ctx * rowreq_ctx){    int             rc = MFD_SUCCESS;    DEBUGMSGTL(("verbose:ipAddressTable:ipAddressTable_undo_commit",                "called\n"));    /** we should have a non-NULL pointer */    netsnmp_assert(NULL != rowreq_ctx);    /*     * TODO:485:M: |-> Undo ipAddressTable commit.     * check the column's flag in rowreq_ctx->column_set_flags to see     * if it was set during commit, then undo it.     *     * eg: if (rowreq_ctx->column_set_flags & COLUMN__FLAG) {}     */    if (rowreq_ctx->column_set_flags & COLUMN_IPADDRESSROWSTATUS_FLAG) {        /*         * if we created an addr, delete it. if we deleted it,         * re-create it. If we changed it, change it back.         */        if (rowreq_ctx->rowreq_flags & MFD_ROW_CREATED) {            rowreq_ctx->undo->flags |= NETSNMP_ACCESS_IPADDRESS_DELETE;        } else if (ROWSTATUS_DESTROY == rowreq_ctx->ipAddressRowStatus) {            rowreq_ctx->undo->flags |= NETSNMP_ACCESS_IPADDRESS_CREATE;        } else            rowreq_ctx->undo->flags |= NETSNMP_ACCESS_IPADDRESS_CHANGE;    } else        rowreq_ctx->undo->flags |= NETSNMP_ACCESS_IPADDRESS_CHANGE;    /*     * do it     */    rc = netsnmp_access_ipaddress_entry_set(rowreq_ctx->undo);    if (rc) {        DEBUGMSGTL(("ipAddressTable",                    "bad rc %d from IP address data access\n", rc));        rc = MFD_ERROR;    }    /*     * if we successfully un-commited this row, clear the dirty flag.     */    if (MFD_SUCCESS == rc) {        rowreq_ctx->rowreq_flags &= ~MFD_ROW_DIRTY;    }    return rc;}                               /* ipAddressTable_undo_commit *//* * TODO:440:M: Implement ipAddressTable node value checks. * TODO:450:M: Implement ipAddressTable undo functions. * TODO:460:M: Implement ipAddressTable set functions. * TODO:480:M: Implement ipAddressTable commit functions. *//*--------------------------------------------------------------------- * IP-MIB::ipAddressEntry.ipAddressIfIndex * ipAddressIfIndex is subid 3 of ipAddressEntry. * Its status is Current, and its access level is Create. * OID: .1.3.6.1.2.1.4.34.1.3 * Description:The index value which uniquely identifies the interface to            which this entry is applicable.  The interface identified by            a particular value of this index is the same interface as            identified by the same value of the IF-MIB's ifIndex. * * Attributes: *   accessible 1     isscalar 0     enums  0      hasdefval 0 *   readable   1     iscolumn 1     ranges 1      hashint   1 *   settable   1 *   hint: d * * Ranges:  1 - 2147483647; * * Its syntax is InterfaceIndex (based on perltype INTEGER32) * The net-snmp type is ASN_INTEGER. The C type decl is long (long) *//** * Check that the proposed new value is potentially valid. * * @param rowreq_ctx *        Pointer to the row request context. * @param ipAddressIfIndex_val *        A long containing the new value. * * @retval MFD_SUCCESS        : incoming value is legal * @retval MFD_NOT_VALID_NOW  : incoming value is not valid now * @retval MFD_NOT_VALID_EVER : incoming value is never valid * * This is the place to check for requirements that are not * expressed in the mib syntax (for example, a requirement that * is detailed in the description for an object). * * You should check that the requested change between the undo value and the * new value is legal (ie, the transistion from one value to another * is legal). *       *@note * This check is only to determine if the new value * is \b potentially valid. This is the first check of many, and * is one of the simplest ones. *  *@note * this is not the place to do any checks for values * which depend on some other value in the mib. Those * types of checks should be done in the * ipAddressTable_check_dependencies() function. * * The following checks have already been done for you: *    The syntax is ASN_INTEGER *    The value is in (one of) the range set(s):  1 - 2147483647 * * If there a no other checks you need to do, simply return MFD_SUCCESS. * */intipAddressIfIndex_check_value(ipAddressTable_rowreq_ctx * rowreq_ctx,                             long ipAddressIfIndex_val){    DEBUGMSGTL(("verbose:ipAddressTable:ipAddressIfIndex_check_value",                "called\n"));    /** should never get a NULL pointer */    netsnmp_assert(NULL != rowreq_ctx);    /*     * TODO:441:o: |-> Check for valid ipAddressIfIndex value.     */    /*     * if the new value is the same as the old, accept it.     */    if (ipAddressIfIndex_val == rowreq_ctx->data->if_index)        return MFD_SUCCESS;    /*     * currently don't support moving addresses between interfaces, so     * if this isn't a new row, return error.     */    if (!(rowreq_ctx->rowreq_flags & MFD_ROW_CREATED)) {        DEBUGMSGT(("ipAddressTable",                   "changing ifIndex value not supported\n"));        return MFD_NOT_VALID_EVER;    }    /*     * find name for ifIndex     */    if (NULL == netsnmp_access_interface_name_find(ipAddressIfIndex_val)) {        DEBUGMSGT(("ipAddressTable", "cant find name for index %d\n",                   ipAddressIfIndex_val));        return MFD_NOT_VALID_NOW;    }    return MFD_SUCCESS;         /* ipAddressIfIndex value not illegal */}                               /* ipAddressIfIndex_check_value *//** * Save old value information * * @param rowreq_ctx *        Pointer to the table context (ipAddressTable_rowreq_ctx) * * @retval MFD_SUCCESS : success * @retval MFD_ERROR   : error. set will fail. * * This function will be called after the table level undo setup function * ipAddressTable_undo_setup has been called. * *@note * this function will only be called if a new value is set for this column. * * If there is any setup specific to a particular column (e.g. allocating * memory for a string), you should do that setup in this function, so it * won't be done unless it is necessary. */intipAddressIfIndex_undo_setup(ipAddressTable_rowreq_ctx * rowreq_ctx){    DEBUGMSGTL(("verbose:ipAddressTable:ipAddressIfIndex_undo_setup",                "called\n"));    /** should never get a NULL pointer */    netsnmp_assert(NULL != rowreq_ctx);    /*     * TODO:455:o: |-> Setup ipAddressIfIndex undo.     */    /*     * handled in ipAddressTable_undo_setup     */    return MFD_SUCCESS;}                               /* ipAddressIfIndex_undo_setup *//** * Set the new value. * * @param rowreq_ctx *        Pointer to the users context. You should know how to *        manipulate the value from this object. * @param ipAddressIfIndex_val *        A long containing the new value. */intipAddressIfIndex_set(ipAddressTable_rowreq_ctx * rowreq_ctx,                     long ipAddressIfIndex_val){    DEBUGMSGTL(("verbose:ipAddressTable:ipAddressIfIndex_set",                "called\n"));    /** should never get a NULL pointer */    netsnmp_assert(NULL != rowreq_ctx);    /*     * TODO:461:M: |-> Set ipAddressIfIndex value.     * set ipAddressIfIndex value in rowreq_ctx->data     */    if (rowreq_ctx->data->if_index != ipAddressIfIndex_val)        rowreq_ctx->data->if_index = ipAddressIfIndex_val;    else        rowreq_ctx->column_set_flags &= ~COLUMN_IPADDRESSIFINDEX_FLAG;    return MFD_SUCCESS;}                               /* ipAddressIfIndex_set *//** * undo the previous set. * * @param rowreq_ctx *        Pointer to the users context. */intipAddressIfIndex_undo(ipAddressTable_rowreq_ctx * rowreq_ctx){    DEBUGMSGTL(("verbose:ipAddressTable:ipAddressIfIndex_undo",                "called\n"));

⌨️ 快捷键说明

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