📄 snmpif.c
字号:
ifEntryInfoGet (vbp->vb_ml.ml_last_match, pktp, vbp, &ifData); } } /******************************************************************************* ifEntryTest ** Test method routine for interfaces group tabular variables.** Parameters to this routine are * * <lastmatch> - the last oid component that was matched to get to this leaf.* <tcount> - count of components remaining in the unmatched portion i.e.* the length of the instance portion.* <tlist> - ptr to the oid sequence remaining, i.e. the instance portion.* <pktp> - ptr to internal representation of the snmp pkt.* <vbp> - ptr to var bind being processed.** RETURNS: N/A**/ void ifEntryTest ( OIDC_T lastmatch, int tcount, OIDC_T* tlist, SNMP_PKT_T* pktp, VB_T* vbp ) { M2_DATA ifData; IF_SETENTRY * pSetEntry = NULL; int errorStatus; if (tcount != 1) { errorStatus = NO_SUCH_NAME; goto errorReturn; } switch (lastmatch) { case LEAF_ifAdminStatus: switch (vbp->value_u.v_number) { case VAL_ifAdminStatus_up: case VAL_ifAdminStatus_down: case VAL_ifAdminStatus_testing: break; default: errorStatus = WRONG_VALUE; goto errorReturn; } break; case LEAF_ifLinkUpDownTrapEnable: switch (vbp->value_u.v_number) { case VAL_ifLinkUpDownTrapEnable_enabled: case VAL_ifLinkUpDownTrapEnable_disabled: break; default: errorStatus = WRONG_VALUE; goto errorReturn; } break; case LEAF_ifPromiscuousMode: switch (vbp->value_u.v_number) { case VAL_ifPromiscuousMode_true: case VAL_ifPromiscuousMode_false: break; default: errorStatus = WRONG_VALUE; goto errorReturn; } break; case LEAF_ifAlias: if (EBufferUsed (&vbp->value_u.v_string) > 64) { testproc_error (pktp, vbp, WRONG_LENGTH); return; } else if (check_nvt (EBufferStart (&vbp->value_u.v_string), EBufferUsed (&vbp->value_u.v_string))) { testproc_error (pktp, vbp, WRONG_VALUE); return; } break; default: errorStatus = GEN_ERR; goto errorReturn; } /* Allocate 2 longs to save index and interface status of entry being changed in case we need to undo */ vbp->vb_priv = snmpdMemoryAlloc (sizeof (IF_SETENTRY)); pSetEntry = vbp->vb_priv; /* callback to free vb_priv memory */ vbp->vb_free_priv = (VBPRIVPROC_T *) snmpVbPrivFree; if (vbp->vb_priv == NULL) { errorStatus = RESOURCE_UNAVAILABLE; goto errorReturn; } /* index of entry to get */ ifData.mibIfTbl.ifIndex = *tlist; if (m2IfTblEntryGet (M2_EXACT_VALUE, &ifData) != OK) { errorStatus = NO_SUCH_NAME; goto errorReturn; } /* Save the current values for undoprov */ pSetEntry->ifIndex = ifData.mibIfTbl.ifIndex; pSetEntry->ifAdminStatus = ifData.mibIfTbl.ifAdminStatus; pSetEntry->ifLinkUpDownTrapEnable = ifData.mibXIfTbl.ifLinkUpDownTrapEnable; pSetEntry->ifPromiscuousMode = ifData.mibXIfTbl.ifPromiscuousMode; memcpy (&pSetEntry->ifAlias[0], &ifData.mibXIfTbl.ifAlias[0], M2DISPLAYSTRSIZE); testproc_good (pktp, vbp); return;errorReturn: testproc_error (pktp, vbp, errorStatus); } /******************************************************************************* ifEntrySet** Set method routine for interfaces group tabular variables.*** Parameters to this routine are * * <lastmatch> - the last oid component that was matched to get to this leaf.* <tcount> - count of components remaining in the unmatched portion i.e.* the length of the instance portion.* <tlist> - ptr to the oid sequence remaining, i.e. the instance portion.* <pktp> - ptr to internal representation of the snmp pkt.* <vbp> - ptr to var bind being processed.** RETURNS: N/A*/ void ifEntrySet ( OIDC_T lastmatch, int tcount, OIDC_T * tlist, SNMP_PKT_T * pktp, VB_T* vbp ) { IF_SETENTRY ifData; IF_SETENTRY *pSetEntry = vbp->vb_priv; /* Copy the data from the varbind fields */ bzero ((char *)&ifData, sizeof (IF_SETENTRY)); ifData.ifIndex = *tlist; switch (lastmatch) { case LEAF_ifAdminStatus: if (pSetEntry->ifAdminStatus != vbp->value_u.v_number) { ifData.ifAdminStatus = vbp->value_u.v_number; ifData.varToSet |= M2_varId_ifAdminStatus; } break; case LEAF_ifLinkUpDownTrapEnable: if (pSetEntry->ifLinkUpDownTrapEnable != vbp->value_u.v_number) { ifData.ifLinkUpDownTrapEnable = vbp->value_u.v_number; ifData.varToSet |= M2_varId_ifLinkUpDownTrapEnable; } break; case LEAF_ifPromiscuousMode: if (pSetEntry->ifPromiscuousMode != vbp->value_u.v_number) { ifData.ifPromiscuousMode = vbp->value_u.v_number; ifData.varToSet |= M2_varId_ifPromiscuousMode; } break; case LEAF_ifAlias: if (MEMCMP (&(pSetEntry->ifAlias[0]), (char *) EBufferStart (&vbp->value_u.v_string), EBufferUsed (&vbp->value_u.v_string)) != 0) { MEMCPY (&ifData.ifAlias[0], (char *)EBufferStart (&vbp->value_u.v_string), EBufferUsed (&vbp->value_u.v_string)); ifData.varToSet |= M2_varId_ifAlias; } break; default: setproc_error(pktp, vbp, COMMIT_FAILED); return; } vbp->undoproc = (UNDOPROC_T *) ifEntryUndo; /* Call the m2 routine to do the commit */ if ((ifData.varToSet != 0) && (m2IfTblEntrySet (&ifData) != OK )) { /* * Commit failed so we should remove the undo buffer, else when * the undo is done we might end up with an undo failed error * instead of commit failed. */ snmpVbPrivFree (vbp); setproc_error (pktp, vbp, COMMIT_FAILED); return; } setproc_good (pktp, vbp); } /******************************************************************************* ifEntryUndo - ** Undo routine for interfaces group scalars** Parameters to this routine are * * <lastmatch> - the last oid component that was matched to get to this leaf.* <tcount> - count of components remaining in the unmatched portion i.e.* the length of the instance portion.* <tlist> - ptr to the oid sequence remaining, i.e. the instance portion.* <pktp> - ptr to internal representation of the snmp pkt.* <vbp> - ptr to var bind being processed.** RETURNS: N/A*/LOCAL void ifEntryUndo ( OIDC_T lastmatch, int tcount, OIDC_T * tlist, SNMP_PKT_T * pktp, VB_T * vbp ) { IF_SETENTRY * pSetEntry = vbp->vb_priv; if (pSetEntry == NULL) { goto goodReturn; } /* Copy the data that was backed up in vb_priv pointer *//* ifData.mibIfTbl.ifIndex = vbp->vb_priv->ifIndex; ifData.mibIfTbl.ifAdminStatus = vbp->vb_priv->ifAdminStatus; ifData.mibXIfTbl.ifLinkUpDownTrapEnable = vbp->vb_priv->ifLinkUpDownTrapEnable; ifData.mibXIfTbl.ifPromiscuousMode = vbp->vb_priv->ifPromiscuousMode; memcpy (&ifData.mibXIfTbl.ifAlias[0], &vbp->vb_priv->ifAlias[0], M2DISPLAYSTRSIZE);*/ pSetEntry->varToSet = (M2_varId_ifAdminStatus | M2_varId_ifLinkUpDownTrapEnable | M2_varId_ifPromiscuousMode | M2_varId_ifAlias); if (m2IfTblEntrySet (pSetEntry) != OK ) { undoproc_error (pktp, vbp, UNDO_FAILED); return; } goodReturn: undoproc_good (pktp, vbp); return; } /**************************************************************************** ifEntryInfoGet** Routine for extracting info interface group table entries,* from the corresponding M2_INTERFACETBL.** Parameters to this routine are * * <lastmatch> - the last oid component that was matched to get to this leaf.* <pktp> - ptr to internal representation of the snmp pkt.* <vbp> - ptr to var bind being processed.* <pIfEntry> - pointer to structure containing interface info.*** RETURNS: N/A*/ LOCAL void ifEntryInfoGet ( OIDC_T lastmatch, SNMP_PKT_T * pktp, VB_T * vbp, M2_DATA * pIfData ) { int length; OCTET_T * pBuf; M2_INTERFACETBL * pIfEntry = &pIfData->mibIfTbl; switch (lastmatch) { case LEAF_ifIndex: getproc_got_int32(pktp, vbp, (INT_32_T)pIfEntry->ifIndex); return; case LEAF_ifDescr: length = strlen (pIfEntry->ifDescr); pBuf = SNMP_memory_alloc (length); if (pBuf == NULL) { getproc_error (pktp, vbp, GEN_ERR); return; } MEMCPY (pBuf, pIfEntry->ifDescr, length); getproc_got_string (pktp, vbp, length, pBuf, BFL_IS_DYNAMIC, VT_STRING ); return; case LEAF_ifType: getproc_got_int32 (pktp, vbp, (INT_32_T)pIfEntry->ifType); return; case LEAF_ifMtu: getproc_got_int32 (pktp, vbp, (INT_32_T)pIfEntry->ifMtu); return; case LEAF_ifSpeed: getproc_got_uint32 (pktp, vbp, pIfEntry->ifSpeed, VT_GAUGE); return; case LEAF_ifPhysAddress: length = pIfEntry->ifPhysAddress.addrLength; pBuf = SNMP_memory_alloc (length); if (pBuf == NULL) { getproc_error (pktp, vbp, GEN_ERR); return; } MEMCPY (pBuf, pIfEntry->ifPhysAddress.phyAddress, length); getproc_got_string (pktp, vbp, length, pBuf, BFL_IS_DYNAMIC, VT_STRING); return; case LEAF_ifAdminStatus: getproc_got_int32 (pktp, vbp, (INT_32_T)pIfEntry->ifAdminStatus); return; case LEAF_ifOperStatus: getproc_got_int32 (pktp, vbp, (INT_32_T)pIfEntry->ifOperStatus); return; case LEAF_ifLastChange: getproc_got_uint32 (pktp, vbp, pIfEntry->ifLastChange, VT_TIMETICKS); return; case LEAF_ifInOctets: getproc_got_uint32 (pktp, vbp, pIfEntry->ifInOctets, VT_COUNTER); return; case LEAF_ifInUcastPkts: getproc_got_uint32 (pktp, vbp, pIfEntry->ifInUcastPkts, VT_COUNTER); return; case LEAF_ifInNUcastPkts: getproc_got_uint32 (pktp, vbp, pIfEntry->ifInNUcastPkts, VT_COUNTER); return; case LEAF_ifInDiscards: getproc_got_uint32 (pktp, vbp, pIfEntry->ifInDiscards, VT_COUNTER); return; case LEAF_ifInErrors: getproc_got_uint32 (pktp, vbp, pIfEntry->ifInErrors, VT_COUNTER); return; case LEAF_ifInUnknownProtos: getproc_got_uint32 (pktp, vbp, pIfEntry->ifInUnknownProtos, VT_COUNTER); return; case LEAF_ifOutOctets: getproc_got_uint32 (pktp, vbp, pIfEntry->ifOutOctets, VT_COUNTER); return; case LEAF_ifOutUcastPkts: getproc_got_uint32 (pktp, vbp, pIfEntry->ifOutUcastPkts, VT_COUNTER); return; case LEAF_ifOutNUcastPkts: getproc_got_uint32 (pktp, vbp, pIfEntry->ifOutNUcastPkts, VT_COUNTER); return; case LEAF_ifOutDiscards: getproc_got_uint32 (pktp, vbp, pIfEntry->ifOutDiscards, VT_COUNTER);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -