📄 snmpdlib.c
字号:
}/******************************************************************************** snmpHookPreSet - perform user-specified actions before a `set' operation** This routine is called after all `testproc' operations have* completed successfully, but before any `setproc' operation is begun.* 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 snmpHookPreSet ( SNMP_PKT_T * pPkt /* Pointer to SNMP packet */ ) { if (snmpHkPreSetRtn != NULL) { return ((*snmpHkPreSetRtn) (pPkt)); } return 0; }/******************************************************************************* snmpHookPostSet - perform user-specified actions after a `set' operation** This routine is called after all `setproc' have completed* successfully. This routine can be used to free resources allocated* during `set' processing. This routine must be provided by the user,* if it is required.** RETURNS: N/A** NOMANUAL*/int snmpHookPostSet ( SNMP_PKT_T * pPkt /* Pointer to SNMP packet */ ) { if (snmpHkPostSetRtn != NULL) { return ((*snmpHkPostSetRtn) (pPkt)); } return 0; }/******************************************************************************** snmpHookSetFailed - perform user-specified actions on failure of a `set' operation** 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. This routine must be provided by the user, if it* is required.** RETURNS: N/A** NOMANUAL*/int snmpHookSetFailed ( SNMP_PKT_T * pPkt /* Pointer to SNMP packet */ ) { if (snmpHkSetFailedRtn != NULL) { return ((*snmpHkSetFailedRtn) (pPkt)); } return 0; }/******************************************************************************** snmpdContinue - continue processing of an SNMP packet* * This routine continues processing a packet. snmpdPktProcess() begins* the method routines needed to fulfill the request, while this* routine determines whether the current set of method routines have* finished; it then either starts more method routines or sends a* response packet.** If a method routine returns before completing its task, it must* arrange for snmpdContinue() to be called when the task is completed.* You must obtain the write-lock on this packet by calling* snmpdPktLockGet() prior to calling snmpdContinue(). snmpdContinue() * releases the write-lock when it completes.** <pPkt> is a pointer to the structure that contains the packet.** RETURNS: N/A**/void snmpdContinue ( SNMP_PKT_T * pPkt /* snmp packet */ );/******************************************************************************** snmpdGroupByGetprocAndInstance - gather set of similar variable bindings** This routine gathers a set of similar variable bindings together by* searching the variable bindings in <pktp>, starting at <firstVbp>* for a match of the `getproc' pointer of <firstVbp> and with an* instance specified by <compc> and <compl>. This routine then links* the variable bindings found which match <firsVbp>.** This routine does not set any flags in the variable bindings. It is* left to the calling routine to decide whether the <tested> or <set> flags* should be set.** RETURNS: N/A**/void snmpdGroupByGetprocAndInstance ( SNMP_PKT_T * pPkt, /* snmp packet */ VB_T * pFirstVbp, /* first var bind */ int compc, /* component count */ OIDC_T * compl /* component length */ );/******************************************************************************** snmpdVbRowExtract - extract required pieces of a row for a `set' operation** This routine assists in implementing row-creation `set' operations.* It is typically used by the `testproc' routine for a table. It scans* the SNMP packet looking for all the pieces that go together for the* purposes of creating a new row in an SNMP table.** The parameter <row> describes what this routine is looking for.* <row> is a list of MIB leaf pointers referring to variables in the* table in question, and a flag indicating if this variable (<column>)* in the table is required. This routine searches the variable* bindings in <pktp> for a match of the MIB leaf pointer specified in* the row array and the instance specified by <compc> and <compl>. It* links the variable bindings found from the first MIB leaf node in* the row array. This first variable binding must be in the packet * whether it is marked as needed or not, and is the return value of* snmpdVbRowExtract().** If snmpdVbRowExtract() does not find a matching variable binding and* that leaf is flagged ROW_FLAG_NEEDED in the row array, the routine* returns NULL to indicate an error.** This routine marks the variable bindings in the resulting list as* already tested except for the first entry, which is marked as* already set. As a result, the agent only calls the `set' routine* associated with the first MIB leaf in the row array. This `set'* routine should handle creation of the necessary data structures and* reading the variable binding list to execute the required `set'* operations. You can force other entries set routines to be called* by flagging entries with ROW_FLAG_CALL_SET.** RETURNS: a pointer to the first variable binding if successful,* otherwise NULL.**/VB_T * snmpdVbRowExtract ( SNMP_PKT_T * pPkt, /* snmp packet */ int start_index, /* starting index */ int compc, /* component count */ OIDC_T * compl, /* component length */ int row_structure_length, /* length of row structure */ struct create_row * pRow /* row structure */ );/******************************************************************************** snmpdVbExtractRowLoose - incrementally extract pieces of a row for a set ** This routine assists in implementing row-creation `set' operations,* especially in the case of ``dribble'' creation. In ``dribble''* creation, the network management station may choose to break the* creation of a new entry in some table into multiple packets. Using* multiple packets does not work with snmpdVbRowExtract(), which* requires at least one specified item to be in the packet.** In dribble creation, there is no single item that is guaranteed to* be in every packet. As its name implies, this routine is similar to* snmpdVbRowExtract(). It searches the variable bindings in <pktp>* starting at <indx> for a match of the MIB leaf pointer specified in* the <leaves> array and with an instance specified by <compc> and* <compl>. The routine then links the variable bindings found from* the last variable binding found.* * If no variable bindings are found, this routine returns a NULL* pointer. This routine does not set any of the flags in the variable* bindings. It is left to the calling routine to decide if the <tested>* or <set> flags should be set.** RETURNS: a pointer to the last variable binding if successful,* otherwise NULL.**/VB_T * snmpdVbExtractRowLoose ( SNMP_PKT_T * pPkt, /* snmp packet */ int indx, /* index */ MIBLEAF_T ** pLeaves, /* mib leaves */ int compc, /* component count */ OIDC_T * compl /* component length */ );/******************************************************************************** snmpdPktLockGet - lock an SNMP packet ** This routine obtains a lock on the SNMP packet being processed,* which must be obtained by any asynchronous method routine prior to* calling any of the routines `getproc_*', `nextproc_*', `testproc_*',* or `setproc_*', or also snmpdContinue(). snmpdContinue() releases* the lock before returning. No other routine can release this lock.** This routine blocks until the lock is obtained.** Returns: OK, or ERROR on failure.** SEE ALSO: `snmpProcLib', snmpdContinue()*/STATUS snmpdPktLockGet ( SNMP_PKT_T * pPkt /* snmp packet */ ) { return (semTake (pPkt->continue_lock, WAIT_FOREVER)); }/******************************************************************************** snmpTraceInput - Function called by envoy for input pkt tracing.** Prints out some of the fields of the pkt via snmpdLog** RETURNS: N/A** NOMANUAL*/void snmpTraceInput ( SNMP_PKT_T * pPkt /* snmp packet */ ) { static char * pduNames [MAX_PDU + 1] = /* names for pdu */ { "Get", "GetNext", "GetResponse", "Set", "Trap", "GetBulk", "Inform", "Trap2", "Report" }; char * buf; /* output buffer */ char * pPduType; /* ptr to pdu name */ int needLen; if (EBufferUsed(&pPkt->community) == 0) needLen = 256; else needLen = 128 + EBufferUsed(&pPkt->community); if ((buf = SNMP_memory_alloc(needLen)) == 0) /* We can't generate a message if we can't get the memory to put it in. */ return; if (pPkt->pdu_type > MAX_PDU) { pPduType = "Unknown"; } else { pPduType = pduNames [pPkt->pdu_type]; } /* We have several options. If 2275 views are installed then we should output a string for the view name instead of the integer view index that is used for 1445 views. Also if v3 is installed we check the version type and output the user name instead of the community string that we use for v1 or v2 packets */#if INSTALL_ENVOY_SNMP_RFC2275_VIEWS#if INSTALL_ENVOY_SNMP_VERSION_3 if (SNMP_pkt_get_SNMP_version(pPkt) == SNMP_VERSION_3) { sprintf (buf, "PduType = %sPdu PduLength = %d User = %.*s " "ViewIndex = %.*s\n", pPduType, pPkt->pdu_length, EBufferUsed (&(pPkt->msg_sec_name)), EBufferStart(&(pPkt->msg_sec_name)), EBufferUsed (&(pPkt->view_name)), pPkt->view_name.start_bp); } else#endif { sprintf (buf, "PduType = %sPdu PduLength = %d Community = %.*s " "ViewIndex = %.*s\n", pPduType, pPkt->pdu_length, EBufferUsed (&(pPkt->community)), pPkt->community.start_bp, EBufferUsed (&(pPkt->view_name)), pPkt->view_name.start_bp); }#else sprintf (buf, "PduType = %sPdu PduLength = %d Community = %.*s " "ViewIndex = %d \n", pPduType, pPkt->pdu_length, EBufferUsed (&(pPkt->community)), pPkt->community.start_bp, pPkt->view_index);#endif snmpdLog (SNMP_INFO, buf); SNMP_memory_free(buf); }/********************************************************************************* envoy_now - return the relative time in milliseconds*** RETURNS: a millisecond count **/bits32_t envoy_now (void) { struct timespec clockTime; ulong_t currTime; clock_gettime (CLOCK_REALTIME, &clockTime); currTime = ((clockTime.tv_sec * 1000) + (clockTime.tv_nsec / 1000)); return (currTime); }/********************************************************************************* envoy_call_timer - execute the specified function when the timer expires** This routine executes the <what> function after <when> ticks have elapsed.* This function is used internally to respond when the interval between the* test and set of a "test and set" exceeds the timeout specified by <when>.** RETURNS: N/A**/voidenvoy_call_timer(bits32_t when, void (*what)()){bits8_t start_timeout[] = "3";/* update the structure which the timer task reads */timerBlock.what = what;timerBlock.when = when; /* time in ticks */msgQSend(tmrQID, (char *) start_timeout, 1, NO_WAIT, MSG_PRI_URGENT);}/******************************************************************************** snmpdMemoryAlloc - allocate memory for the SNMP agent** This routine allocates memory for the SNMP agent. The required size* of the block is passed in <size>. * This memory must be deallocated later with snmpdMemoryFree().** RETURNS: a pointer to the allocated buffer on success, otherwise NULL.** SEE ALSO: snmpdMemoryFree()*/void * snmpdMemoryAlloc ( size_t size /* size of memory to be allocated */ ) { return ((char*) malloc (size)); }/******************************************************************************** snmpdMemoryFree - free memory allocated by the SNMP agent** This routine deallocates memory which was previously allocated by the* SNMP agent with snmpdMemoryAlloc().** RETURNS: N/A** SEE ALSO: snmpdMemoryAlloc()*/void snmpdMemoryFree ( void * pBuf /* buffer to free */ ) { free (pBuf); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -