⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sendntfy.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
📖 第 1 页 / 共 4 页
字号:
/* sendntfy.c - sendntfy.c routines *//* *  Copyright 2000-2005 Wind River Systems, Inc. *  All rights reserved.  Provided under license only. *  Distribution or other use of this software is only *  permitted pursuant to the terms of a license agreement *  from Wind River Systems (and is otherwise prohibited). *  Refer to that license agreement for terms of use. *//* *  Copyright 1998 Integrated Systems, Inc. *  All rights reserved. *//* * $Log: sendntfy.c,v $ * Revision 1.6  2002/08/26 20:31:05  josh * modifications to the code to eliminate warnings from Diab compiler * * Revision 1.5  2002/06/24 20:23:35  josh * re-cast the 'specific' variable so Diab will build this module * without warnings * * Revision 1.4  2002/01/15 21:42:03  josh * cleaning up the code a bit...ritual purification * * Revision 1.3  2002/01/11 22:44:36  josh * initialize agentip_tdomain and agentip_taddress before using them * let SNMPv1 and SNMPv2c notifications own their own copies of the * community string * * Revision 1.2  2001/11/06 21:20:27  josh * revised new path hacking * * Revision 1.1.1.1  2001/11/05 17:47:43  tneale * Tornado shuffle * * Revision 9.19.4.3  2001/09/21 19:29:24  josh * adjustments for expanded structures and moved functions * * Revision 9.19.4.2  2001/08/07 18:33:58  josh * adding support for SNMPv1/v2c/v3 coexistence to SNMP Notify code * * Revision 9.19.4.1  2001/08/06 20:05:39  meister * Added dynamic component configuration macros to V3 conditional code * * Revision 9.19  2001/04/27 21:10:39  josh * removed some duplicate code from SNMP_Send_Notify_Name() * * Revision 9.18  2001/04/11 20:42:58  josh * merge from the kingfisher branch * * Revision 9.17  2001/01/19 22:22:26  paul * Update copyright. * * Revision 9.16  2000/07/12 20:09:25  josh * moving SNMP_Find_Matching_Engine_ID() from sendntfy.c to v3_eng.c * * Revision 9.15  2000/06/09 13:55:08  josh * changing of installation option-related builds.  Moved certain glue * functions to v3_ber.c from sendntfy.c so they get built even when * ENVOY_SNMP_V3_NOTIFY isn't installed * * Revision 9.14.2.5  2001/03/12 22:08:25  tneale * Updated copyright * * Revision 9.14.2.4  2001/01/25 22:09:50  josh * fixed a few places where we forgot to release the lock in * SNMP_Send_Notify() and SNMP_Send_Notify_Name() * * Revision 9.14.2.3  2001/01/19 21:32:25  josh * prototype for SNMP_Send_Notify_Name().  retrans_timer_exp() redefined * to static * * Revision 9.14.2.2  2000/12/13 20:51:08  josh * SNMP_Send_Notify_Name() now obsoletes SNMP_Send_Notify() * logic of SNMP_Send_Notify_Name() is improved to help prevent nesting of * locks and generally smooth out flow of data * * Revision 9.14.2.1  2000/09/20 21:47:00  josh * bringing branch up to currency with the root tree * * Revision 9.14  2000/03/17 00:19:22  meister * Update copyright message * * Revision 9.13  2000/03/09 13:51:32  josh * a shell function has been created to allow SNMPv3 requests * to be created while we're holding the coarse lock. * * Revision 9.12  2000/02/16 18:14:57  josh * cleaning up some memory leaks associated with error routines * * Revision 9.11  2000/01/04 21:03:27  josh * shuffled some more code (probe checking) to avoid another * potential deadlock situation. * * Revision 9.10  2000/01/02 22:55:59  josh * patching up a memory leak here, a broken compare there...per * sar's comments * * Revision 9.9  1999/12/06 18:42:11  josh * move the code that does the time update on pending retransmit * packets into v3_ber.c, where it won't cause a deadlock. * * Revision 9.8  1999/11/23 16:16:32  josh * put some locking code in to protect the engine list while * we're updating engine info in the packet * * Revision 9.7  1999/11/22 21:15:54  josh * fix a minor timing issue.  modify time-based code to update * a packet's engine boots and time information to prevent old * information from being retransmitted. * * Revision 9.6  1999/11/09 20:25:52  josh * cleaning up nits * * Revision 9.5  1999/11/09 17:56:39  josh * fixing memory leaks and initialization issues * * Revision 9.4  1999/11/05 20:59:35  josh * fixing an unaligned access problem with SNMPADDR_Ts * * Revision 9.3  1999/11/04 23:31:11  josh * fixing memory leaks found by Purify * * Revision 9.2  1999/11/04 21:14:05  josh * fixing Purify-related bugs * * Revision 9.1  1999/11/01 15:03:50  josh * manually reinitialize globals on startup -- makes Envoy restartable * * Revision 9.0  1999/10/21 20:41:37  josh * updating version stamps * * Revision 1.9  1999/10/15 17:50:02  josh * cosmetic change: Get_Tdomain macro is now Get_TDomain * * Revision 1.8  1999/10/07 23:42:08  josh * fix flags getting passed to create_request calls, add a default * SNMPADDR to TAddress conversion routine * * Revision 1.7  1999/10/03 00:18:10  josh * fixing retramit timer code -- setting handler correctly, * cleaning up some double-free situations, and putting locking in * where needed * * Revision 1.6  1999/09/30 22:10:26  josh * new cookie scheme to make sure cookies are only freed once * * Revision 1.5  1999/09/27 21:11:47  josh * fixing nits, rewriting engine id <--> address code, adding installation * option * * Revision 1.4  1999/09/15 16:17:37  josh * Linking the Retransmit Lock to the Retransmit list turns out to * be a lot more trouble than it's worth.  We'll just refer to * it directly, a la SNMP_CoarseLock. * * Revision 1.3  1999/09/14 19:29:28  josh * completed code for sending notifies * * Revision 1.2  1999/09/11 02:06:15  josh * some code rearrangement.  Stuff that was in this file is now in * ntfy_chk.c, while more pertinent code is here. * * Revision 1.1  1999/09/01 21:56:05  josh * Code to do actual sending of Notifies * * *//* [clearcase]modification history-------------------01d,12may05,job  fix apigen comments01c,18apr05,job  update copyright notices01b,22feb05,job  apigen for documented APIs01a,24nov03,job  update copyright information*//*DESCRIPTIONThis library contains sendntfy.c routines.INCLUDE FILES: snmp.h, v3_acc.h, v3_ntfy.h, v3_trgt.h, v3_eng.h, sendntfy.h*/#include <wrn/wm/snmp/engine/asn1.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/snmp/engine/view.h>#include <wrn/wm/snmp/engine/buffer.h>#include <wrn/wm/snmp/engine/v3_acc.h>#include <wrn/wm/snmp/engine/v3_ntfy.h>#include <wrn/wm/snmp/engine/v3_trgt.h>#include <wrn/wm/snmp/engine/v3_eng.h>#include <wrn/wm/snmp/engine/snmpdefs.h>#include <wrn/wm/snmp/engine/objectid.h>#include <wrn/wm/snmp/engine/ntfy_chk.h>#include <wrn/wm/snmp/engine/sendntfy.h>#include <wrn/wm/snmp/engine/wkobj.h>#if INSTALL_ENVOY_SNMP_COEXISTENCE#include <wrn/wm/snmp/engine/v3_comm.h>#endifextern RETRANS_COOKIE_T *root_retrans_cookie;static void retrans_timer_exp(ENVOY_TIMER_T *timer, void *cookie);#if INSTALL_ENVOY_SNMP_COEXISTENCE#define sizeof_snmpUDPDomain 7static OIDC_T snmpUDPDomain[] = { 1, 3, 6, 1, 6, 1, 1 };#endif/****************************************************************************NAME: retrans_timer_updatePURPOSE: Walk the retransmit list and determine whether the retransmit         timer needs to be set (or reset).  This call is always made         with the list locked, so care should be exercised...PARAMETERS: noneRETURNS: nothing****************************************************************************/static void  retrans_timer_update(void){bits32_t curtime = ENVOY_NOW();bits32_t nexttime = 0;SNMP_RETRANS_T *retrans;if (root_retrans_block.timer.handler == 0)    root_retrans_block.timer.handler = retrans_timer_exp;for (retrans = root_retrans_block.retrans; retrans; retrans = retrans->next) {    if (retrans->flags & 	(SNMP_RETRANS_FLAGS_EXPIRED | SNMP_RETRANS_FLAGS_ACKNOWLEDGED))        continue;    if (!(nexttime) || (nexttime > (retrans->time_sent + retrans->timeout)))        nexttime = retrans->time_sent + retrans->timeout;    }/* If there's no nexttime and there are still retrans blocks, we probably * have dead blocks that will need to be cleaned up later. */if ((!nexttime) && ((root_retrans_block.retrans) || (root_retrans_cookie)))    nexttime = curtime + ENVOY_RETRANS_CLEANUP_INTERVAL;if (nexttime)    envoy_tm_set(&root_retrans_block.timer,		 ((nexttime > curtime) ? (nexttime - curtime) : 0));else    envoy_tm_cancel(&root_retrans_block.timer);}/****************************************************************************\NOMANUALNAME: SNMP_Probe_CheckPURPOSE: Determine whether a probe attempt was successful and          perform the necessary gyrations to make sure the packet 	 gets updated if it has.         WARNING:  This function does a number of things that require	 internal knowledge of Envoy structures and methods.  For	 everyone's sake, please don't use this code as an example.PARAMETERS: SNMP_RETRANS_T  *retransRETURNS: 1 if successful, 0 otherwise****************************************************************************/int  SNMP_Probe_Check(SNMP_RETRANS_T *retrans){bits8_t *sec_id = 0;ALENGTH_T sec_id_len = 0;SNMP_PKT_T *pktp;int msg_flags = 0;SNMP_Find_Matching_Engine_ID(&(retrans->tlp->tdomain),			     &(retrans->tlp->taddress),			     &sec_id,			     &sec_id_len);if (sec_id_len == 0)    return 0;/* If we got here, we found a security ID for our notify.   * This is all we need to send the notify, so let's build the right packet. */switch(retrans->tlp->sec_level) {    case ETC_SEC_LEVEL_PRIV:        msg_flags |= ETC_V3_PRIV;        /* fall through... */    case ETC_SEC_LEVEL_AUTH:        msg_flags |= ETC_V3_AUTH;        /* fall through... */    case ETC_SEC_LEVEL_NONE:        break;    default:        return 0;    }pktp = SNMP_Create_Request_V3_Lockable(retrans->tlp->ptype,				       retrans->tlp->mp_model,				       0, 0, 				       msg_flags,				       retrans->tlp->sec_model,				       SNMP_Engine_Get_My_ID(),				       SNMP_Engine_Get_My_ID_Length(),				       EBufferStart(&(retrans->tlp->context)),				       EBufferUsed(&(retrans->tlp->context)),				       sec_id,				       sec_id_len,				       EBufferStart(&(retrans->tlp->sec_name)),				       EBufferUsed(&(retrans->tlp->sec_name)),				       0, 0, 0, 0, 0);if (!pktp)    return 0;SNMP_Free(retrans->pktp);retrans->tlp->pktp = 0;retrans->pktp = pktp;/* Now copy the VarBindList */MEMCPY(&(pktp->pdu.std_pdu.std_vbl),       retrans->tlp->vblp,       sizeof(VBL_T));/* We 'cleverly' free the original VBL_T but leave the list of varbinds * intact.   */SNMP_memory_free(retrans->tlp->vblp);retrans->tlp->vblp = 0;retrans->tlp->flags = 0;/* Update the information in the retrans block */retrans->retry_count = retrans->tlp->retry_count + 1;retrans->timeout = retrans->tlp->timeout;retrans->flags &= ~SNMP_RETRANS_FLAGS_SENDING_PROBE;clean_target_list(retrans->tlp);retrans->tlp = 0;ENVOY_SET_RETRANS_ID(retrans);pktp->pdu.std_pdu.request_id = retrans->retrans_id;pktp->msg_id = retrans->retrans_id;/* Make sure that this Inform is processed reasonably soon. */retrans->time_sent = ENVOY_NOW() - retrans->timeout;return(1);}/****************************************************************************NAME: retrans_timer_expPURPOSE: Handler for when the retrans timer expires.  Walk through the          retransmit list and retransmit any packets that need it.  At the 	 same time, expire any packets that have outlived their usefulness. PARAMETERS: RETURNS: nothing****************************************************************************/static void   retrans_timer_exp(ENVOY_TIMER_T *timer,		    void          *cookie){SNMP_RETRANS_T **retrans, **next_retrans;SNMP_RETRANS_T *dead_retrans;ALENGTH_T bufsize;RETRANS_COOKIE_T **retrans_cookie, *dead_retrans_cookie;#if INSTALL_ENVOY_SNMP_LOCKENVOY_SNMP_GET_WRITE_LOCK(SNMP_V3_Retrans_Lock);#endiffor (retrans = &root_retrans_block.retrans;      *retrans; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -