📄 snmpip.c
字号:
if (addr != htonl(pRteEntry->ipRouteMask)) { errorStatus = INCONSISTENT_VALUE; goto errorReturn; }#endif break; case LEAF_ipRouteDest : memcpy (&addr, vbp->value_u.v_network_address, IP_ADDR_LEN); if (ntohl (addr) != pRteEntry->ipRouteDest ) { errorStatus = INCONSISTENT_VALUE; goto errorReturn; } break; case LEAF_ipRouteType: switch (vbp->value_u.v_number) { case M2_ipRouteType_other: case M2_ipRouteType_direct: case M2_ipRouteType_indirect: break; case M2_ipRouteType_invalid: if (! entryExists) { /* Attempt to delete non existent entry */ errorStatus = NO_SUCH_NAME; goto errorReturn; } break; default: errorStatus = WRONG_VALUE; goto errorReturn; } break; case LEAF_ipRouteNextHop: memcpy (&addr, vbp->value_u.v_network_address, IP_ADDR_LEN); if (addr == 0 || addr == 0xffffffff) { errorStatus = WRONG_VALUE; goto errorReturn; } nextHopFlag = TRUE; break; default: errorStatus = GEN_ERR; goto errorReturn; } } if ( !entryExists && !nextHopFlag) { /* * we cannot proceed with the set since row creation is required but * the next hop field is not available */ errorStatus = INCONSISTENT_VALUE; goto errorReturn; } for (vbp = pVbpSaved; vbp; vbp = vbp->vb_link) { testproc_good (pktp, vbp); } return;errorReturn: testproc_error (pktp, pVbpSaved, errorStatus); } /******************************************************************************* ipRouteEntrySet - Set method routine for ipRouteTable.** 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 ipRouteEntrySet ( OIDC_T lastmatch, int compc, OIDC_T * compl, SNMP_PKT_T * pktp, VB_T * vbp ) { M2_IPROUTETBL rteEntry; M2_IPROUTETBL * pRteEntry; unsigned int varToSet = 0; VB_T * pVbpSaved = vbp; int dataChanged = 0; memset (&rteEntry, 0, sizeof rteEntry); /* get the index for the table entry, already stored in vb_priv area */ pRteEntry = (M2_IPROUTETBL *) vbp->vb_priv; rteEntry.ipRouteDest = pRteEntry->ipRouteDest; for ( ; vbp; vbp = vbp->vb_link) { switch (vbp->vb_ml.ml_last_match) { case LEAF_ipRouteIfIndex: case LEAF_ipRouteMetric1: case LEAF_ipRouteMetric2: case LEAF_ipRouteMetric3: case LEAF_ipRouteMetric4: case LEAF_ipRouteMetric5: case LEAF_ipRouteAge: break; case LEAF_ipRouteMask:#ifdef M2_IP_ROUTE_MASK /* If the m2lib supports SETs for this, update the information. */ memcpy (&rteEntry.ipRouteMask, vbp->value_u.v_network_address, IP_ADDR_LEN); rteEntry.ipRouteMask = ntohl (rteEntry.ipRouteMask); varToSet |= M2_IP_ROUTE_MASK; dataChanged = 1;#endif break; case LEAF_ipRouteDest: varToSet |= M2_IP_ROUTE_DEST; dataChanged = 1; break; case LEAF_ipRouteNextHop: memcpy (&rteEntry.ipRouteNextHop, vbp->value_u.v_network_address, IP_ADDR_LEN); rteEntry.ipRouteNextHop = ntohl (rteEntry.ipRouteNextHop); varToSet |= M2_IP_ROUTE_NEXT_HOP; dataChanged = 1; break; case LEAF_ipRouteType: rteEntry.ipRouteType = vbp->value_u.v_number; varToSet |= M2_IP_ROUTE_TYPE; dataChanged = 1; break; } } pVbpSaved->undoproc = (UNDOPROC_T *) ipRouteEntryUndo; /* The m2IpRouteTblEntrySet is indexed by both destination and next hop * unlike m2IpRouteTblEntryGet, so we need to fill in next hop field if * not specified. All this assumes that we do not have multiple entries * with the same destination field in the routing table, but that is the * way mib-2 wants it anyway */ if (rteEntry.ipRouteNextHop == 0) { rteEntry.ipRouteNextHop = ((M2_IPROUTETBL *)pVbpSaved->vb_priv)-> ipRouteNextHop; } if ((dataChanged == 1) && (m2IpRouteTblEntrySet (varToSet, &rteEntry) != OK )) { snmpVbPrivFree (pVbpSaved); setproc_error (pktp, pVbpSaved, COMMIT_FAILED); return; } for (vbp = pVbpSaved ; vbp; vbp = vbp->vb_link) { setproc_good (pktp, vbp); } } /******************************************************************************* ipRouteEntryUndo - Undo method routine for ipRouteTable.** 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 ipRouteEntryUndo */void ipRouteEntryUndo ( OIDC_T lastmatch, int compc, OIDC_T * compl, SNMP_PKT_T * pktp, VB_T * vbp ) { if (vbp->vb_priv == NULL) { goto goodReturn; } /* * The comlete original entry was saved so we simply restore * all the writable fields. */ if (m2IpRouteTblEntrySet ((M2_IP_ROUTE_DEST | M2_IP_ROUTE_NEXT_HOP | M2_IP_ROUTE_TYPE), (M2_IPROUTETBL *) vbp->vb_priv ) != OK ) { undoproc_error (pktp, vbp, UNDO_FAILED); return; }goodReturn: undoproc_good (pktp, vbp); return; }/******************************************************************************* ipSet - Set method routine for ipGroup.* * * 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 ipSet ( OIDC_T lastmatch, int compc, OIDC_T * compl, SNMP_PKT_T * pktp, VB_T * vbp ) { M2_IP ipVars; /* struct for ip variables */ unsigned int varToSet; /* fields to be set */ VB_T * pVbpSaved; /* save init value of vbp */ varToSet = 0; pVbpSaved = vbp; /* set up undo reutine */ pVbpSaved->undoproc = (UNDOPROC_T *) ipUndo; for ( ; vbp; vbp = vbp->vb_link) { switch (vbp->vb_ml.ml_last_match) { case LEAF_ipForwarding: ipVars.ipForwarding = vbp->value_u.v_number; varToSet |= M2_IPFORWARDING; break; case LEAF_ipDefaultTTL: ipVars.ipDefaultTTL = vbp->value_u.v_number; varToSet |= M2_IPDEFAULTTTL; break; } } if ( m2IpGroupInfoSet (varToSet, &ipVars) != OK ) { /* Since this set failed the undo is pointless as nothing has changed. * However since the undo proc for this vb will be called we remove the * attached undo buffer to distinguish between a required undo and this * case. */ snmpVbPrivFree (pVbpSaved); setproc_error (pktp, pVbpSaved, COMMIT_FAILED); return; } for (vbp = pVbpSaved ; vbp; vbp = vbp->vb_link) { setproc_good (pktp, vbp); } } /******************************************************************************* ipUndo - Undo method routine for ipGroup.* * 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 ipUndo ( OIDC_T lastmatch, int compc, OIDC_T * compl, SNMP_PKT_T * pktp, VB_T * vbp ) { M2_IP ipVars; if (vbp->vb_priv == NULL) { goto goodReturn; } /* restore the saved values */ ipVars.ipForwarding = *((long *)vbp->vb_priv); ipVars.ipDefaultTTL = *(((long *)vbp->vb_priv) + 1); if ( m2IpGroupInfoSet (M2_IPFORWARDING | M2_IPDEFAULTTTL, &ipVars) != OK ) { undoproc_error (pktp, vbp, UNDO_FAILED); return; }goodReturn: undoproc_good (pktp, vbp); return; }/******************************************************************************* ipTest - Test method routine for ip group scalars.** 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** RETURN: N/A**/ void ipTest ( OIDC_T lastmatch, int compc, OIDC_T * compl, SNMP_PKT_T * pktp, VB_T * vbp ) { M2_IP ipVars; /* struct for ip info */ int errorStatus; /* error status value */ INT_32_T number; /* local copy of vb number field */ if ((compc != 1) || (*compl != 0)) { errorStatus = NO_SUCH_NAME; goto errorReturn; } if (m2IpGroupInfoGet (&ipVars) != OK) { errorStatus = GEN_ERR; goto errorReturn; } /* callback rtn for freeing memory */ vbp->vb_free_priv = (VBPRIVPROC_T *) snmpVbPrivFree; /* * Allocate 2 longs to save the ipForwarding and ipDefaultTTL fields - * the only writable ones in the ip scalars */ vbp->vb_priv = snmpdMemoryAlloc ( 2 * sizeof (long)); if (vbp->vb_priv == NULL) { errorStatus = RESOURCE_UNAVAILABLE; goto errorReturn; } /* Save current values for undo if needed */ *((long *)vbp->vb_priv) = ipVars.ipForwarding; *(((long *)vbp->vb_priv) + 1) = ipVars.ipDefaultTTL; /* Group together all varbinds which have the same getproc and instance */ for (snmpdGroupByGetprocAndInstance (pktp, vbp, compc, compl); vbp; vbp = vbp->vb_link) { number = vbp->value_u.v_number; switch (vbp->vb_ml.ml_last_match) { case LEAF_ipForwarding: if ((number != M2_ipForwarding_forwarding) && (number != M2_ipForwarding_not_forwarding)) { testproc_error (pktp, vbp, WRONG_VALUE); return; } break; case LEAF_ipDefaultTTL: if ( (number <= 0) || (number > IP_MAX_TTL)) { testproc_error (pktp, vbp, WRONG_VALUE); return; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -