📄 snmpdlib.c
字号:
STATUS snmpdTreeAdd ( char * pTreeOidStr, MIBNODE_T * pTreeAddr ) { int status = 0; MIBNODE_T * pReplacedNode; OBJ_ID_T treeOid; OIDC_T oidArray [MAX_OID_LEN]; treeOid.num_components = snmpOidStrToArray (pTreeOidStr, oidArray); if (treeOid.num_components > 0) { treeOid.component_list = oidArray; semTake (SNMP_CoarseLock, WAIT_FOREVER); status = Add_Node_From_Root (NULL, &treeOid, pTreeAddr, &pReplacedNode); semGive (SNMP_CoarseLock); if ( status == 0 ) { snmpdLog (SNMP_INFO, "Mib tree added successfully\n"); } else { snmpdLog (SNMP_WARN, "Unable to add mib tree\n"); } } return ((status == 0) ? OK : ERROR); }/******************************************************************************* snmpdTreeRemove - dynamically remove part of the SNMP agent MIB tree** This routine deletes part of the SNMP agent MIB tree at* runtime. Once the specified subtree is deleted, any further requests* to access objects of that subtree fail.** RETURNS: N/A** SEE ALSO:* .I WindNet SNMPv1v2c VxWorks Component Release Supplement*/void snmpdTreeRemove ( char * pTreeOidStr /* char string specifying oid of tree to remove */ ) { OBJ_ID_T treeOid; OIDC_T oidArray [MAX_OID_LEN]; treeOid.num_components = snmpOidStrToArray (pTreeOidStr, oidArray); if (treeOid.num_components > 0) { treeOid.component_list = oidArray; semTake (SNMP_CoarseLock, WAIT_FOREVER); Remove_Node_From_Root (NULL, &treeOid); semGive (SNMP_CoarseLock); } }#if 0/******************************************************************************** snmpCentiSecsGet - get hundreds of a second** The number of hundreds of a second that have passed since this routine was* first called.** Note: This routine assumes that the sysClkRate will never get above* 2^32 / 100. If it does then the remainder portion of the equations will* rollover. This _shouldn't_ be a problem.** RETURNS: Hundreds of a second since the group was initialized.** NOMANUAL*/LOCAL ulong_t snmpCentiSecsGet (void) { struct timespec clockTime; ulong_t currTime; clock_gettime (CLOCK_REALTIME, &clockTime); currTime = ((clockTime.tv_sec * 100) + (clockTime.tv_nsec / 10000)); if (snmpStartCentiSecs == 0) snmpStartCentiSecs = currTime; return (currTime - snmpStartCentiSecs); }#endif /* #if 0 *//******************************************************************************** snmpNextIndex - Computes the next feasible OID for m2 routines** Function to compute the next feasible OID for some given * table index type.** <compc> - component count of input oid sequence* <compl> - input oid sequence* <pOutOid> - output OID sequence. This buffer must be provided by the caller,* and be big enough for an oid sequence of length oidLen.* <pMaxOid> - The max possible table index of this kind.* e.g. for the udpTable the index can be max ff.ff.ff.ff.ffff* <oidLen> - length of index oid sequence** RETURNS:* 0 if valid next index generated in OutOid.* 1 if no next index value possible.** NOMANUAL*/int snmpNextIndex ( int compc, /* Component count */ const OIDC_T * compl, /* Oid for which lexicographic next is reqd */ OIDC_T * pOutOid, /* Output oid i.e. the next feasible oid */ const OIDC_T * pMaxOid, /* max possible value for the index oid */ int oidLen /* length of index oid */ ) { int ix; int lastCarryIndex = oidLen; int carryFlag = 0; /* Ignore components beyond end of index. They don't matter */ if (compc > oidLen) { compc = oidLen; } memset (pOutOid, 0, oidLen * sizeof *pOutOid); memcpy (pOutOid, compl, compc * sizeof *pOutOid); /* add a 1 to least significant end if and only if input oid * sequence has length equal to length of the table index. */ for (ix = oidLen - 1; ix >= 0; --ix) { if ( pOutOid [ix] >= pMaxOid [ix] ) { if ( ix == 0 ) { return (1); } lastCarryIndex = ix; carryFlag = 1; } else if (carryFlag == 1) { ++ pOutOid [ix]; carryFlag = 0; } } for ( ix = lastCarryIndex; ix < oidLen; ++ix) { pOutOid [ix] = 0; } if ((lastCarryIndex == oidLen) && (compc == oidLen)) { ++ pOutOid [compc - 1]; } return (0); }/******************************************************************************** snmpVbPrivFree** Routine for freeing memory allocated in the vb_priv field of a var bind** RETURNS: N/A* NOMANUAL*/void snmpVbPrivFree ( VB_T * pVbp /* varbind */ ) { if ( pVbp->vb_priv != NULL ) { snmpdMemoryFree (pVbp->vb_priv); pVbp->vb_priv = NULL; } }/********************************************************************************* snmpOidToIpHostOrder** Converts an oid sequence representing an ip address to an ip address* in host order** RETURNS: 0 if valid ip address generated else non zero** NOMANUAL*/int snmpOidToIpHostOrder ( int compLen, /* component length */ OIDC_T * pCompSeq, /* component sequence */ ulong_t * pIpAddr /* ip address */ ) { int status; status = oid_to_ip (compLen, pCompSeq, pIpAddr); *pIpAddr = ntohl (*pIpAddr); return (status); }/******************************************************************************** snmpOidStrToArray - Convert oid in string form to oid component array * * Convert an oid in string form <pOidStr> to an array of oid components, * <pOidArray> which is a user supplied array and must be of sufficient size.** RETURNS: 0 on failure else number of oid components in the array* * NOMANUAL*/int snmpOidStrToArray ( char * pOidStr, /* input oid string */ OIDC_T * pOidArray /* output oid compononent array */ ) { int oidLen = 0; char * pIx; for (pIx = pOidStr; ; ++ pIx ) { if ( !isdigit ((int) *pIx)) { /* Non digit char where we stop must be either '.' or EOS. * Also when we stop at one of these it must not be the first * char encountered. This could happen for example if we heve * 2 consecutive '.' chars in the input or it starts with a '.'. * */ if ( (*pIx != '.' && *pIx != EOS) || pIx == pOidStr) { snmpdLog (SNMP_WARN, "Invalid object identifier syntax\n"); return (0); } pOidArray [oidLen ++] = atol (pOidStr); if (*pIx == EOS) { break; } pOidStr = pIx + 1; } } return (oidLen); }/******************************************************************************** snmpdInitFinish - complete the initialization of the agent** This routine is required to be called by the user to complete the* initialization of the SNMP agent after the transport endpoint has* been initialized. This routine must be called \f2after\fR the endpoint has* been established, since it depends on that endpoint to function* correctly.** This routine also installs any user-supplied hooks for customizing* the agent. If a hook is not required, a NULL pointer should be passed* in that position. The function snmpIoTrapSend() is invoked by this* routine, so any configuration required by that routine should be* done prior to calling snmpdInitFinish().** The hook routines are as follows:** .iP "<pPrivRlse>" 8 * This routine is used by the agent to free any memory attached to the* private field of the SNMP_PKT_T structure. * .iP "<pSetPduVldt>"* This routine is called before any processing of a `set' request has* taken place. It can be used to perform global validation of the* request, if needed. The return values for this routine must meet the* following requirements:* * 0 - indicates that the `set' PDU is valid, and processing should continue.* * 1 - indicates that the `set' PDU is valid, and that this routine has* already completed all the required `set' operations.* * -1 - indicates that the `set' PDU is invalid and should be rejected.* .iP "<pPreSet>"* This routine is called after all `testproc' operations have* completed successfully, but before any `setproc' operation is begun.* Return value requirements are as follows* * 0 - indicates that the `set' PDU is valid, and processing should continue.* * 1 - indicates that the `set' PDU is valid, and that this routine has* already completed all the required `set' operations.* * -1 - indicates that the `set' PDU is invalid and should be rejected.* .iP "<pPostSet>"* This routine is called after all `setproc' have completed* successfully. This routine can be used to free resources allocated* during `set' processing. * .iP "<pSetFailed>"* This routine is possibly called under two sets of circumstances:* after all `testproc' operations have returned and some of them have* failed, and/or after all `undoproc' operations have returned and* some `setproc' operations have failed. It can be used to do any* required cleanup. * .LP** RETURNS: N/A*/void snmpdInitFinish ( VOIDFUNCPTR pPrivRlse, /* user's privare release routine */ FUNCPTR pSetPduVldt, /* user's set pdu validate routine */ FUNCPTR pPreSet, /* user's pre set routine */ FUNCPTR pPostSet, /* user's post set routine */ FUNCPTR pSetFailed /* user's set failed routine */ ) { snmpHkPrivRlseRtn = pPrivRlse; snmpHkSetPduVldtRtn = pSetPduVldt; snmpHkPreSetRtn = pPreSet; snmpHkPostSetRtn = pPostSet; snmpHkSetFailedRtn = pSetFailed; }/******************************************************************************** snmpdExit - exit the SNMP agent** This routine causes the SNMP agent to exit. It is available in case* the user encounters some problem after a successful startup. * * This routine must be called from the main thread. Any other tasks* spawned by the user (for asynchronous method routines) should be* deleted prior to calling this function.** RETURNS: N/A**/void snmpdExit (void) { snmpdCleanup (); }/******************************************************************************** snmpHookPrivRelease - release private memory used by hooks** This routine is used by the agent to free any memory attached to the* private field of the SNMP_PKT_T structure. This routine must be* provided by the user, if it is required.** RETURNS: N/A** NOMANUAL*/void snmpHookPrivRelease ( SNMP_PKT_T *pPkt /* snmp packet */ ) { if (snmpHkPrivRlseRtn != NULL) { ((*snmpHkPrivRlseRtn) (pPkt)); } }/******************************************************************************** snmpHookSetPduValidate - validate a `set' request PDU** This routine is called before any processing of a `set' request has* taken place. It can be used to perform global validation of the* request, if needed. This routine must be provided by the user, if* it is required.** RETURNS: * 0 indicates that the `set' PDU is valid, and processing should continue.* 1 indicates that the `set' PDU is valid, and that this routine has* already completed all the required `set' operations.* -1 indicates that the `set' PDU is invalid and should be rejected.** NOMANUAL*/int snmpHookSetPduValidate ( SNMP_PKT_T * pPkt /* Pointer to SNMP packet */ ) { if (snmpHkSetPduVldtRtn != NULL) { return ((*snmpHkSetPduVldtRtn) (pPkt)); } return 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -