components/net-snmp/sun/agent/modules/entityMib/entLastChangeTime.c
changeset 252 ee0fb1eabcbf
equal deleted inserted replaced
251:f527656d334f 252:ee0fb1eabcbf
       
     1 /*
       
     2  * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
       
     3  *
       
     4  * U.S. Government Rights - Commercial software. Government users are subject
       
     5  * to the Sun Microsystems, Inc. standard license agreement and applicable
       
     6  * provisions of the FAR and its supplements.
       
     7  *
       
     8  *
       
     9  * This distribution may include materials developed by third parties. Sun,
       
    10  * Sun Microsystems, the Sun logo and Solaris are trademarks or registered
       
    11  * trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
       
    12  *
       
    13  */
       
    14 #pragma ident   "@(#)entLastChangeTime.c 1.1     03/02/24 SMI"
       
    15 
       
    16 /*
       
    17  * Note: this file originally auto-generated by mib2c using
       
    18  *        : mib2c.scalar.conf,v 1.5 2002/07/18 14:18:52 dts12 Exp $
       
    19  */
       
    20 
       
    21 #include <net-snmp/net-snmp-config.h>
       
    22 #include <net-snmp/net-snmp-includes.h>
       
    23 #include <net-snmp/agent/net-snmp-agent-includes.h>
       
    24 #include "stdhdr.h"
       
    25 #include "entLastChangeTime.h"
       
    26 
       
    27 /* Fix for 4929068 */
       
    28 static int creg;
       
    29 /* End of Fix for 4929068 */
       
    30 
       
    31 static void poll_entLastChangeTime();
       
    32 static void send_entConfigChange_trap();
       
    33 
       
    34 /* time between entConfigChange traps in 1/1000th of a second */
       
    35 #define	TRAP_THROTTLE_PERIOD	5000
       
    36 /* Fix for 4929068 */
       
    37 #define	TRAP_THROTTLE_PERIOD_SECS TRAP_THROTTLE_PERIOD/1000
       
    38 /* End of Fix for 4929068 */
       
    39 
       
    40 /* Fix for 4928832 */
       
    41 /* Static storage for markers */
       
    42 static struct timeval entLastChangeTimeStorage;
       
    43 static struct timeval trapLastIssuedStorage;
       
    44 
       
    45 /* Pointers to storage for markers */
       
    46 static marker_t entLastChangeTime;
       
    47 static marker_t trapLastIssued;
       
    48 /* End of Fix for 4928832 */
       
    49 
       
    50 /* 4929068 - structures for debugging throttling period waits
       
    51 static struct timeval alarmTimeStorage;
       
    52 static marker_t alarmTime;
       
    53 */
       
    54 
       
    55 static oid entityMIBTrapsOID[] = { entityMIBTraps };
       
    56 
       
    57 
       
    58 /*
       
    59  * returns the value of sysUpTime in TimeTicks
       
    60  */
       
    61 static unsigned long
       
    62 entLastChangeTime_TimeTicks()
       
    63 {
       
    64 	return (unsigned long) netsnmp_marker_uptime(entLastChangeTime) &
       
    65 	    0xFFFFFFFF;
       
    66 }
       
    67 
       
    68 /* Initializes the entLastChangeTime module */
       
    69 void
       
    70 init_entLastChangeTime(void)
       
    71 {
       
    72 	static oid entLastChangeTime_oid[] =
       
    73 	    { 1, 3, 6, 1, 2, 1, 47, 1, 4, 1, 0 };
       
    74 
       
    75 	DEBUGMSGTL(("entLastChangeTime", "Initializing\n"));
       
    76 
       
    77 /* Fix for 4928832 */
       
    78 	entLastChangeTime = (marker_t)&entLastChangeTimeStorage;
       
    79 	trapLastIssued = (marker_t)&trapLastIssuedStorage;
       
    80 /* End of Fix for 4928832 */
       
    81 /* Fix for 4928828 */
       
    82 	entLastChangeTimeStorage.tv_sec = 0;
       
    83 	entLastChangeTimeStorage.tv_usec = 0;
       
    84 	atime_setMarker(entLastChangeTime);
       
    85 /* End of Fix for 4928828 */
       
    86 
       
    87 /* 4929068 - debug code
       
    88 	alarmTime = (marker_t)&alarmTimeStorage;
       
    89 */
       
    90 
       
    91 	if (!entLastChangeTime || !trapLastIssued)
       
    92 	    return;
       
    93 
       
    94 	netsnmp_register_read_only_instance(netsnmp_create_handler_registration
       
    95 	    ("entLastChangeTime", get_entLastChangeTime, entLastChangeTime_oid,
       
    96 		OID_LENGTH(entLastChangeTime_oid), HANDLER_CAN_RONLY));
       
    97 }
       
    98 
       
    99 /* Fix for 4929068 */
       
   100 /*
       
   101  * alarm_entLastChangeTime - called after throttle period over,
       
   102  * poll to see if anything was suppressed.
       
   103  */
       
   104 static void alarm_entLastChangeTime(unsigned int regnum, void *data) {
       
   105 /* 4929068 - debug code
       
   106 	atime_setMarker(alarmTime);
       
   107 	printf("alarm_entLastChangeTime, marker time = %d\n",
       
   108 	(netsnmp_marker_uptime(alarmTime) & 0xFFFFFFFF));
       
   109 */
       
   110 
       
   111     poll_entLastChangeTime();
       
   112 }
       
   113 /* End of Fix for 4929068 */
       
   114 
       
   115 int
       
   116 get_entLastChangeTime(netsnmp_mib_handler * handler,
       
   117     netsnmp_handler_registration * reginfo,
       
   118     netsnmp_agent_request_info * reqinfo, netsnmp_request_info * requests)
       
   119 {
       
   120 	unsigned long t;
       
   121 
       
   122 	/*
       
   123 	 * We are never called for a GETNEXT if it's registered as a
       
   124 	 * "instance", as it's "magically" handled for us.
       
   125 	 */
       
   126 
       
   127 	/*
       
   128 	 * a instance handler also only hands us one request at a time, so
       
   129 	 * we don't need to loop over a list of requests; we'll only get one.
       
   130 	 */
       
   131 
       
   132 	switch (reqinfo->mode) {
       
   133 
       
   134 	case MODE_GET:
       
   135 
       
   136 		t = entLastChangeTime_TimeTicks();
       
   137 		snmp_set_var_typed_value(requests->requestvb, ASN_TIMETICKS,
       
   138 		    (u_char *) & t, sizeof (t));
       
   139 		break;
       
   140 
       
   141 	default:
       
   142 		/*
       
   143 		 * we should never get here, so this is a really bad error
       
   144 		 */
       
   145 		return (SNMP_ERR_GENERR);
       
   146 	}
       
   147 
       
   148 	return (SNMP_ERR_NOERROR);
       
   149 }
       
   150 
       
   151 void
       
   152 configChanged()
       
   153 {
       
   154 	atime_setMarker(entLastChangeTime);
       
   155 	poll_entLastChangeTime();
       
   156 }
       
   157 
       
   158 static void
       
   159 poll_entLastChangeTime()
       
   160 {
       
   161 	long diff;
       
   162 
       
   163 	/* don't issue trap if within throttle period */
       
   164 	if (!atime_ready(trapLastIssued, TRAP_THROTTLE_PERIOD))
       
   165 		return;
       
   166 
       
   167 	diff = atime_diff(entLastChangeTime, trapLastIssued);
       
   168 	if (diff <= 0 ) {
       
   169 		/* there was a change since the last trap was issued */
       
   170 
       
   171 		send_entConfigChange_trap();
       
   172 
       
   173 		atime_setMarker(trapLastIssued);
       
   174 		/* Fix for 4929068 */
       
   175 		/*
       
   176 		 * Set up alarm to wake up TRAP_THROTTLE_PERIOD_SECS seconds
       
   177 		 * after the last trap was sent.  If anything was suppressed,
       
   178 		 * a trap will be sent.
       
   179 		 */
       
   180 		creg = snmp_alarm_register(TRAP_THROTTLE_PERIOD_SECS, NULL,
       
   181 					   alarm_entLastChangeTime, NULL);
       
   182 		/* End of Fix for 4929068 */
       
   183 	}
       
   184 }
       
   185 
       
   186 static void
       
   187 send_entConfigChange_trap()
       
   188 {
       
   189         send_enterprise_trap_vars(SNMP_TRAP_ENTERPRISESPECIFIC, 1,
       
   190             entityMIBTrapsOID, OID_LENGTH(entityMIBTrapsOID), NULL);
       
   191 }
       
   192 
       
   193