📄 snmpif.c
字号:
* * <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 ifStackEntryNext ( OIDC_T lastmatch, int tcount, OIDC_T * tlist, SNMP_PKT_T * pktp, VB_T * vbp ) { OIDC_T index[IF_STACKTBL_INDEX_LEN]; int highIndex; M2_IFSTACKTBL ifStackData; /* * Group together all varbinds which have the same getproc * and instance. */ snmpdGroupByGetprocAndInstance (pktp, vbp, tcount, tlist); highIndex = (tlist != NULL) ? *tlist : 0; ifStackData.index = ((tlist != NULL) && (*(tlist + 1) != 0)) ? *(tlist + 1) : 0; if (m2IfStackEntryGet (M2_NEXT_VALUE, &highIndex, &ifStackData) != OK) { for ( ; vbp != NULL; vbp = vbp->vb_link) { nextproc_no_next (pktp, vbp); } return; } /* Create oid sequence for interface index retrieved */ *index = highIndex; *(index + 1) = ifStackData.index; for ( ; vbp; vbp = vbp->vb_link) { nextproc_next_instance (pktp, vbp, IF_STACKTBL_INDEX_LEN, index); ifStackEntryInfoGet (vbp->vb_ml.ml_last_match, pktp, vbp, &ifStackData); } }/******************************************************************************* ifStackEntryTest ** 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 ifStackEntryTest ( OIDC_T lastmatch, int tcount, OIDC_T* tlist, SNMP_PKT_T* pktp, VB_T* vbp ) { M2_IFSTACKTBL *pSetEntry = NULL; int errorStatus; int highIndex; if (tcount != IF_STACKTBL_INDEX_LEN) { testproc_error (pktp, vbp, NO_SUCH_NAME); return; } snmpdGroupByGetprocAndInstance (pktp, vbp, tcount, tlist); vbp->vb_priv = snmpdMemoryAlloc (sizeof (M2_IFSTACKTBL)); pSetEntry = vbp->vb_priv; vbp->vb_free_priv = (VBPRIVPROC_T *) snmpVbPrivFree; if (vbp->vb_priv == NULL) { errorStatus = RESOURCE_UNAVAILABLE; goto errorReturn; } highIndex = *tlist; pSetEntry->index = *(tlist + 1); if (m2IfStackEntryGet (M2_EXACT_VALUE, &highIndex, pSetEntry) != OK) { errorStatus = NO_SUCH_NAME; goto errorReturn; } for ( ; vbp; vbp = vbp->vb_link) { switch (lastmatch) { case LEAF_ifStackStatus: switch (vbp->value_u.v_number) { case VAL_ifStackStatus_active: case VAL_ifStackStatus_notInService: case VAL_ifStackStatus_destroy: break; case VAL_ifStackStatus_notReady: case VAL_ifStackStatus_createAndGo: case VAL_ifStackStatus_createAndWait: default: testproc_error(pktp, vbp, WRONG_VALUE); return; } break; default: testproc_error(pktp, vbp, GEN_ERR); return; } testproc_good (pktp, vbp); } return;errorReturn: testproc_error (pktp, vbp, errorStatus); }/******************************************************************************* ifStackEntrySet** 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 ifStackEntrySet ( OIDC_T lastmatch, int tcount, OIDC_T * tlist, SNMP_PKT_T * pktp, VB_T* vbp ) { int highIndex; M2_IFSTACKTBL ifStackData; M2_IFSTACKTBL *pSetEntry = (M2_IFSTACKTBL *)vbp->vb_priv; int commit = 0; if (tcount != IF_STACKTBL_INDEX_LEN) { for ( ; vbp != NULL; vbp = vbp->vb_link) { getproc_nosuchins (pktp, vbp); } return; } /* Extract the interface index for indexing into the interface table */ highIndex = *tlist; ifStackData.index = *(tlist + 1); switch (lastmatch) { case LEAF_ifStackStatus: if (pSetEntry->status == vbp->value_u.v_number) { ifStackData.status = vbp->value_u.v_number; commit = 0; } break; default: setproc_error(pktp, vbp, COMMIT_FAILED); return; } /* Call the m2 Set API to perform the change */ if ((commit == 1) && (m2IfStackEntrySet (highIndex, &ifStackData) != OK)) { snmpVbPrivFree (vbp); setproc_error (pktp, vbp, COMMIT_FAILED); return; } setproc_good (pktp, vbp); }/**************************************************************************** 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*/void ifRcvAddrInfoGet ( OIDC_T lastmatch, SNMP_PKT_T * pktp, VB_T * vbp, M2_IFRCVADDRTBL * pIfData ) { switch(lastmatch) { case LEAF_ifRcvAddressStatus: getproc_got_int32(pktp, vbp, pIfData->ifRcvAddrStatus); break; case LEAF_ifRcvAddressType: getproc_got_int32(pktp, vbp, pIfData->ifRcvAddrType); break; default: return; } }/******************************************************************************* ifRcvAddrEntryGet ** Get 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 ifRcvAddrEntryGet ( OIDC_T lastmatch, int tcount, OIDC_T * tlist, SNMP_PKT_T * pktp, VB_T * vbp ) { int i; int index; M2_IFRCVADDRTBL rcvAddr; /* Group together all varbinds which have the same getproc and instance */ snmpdGroupByGetprocAndInstance(pktp, vbp, tcount, tlist); if ((tcount < 2) || (tcount != tlist[1] + 2) || (tcount > MAXIFPHYADDR + 2)) { for ( ; vbp != NULL; vbp = vbp->vb_link) { getproc_nosuchins (pktp, vbp); } return; } /* Extract the interface index for indexing into the interface table */ index = *tlist; for (i = 2; i < tcount; i++) rcvAddr.ifRcvAddrAddr.phyAddress[i-2] = *(tlist + i); rcvAddr.ifRcvAddrAddr.addrLength = tcount - 2; /* Call the m2 API to get the status for this index */ if (m2IfRcvAddrEntryGet (M2_EXACT_VALUE, &index, &rcvAddr) != OK) { for ( ; vbp != NULL; vbp = vbp->vb_link) { getproc_nosuchins (pktp, vbp); } return; } for ( ; vbp; vbp = vbp->vb_link) { ifRcvAddrInfoGet (vbp->vb_ml.ml_last_match, pktp, vbp, &rcvAddr); } }/******************************************************************************* ifRcvAddrEntryBuildInstance** Make a proper instance from the information in the ifRcvAddressTable.** Parameters to this routine are * * <ifIndex> - the value of ifIndex for this row.* <rcvAddr> - the structure holding the physical address information.* <tmpInst> - where the instance will be created.** RETURNS: the length of the instance created* */ int ifRcvAddrEntryBuildInstance ( int ifIndex, M2_IFRCVADDRTBL *rcvAddr, OIDC_T *tmpInst ) { int i; *tmpInst = ifIndex; *(tmpInst + 1) = rcvAddr->ifRcvAddrAddr.addrLength; for (i = 0; i < *(tmpInst + 1) ; i++) *(tmpInst + i + 2) = rcvAddr->ifRcvAddrAddr.phyAddress[i]; return (2 + *(tmpInst + 1)); }/******************************************************************************* ifRcvAddrEntryNext** Next 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 ifRcvAddrEntryNext ( OIDC_T lastmatch, int tcount, OIDC_T * tlist, SNMP_PKT_T * pktp, VB_T * vbp ) { int error; int bestExists; int ifIndex; int tmpInstLen; int bestInstLen = 0; OIDC_T tmpInst[MAXIFPHYADDR+1]; OIDC_T bestInst[MAXIFPHYADDR+1]; M2_IFRCVADDRTBL rcvAddr; M2_IFRCVADDRTBL bestRcvAddr; /* * Group together all varbinds which have the same getproc * and instance. */ group_by_getproc_and_instance (pktp, vbp, tcount, tlist); /* generate the instance of each table entry and find the * smallest instance that's larger than tcount/tlist */ ifIndex = 0; bestExists = 0; MEMSET (&rcvAddr, 0, sizeof (M2_IFRCVADDRTBL)); for (error = m2IfRcvAddrEntryGet (M2_NEXT_VALUE, &ifIndex, &rcvAddr); error == OK ; error = m2IfRcvAddrEntryGet (M2_NEXT_VALUE, &ifIndex, &rcvAddr)) { tmpInstLen = ifRcvAddrEntryBuildInstance (ifIndex, &rcvAddr, tmpInst); if ((oidcmp2 (tmpInstLen, tmpInst, tcount, tlist) > 0) && ((bestExists == 0) || (oidcmp2 (tmpInstLen, tmpInst,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -