📄 snmpip.c
字号:
entryExists = FALSE; } for (snmpdGroupByGetprocAndInstance (pktp, vbp, compc, compl); vbp; vbp = vbp->vb_link) { switch (vbp->vb_ml.ml_last_match) { case LEAF_ipNetToMediaIfIndex: if (vbp->value_u.v_number != pNetMediaEntry->ipNetToMediaIfIndex) { /* We're not going to allow sets to this object * for instances that already exist. */ errorStatus = WRONG_VALUE; goto errorReturn; } /* else part should do value checks xxxxxxxxxx ??? */ break; case LEAF_ipNetToMediaNetAddress: memcpy (&addr, vbp->value_u.v_network_address, IP_ADDR_LEN); if (ntohl (addr) != pNetMediaEntry->ipNetToMediaNetAddress) { errorStatus = WRONG_VALUE; goto errorReturn; } break; case LEAF_ipNetToMediaPhysAddress: length = EBufferUsed (&vbp->value_u.v_string); if ((length <= 0) || (length > MAXIFPHYADDR)) { errorStatus = WRONG_VALUE; goto errorReturn; } physAddrFlag = TRUE; break; case LEAF_ipNetToMediaType: switch (vbp->value_u.v_number) { case VAL_ipNetToMediaType_other: case VAL_ipNetToMediaType_dynamic: case VAL_ipNetToMediaType_static: if ((entryExists) && (vbp->value_u.v_number != pNetMediaEntry->ipNetToMediaType)) { errorStatus = INCONSISTENT_VALUE; goto errorReturn; } break; case VAL_ipNetToMediaType_invalid: if (! entryExists) { /* attempt to delete non existent entry */ errorStatus = NO_SUCH_NAME; goto errorReturn; } break; default: errorStatus = WRONG_VALUE; goto errorReturn; } break; } } if ( !entryExists && !physAddrFlag) { /* Attempt to create new row with the phys address column unspecified */ errorStatus = INCONSISTENT_VALUE; goto errorReturn; } for ( vbp = pVbpSaved; vbp; vbp = vbp->vb_link) { testproc_good (pktp, vbp); } return;errorReturn: testproc_error (pktp, pVbpSaved, errorStatus); }/******************************************************************************* ipNetToMediaEntrySet - Set routine for ip net to media table** Parameters to this routine are * * <lastmatch> - the last oid component that was matched to get to this leaf.* <compc> - count of components remaining in the unmatched portion i.e.* the length of the instance portion.* <compl> - 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.** NOMANUAL** RETURNS: N/A*/void ipNetToMediaEntrySet ( OIDC_T lastmatch, int compc, OIDC_T * compl, SNMP_PKT_T * pktp, VB_T * vbp ) { M2_IPATRANSTBL netMediaEntry; int length; VB_T * pVbpSaved ; M2_IPATRANSTBL * pNetMediaEntry; int dataChanged = 0; memset (&netMediaEntry, 0, sizeof netMediaEntry); /* get the index for the table entry, already stored in vb_priv area */ pNetMediaEntry = (M2_IPATRANSTBL *) vbp->vb_priv; netMediaEntry.ipNetToMediaIfIndex = pNetMediaEntry->ipNetToMediaIfIndex; netMediaEntry.ipNetToMediaNetAddress = pNetMediaEntry-> ipNetToMediaNetAddress; pVbpSaved = vbp; for ( ; vbp; vbp = vbp->vb_link) { switch (vbp->vb_ml.ml_last_match) { case LEAF_ipNetToMediaIfIndex: break; case LEAF_ipNetToMediaPhysAddress: length = EBufferUsed (&vbp->value_u.v_string); memcpy (&netMediaEntry.ipNetToMediaPhysAddress.phyAddress, EBufferStart (&vbp->value_u.v_string), length); netMediaEntry.ipNetToMediaPhysAddress.addrLength = length; dataChanged = 1; break; case LEAF_ipNetToMediaNetAddress: break; case LEAF_ipNetToMediaType: netMediaEntry.ipNetToMediaType = vbp->value_u.v_number; break; } } /* install the undo procedure */ pVbpSaved->undoproc = (UNDOPROC_T *) ipNetToMediaEntryUndo; if ((dataChanged == 1) && (m2IpAtransTblEntrySet (&netMediaEntry) != OK )) { snmpVbPrivFree (pVbpSaved); setproc_error (pktp, pVbpSaved, COMMIT_FAILED); return; } for ( vbp = pVbpSaved ; vbp != NULL; vbp = vbp->vb_link) { setproc_good (pktp, vbp); }}/******************************************************************************* ipNetToMediaEntryGet - Get routine for ip net to media table** Parameters to this routine are * * <lastmatch> - the last oid component that was matched to get to this leaf.* <compc> - count of components remaining in the unmatched portion i.e.* the length of the instance portion.* <compl> - 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.** NOMANUAL** RETURNS: N/A*/void ipNetToMediaEntryGet ( OIDC_T lastmatch, int compc, OIDC_T * compl, SNMP_PKT_T * pktp, VB_T * vbp ){ M2_IPATRANSTBL netMediaEntry; snmpdGroupByGetprocAndInstance (pktp, vbp, compc, compl); /* * Check for valid instance and also get ip address part of the * index */ if ((compc != IP_NET_TO_MEDIA_INDEX_LEN ) || snmpOidToIpHostOrder ( IP_ADDR_LEN, compl + 1, &netMediaEntry.ipNetToMediaNetAddress) ) { for ( ; vbp != NULL; vbp = vbp->vb_link) { getproc_nosuchins (pktp, vbp); } return; } /* get interface index part of the index */ netMediaEntry.ipNetToMediaIfIndex = *compl; if (m2IpAtransTblEntryGet (M2_EXACT_VALUE, &netMediaEntry) != OK ) { for ( ; vbp != NULL; vbp = vbp->vb_link) { getproc_nosuchins (pktp, vbp); } return; } for ( ; vbp; vbp = vbp->vb_link) { ipNetToMediaEntryInfoGet (vbp->vb_ml.ml_last_match, pktp, vbp, &netMediaEntry); }}/******************************************************************************* ipNetToMediaEntryNext - Next routine for ip net to media table*** Parameters to this routine are * * <lastmatch> - the last oid component that was matched to get to this leaf.* <compc> - count of components remaining in the unmatched portion i.e.* the length of the instance portion.* <compl> - 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.** NOMANUAL** RETURNS: N/A*/#if 0/* The following function is considerably more efficient than the one that's * provided further down. However, due to a bug in the * m2IpAtransTblEntryGet() function, this function doesn't order the table * correctly. Until a fix is available for the m2Lib, the less-efficient * function will have to suffice. */void ipNetToMediaEntryNext ( OIDC_T lastmatch, int compc, OIDC_T * compl, SNMP_PKT_T * pktp, VB_T * vbp ) { M2_IPATRANSTBL netMediaEntry; OIDC_T netMediaIndex [IP_NET_TO_MEDIA_INDEX_LEN]; snmpdGroupByGetprocAndInstance (pktp, vbp, compc, compl); /* Increment instance part by 1 */ if (snmpNextIndex (compc, compl, netMediaIndex, maxNetToMediaIndex, IP_NET_TO_MEDIA_INDEX_LEN)) { /* instance part was already no less than max possible index */ for ( ; vbp != NULL; vbp = vbp->vb_link) { nextproc_no_next (pktp, vbp); } return; } /* get index value */ netMediaEntry.ipNetToMediaIfIndex = * netMediaIndex; (void) snmpOidToIpHostOrder (IP_ADDR_LEN, netMediaIndex + 1, &netMediaEntry.ipNetToMediaNetAddress); if (m2IpAtransTblEntryGet (M2_NEXT_VALUE, & netMediaEntry) != OK ) { for ( ; vbp != NULL; vbp = vbp->vb_link) { snmpNextError (pktp, vbp); } return; } /* Convert ip address and interface index to oid form */ (void)ip_to_rlist (htonl (netMediaEntry.ipNetToMediaNetAddress), netMediaIndex + 1); *netMediaIndex = netMediaEntry.ipNetToMediaIfIndex; for ( ; vbp; vbp = vbp->vb_link) { /* Install instance part for next value found */ nextproc_next_instance (pktp, vbp, IP_NET_TO_MEDIA_INDEX_LEN, netMediaIndex); /* Install the value */ ipNetToMediaEntryInfoGet (vbp->vb_ml.ml_last_match, pktp, vbp, &netMediaEntry); }}#elsevoid ipNetToMediaEntryNext ( OIDC_T lastmatch, int compc, OIDC_T * compl, SNMP_PKT_T * pktp, VB_T * vbp ) { M2_IPATRANSTBL netMediaEntry; M2_IPATRANSTBL bestNetMediaEntry; OIDC_T netMediaIndex [IP_NET_TO_MEDIA_INDEX_LEN]; OIDC_T nextNetMediaIndex [IP_NET_TO_MEDIA_INDEX_LEN]; OIDC_T bestNetMediaIndex [IP_NET_TO_MEDIA_INDEX_LEN]; int best = 0; int nextSuccess = OK; snmpdGroupByGetprocAndInstance (pktp, vbp, compc, compl); MEMSET (&netMediaEntry, 0, sizeof (M2_IPATRANSTBL)); MEMSET (&bestNetMediaEntry, 0, sizeof (M2_IPATRANSTBL)); for (nextSuccess = m2IpAtransTblEntryGet (M2_NEXT_VALUE, & netMediaEntry); nextSuccess == OK; nextSuccess = m2IpAtransTblEntryGet (M2_NEXT_VALUE, & netMediaEntry)) { netMediaIndex [0] = netMediaEntry.ipNetToMediaIfIndex; ip_to_llist ((bits32_t)ntohl (netMediaEntry.ipNetToMediaNetAddress), (sbits32_t *)& netMediaIndex [1]); if ((oidcmp2 (IP_NET_TO_MEDIA_INDEX_LEN, netMediaIndex, compc, compl) > 0) && (((best == 0) || (oidcmp2 (IP_NET_TO_MEDIA_INDEX_LEN, netMediaIndex, IP_NET_TO_MEDIA_INDEX_LEN, bestNetMediaIndex) < 0)))) { best = 1; MEMCPY (&bestNetMediaEntry, &netMediaEntry, sizeof (M2_IPATRANSTBL)); MEMCPY (&bestNetMediaIndex, &netMediaIndex, sizeof (OIDC_T) * IP_NET_TO_MEDIA_INDEX_LEN); } snmpNextIndex (IP_NET_TO_MEDIA_INDEX_LEN, netMediaIndex, nextNetMediaIndex, maxNetToMediaIndex, IP_NET_TO_MEDIA_INDEX_LEN); netMediaEntry.ipNetToMediaIfIndex = nextNetMediaIndex [0]; snmpOidToIpHostOrder (IP_ADDR_LEN, & nextNetMediaIndex [1], & netMediaEntry.ipNetToMediaNetAddress); } if (best != 0) { /* we found a next so get the values and set the instance for all * the varbinds for this row of this table. */ for ( ; vbp != NULL; vbp = vbp->vb_link) { nextproc_next_instance (pktp, vbp, IP_NET_TO_MEDIA_INDEX_LEN, bestNetMediaIndex); ipNetToMediaEntryInfoGet (vbp->vb_ml.ml_last_match, pktp, vbp, &bestNetMediaEntry); } } else for ( ; vbp != NULL; vbp = vbp->vb_link) nextproc_no_next (pktp, vbp); }#endif/******************************************************************************* ipNetToMediaEntryUndo - Undo routine for ip net to media table** Parameters to this routine are * * <lastmatch> - the last oid component that was matched to get to this leaf.* <compc> - count of components remaining in the unmatched portion i.e.* the length of the instance portion.* <compl> - 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.** NOMANUAL** RETURNS: N/A*/LOCAL void ipNetToMediaEntryUndo ( OIDC_T lastmatch, int compc, OIDC_T * compl, SNMP_PKT_T * pktp, VB_T * vbp ) { if (vbp->vb_priv == NULL) { goto goodReturn; } if (m2IpAtransTblEntrySet ((M2_IPATRANSTBL *)vbp->vb_priv) != OK ) { undoproc_error (pktp, vbp, UNDO_FAILED); return; }goodReturn: undoproc_good (pktp, vbp); return; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -