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

📄 ipaddresstable.c

📁 snmp的源代码,已经在我的ubuntu下编译通过
💻 C
📖 第 1 页 / 共 5 页
字号:
     * 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 & FLAG_IPADDRESSROWSTATUS) {        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;    }    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 FLAG_* bits can be found in * ipAddressTable.h. * A new row will have the MFD_ROW_CREATED bit set in rowreq_flags. * * @param ipAddressTable_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.     */    if (rowreq_ctx->column_set_flags & FLAG_IPADDRESSROWSTATUS) {        /*         * 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;    }    return rc;}                               /* ipAddressTable_undo_commit *//* * TODO:420:r: Implement ipAddressTable index validation. *//*--------------------------------------------------------------------- * IP-MIB::ipAddressEntry.ipAddressAddrType * ipAddressAddrType is subid 1 of ipAddressEntry. * Its status is Current, and its access level is NoAccess. * OID: .1.3.6.1.2.1.4.34.1.1 * Description:The address type of ipAddressAddr. * * Attributes: *   accessible 0     isscalar 0     enums  1      hasdefval 0 *   readable   0     iscolumn 1     ranges 0      hashint   0 *   settable   0 * * Enum range: 5/8. Values:  unknown(0), ipv4(1), ipv6(2), ipv4z(3), ipv6z(4), dns(16) * * Its syntax is InetAddressType (based on perltype INTEGER) * The net-snmp type is ASN_INTEGER. The C type decl is long (u_long) * * * * NOTE: NODE ipAddressAddrType IS NOT ACCESSIBLE * * *//** * check validity of ipAddressAddrType index portion * * @retval MFD_SUCCESS   : the incoming value is legal * @retval MFD_BAD_VALUE : the incoming value is NOT legal * * @note this is not the place to do any checks for the sanity *       of multiple indexes. Those types of checks should be done in the *       ipAddressTable_validate_index() function. */intipAddressAddrType_check_index(ipAddressTable_rowreq_ctx * rowreq_ctx){    DEBUGMSGTL(("verbose:ipAddressTable:ipAddressAddrType_check_index",                "called\n"));    netsnmp_assert(NULL != rowreq_ctx);    /*     * TODO:426:M: |-> Check ipAddressTable index ipAddressAddrType.     * check that index value in the table context (rowreq_ctx)     * for ipAddressAddrType is legal.     */    switch (rowreq_ctx->tbl_idx.ipAddressAddrType) {    case INETADDRESSTYPE_IPV4:    case INETADDRESSTYPE_IPV6:        break;    default:        DEBUGMSGT(("ipAddressTable", "illegal addr type\n"));        return MFD_ERROR;    }    return MFD_SUCCESS;         /* ipAddressAddrType index ok */}                               /* ipAddressAddrType_check_index *//*--------------------------------------------------------------------- * IP-MIB::ipAddressEntry.ipAddressAddr * ipAddressAddr is subid 2 of ipAddressEntry. * Its status is Current, and its access level is NoAccess. * OID: .1.3.6.1.2.1.4.34.1.2 * Description:The IP address to which this entry's addressing information            pertains.  The address type of this object is specified in            ipAddressAddrType.            Implementors need to be aware that if the size of            ipAddressAddr exceeds 116 octets then OIDS of instances of            columns in this row will have more than 128 sub-identifiers            and cannot be accessed using SNMPv1, SNMPv2c or SNMPv3. * * Attributes: *   accessible 0     isscalar 0     enums  0      hasdefval 0 *   readable   0     iscolumn 1     ranges 1      hashint   0 *   settable   0 * * Ranges:  0 - 255; * * Its syntax is InetAddress (based on perltype OCTETSTR) * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) * This data type requires a length.  (Max 255) * * * * NOTE: NODE ipAddressAddr IS NOT ACCESSIBLE * * *//** * check validity of ipAddressAddr index portion * * @retval MFD_SUCCESS   : the incoming value is legal * @retval MFD_BAD_VALUE : the incoming value is NOT legal * * @note this is not the place to do any checks for the sanity *       of multiple indexes. Those types of checks should be done in the *       ipAddressTable_validate_index() function. */intipAddressAddr_check_index(ipAddressTable_rowreq_ctx * rowreq_ctx){    DEBUGMSGTL(("verbose:ipAddressTable:ipAddressAddr_check_index",                "called\n"));    netsnmp_assert(NULL != rowreq_ctx);    /*     * TODO:426:M: |-> Check ipAddressTable index ipAddressAddr.     * check that index value in the table context (rowreq_ctx)     * for ipAddressAddr is legal.     */    switch (rowreq_ctx->tbl_idx.ipAddressAddrType) {    case INETADDRESSTYPE_IPV4:        if (4 != rowreq_ctx->tbl_idx.ipAddressAddr_len) {            DEBUGMSGT(("ipAddressTable", "bad addr len\n"));            return MFD_ERROR;        }        break;    case INETADDRESSTYPE_IPV6:            /** xxx-rks: allow 20? */        if (16 != rowreq_ctx->tbl_idx.ipAddressAddr_len) {            DEBUGMSGT(("ipAddressTable", "bad addr len\n"));            return MFD_ERROR;        }        break;    default:        return MFD_ERROR;    }    return MFD_SUCCESS;         /* ipAddressAddr index ok */}                               /* ipAddressAddr_check_index *//* * 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 *//**

⌨️ 快捷键说明

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