252N/A/*
252N/A * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
252N/A *
252N/A * U.S. Government Rights - Commercial software. Government users are subject
252N/A * to the Sun Microsystems, Inc. standard license agreement and applicable
252N/A * provisions of the FAR and its supplements.
252N/A *
252N/A *
252N/A * This distribution may include materials developed by third parties. Sun,
252N/A * Sun Microsystems, the Sun logo and Solaris are trademarks or registered
252N/A * trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
252N/A *
252N/A */
252N/A#pragma ident "@(#)entLastChangeTime.c 1.1 03/02/24 SMI"
252N/A
252N/A/*
252N/A * Note: this file originally auto-generated by mib2c using
252N/A * : mib2c.scalar.conf,v 1.5 2002/07/18 14:18:52 dts12 Exp $
252N/A */
252N/A
252N/A#include <net-snmp/net-snmp-config.h>
252N/A#include <net-snmp/net-snmp-includes.h>
252N/A#include <net-snmp/agent/net-snmp-agent-includes.h>
252N/A#include "stdhdr.h"
252N/A#include "entLastChangeTime.h"
252N/A
252N/A/* Fix for 4929068 */
252N/Astatic int creg;
252N/A/* End of Fix for 4929068 */
252N/A
252N/Astatic void poll_entLastChangeTime();
252N/Astatic void send_entConfigChange_trap();
252N/A
252N/A/* time between entConfigChange traps in 1/1000th of a second */
252N/A#define TRAP_THROTTLE_PERIOD 5000
252N/A/* Fix for 4929068 */
252N/A#define TRAP_THROTTLE_PERIOD_SECS TRAP_THROTTLE_PERIOD/1000
252N/A/* End of Fix for 4929068 */
252N/A
252N/A/* Fix for 4928832 */
252N/A/* Static storage for markers */
252N/Astatic struct timeval entLastChangeTimeStorage;
252N/Astatic struct timeval trapLastIssuedStorage;
252N/A
252N/A/* Pointers to storage for markers */
252N/Astatic marker_t entLastChangeTime;
252N/Astatic marker_t trapLastIssued;
252N/A/* End of Fix for 4928832 */
252N/A
252N/A/* 4929068 - structures for debugging throttling period waits
252N/Astatic struct timeval alarmTimeStorage;
252N/Astatic marker_t alarmTime;
252N/A*/
252N/A
252N/Astatic oid entityMIBTrapsOID[] = { entityMIBTraps };
252N/A
252N/A
252N/A/*
252N/A * returns the value of sysUpTime in TimeTicks
252N/A */
252N/Astatic unsigned long
252N/AentLastChangeTime_TimeTicks()
252N/A{
252N/A return (unsigned long) netsnmp_marker_uptime(entLastChangeTime) &
252N/A 0xFFFFFFFF;
252N/A}
252N/A
252N/A/* Initializes the entLastChangeTime module */
252N/Avoid
252N/Ainit_entLastChangeTime(void)
252N/A{
252N/A static oid entLastChangeTime_oid[] =
252N/A { 1, 3, 6, 1, 2, 1, 47, 1, 4, 1, 0 };
252N/A
252N/A DEBUGMSGTL(("entLastChangeTime", "Initializing\n"));
252N/A
252N/A/* Fix for 4928832 */
252N/A entLastChangeTime = (marker_t)&entLastChangeTimeStorage;
252N/A trapLastIssued = (marker_t)&trapLastIssuedStorage;
252N/A/* End of Fix for 4928832 */
252N/A/* Fix for 4928828 */
252N/A entLastChangeTimeStorage.tv_sec = 0;
252N/A entLastChangeTimeStorage.tv_usec = 0;
252N/A atime_setMarker(entLastChangeTime);
252N/A/* End of Fix for 4928828 */
252N/A
252N/A/* 4929068 - debug code
252N/A alarmTime = (marker_t)&alarmTimeStorage;
252N/A*/
252N/A
252N/A if (!entLastChangeTime || !trapLastIssued)
252N/A return;
252N/A
252N/A netsnmp_register_read_only_instance(netsnmp_create_handler_registration
252N/A ("entLastChangeTime", get_entLastChangeTime, entLastChangeTime_oid,
252N/A OID_LENGTH(entLastChangeTime_oid), HANDLER_CAN_RONLY));
252N/A}
252N/A
252N/A/* Fix for 4929068 */
252N/A/*
252N/A * alarm_entLastChangeTime - called after throttle period over,
252N/A * poll to see if anything was suppressed.
252N/A */
252N/Astatic void alarm_entLastChangeTime(unsigned int regnum, void *data) {
252N/A/* 4929068 - debug code
252N/A atime_setMarker(alarmTime);
252N/A printf("alarm_entLastChangeTime, marker time = %d\n",
252N/A (netsnmp_marker_uptime(alarmTime) & 0xFFFFFFFF));
252N/A*/
252N/A
252N/A poll_entLastChangeTime();
252N/A}
252N/A/* End of Fix for 4929068 */
252N/A
252N/Aint
252N/Aget_entLastChangeTime(netsnmp_mib_handler * handler,
252N/A netsnmp_handler_registration * reginfo,
252N/A netsnmp_agent_request_info * reqinfo, netsnmp_request_info * requests)
252N/A{
252N/A unsigned long t;
252N/A
252N/A /*
252N/A * We are never called for a GETNEXT if it's registered as a
252N/A * "instance", as it's "magically" handled for us.
252N/A */
252N/A
252N/A /*
252N/A * a instance handler also only hands us one request at a time, so
252N/A * we don't need to loop over a list of requests; we'll only get one.
252N/A */
252N/A
252N/A switch (reqinfo->mode) {
252N/A
252N/A case MODE_GET:
252N/A
252N/A t = entLastChangeTime_TimeTicks();
252N/A snmp_set_var_typed_value(requests->requestvb, ASN_TIMETICKS,
252N/A (u_char *) & t, sizeof (t));
252N/A break;
252N/A
252N/A default:
252N/A /*
252N/A * we should never get here, so this is a really bad error
252N/A */
252N/A return (SNMP_ERR_GENERR);
252N/A }
252N/A
252N/A return (SNMP_ERR_NOERROR);
252N/A}
252N/A
252N/Avoid
252N/AconfigChanged()
252N/A{
252N/A atime_setMarker(entLastChangeTime);
252N/A poll_entLastChangeTime();
252N/A}
252N/A
252N/Astatic void
252N/Apoll_entLastChangeTime()
252N/A{
252N/A long diff;
252N/A
252N/A /* don't issue trap if within throttle period */
252N/A if (!atime_ready(trapLastIssued, TRAP_THROTTLE_PERIOD))
252N/A return;
252N/A
252N/A diff = atime_diff(entLastChangeTime, trapLastIssued);
252N/A if (diff <= 0 ) {
252N/A /* there was a change since the last trap was issued */
252N/A
252N/A send_entConfigChange_trap();
252N/A
252N/A atime_setMarker(trapLastIssued);
252N/A /* Fix for 4929068 */
252N/A /*
252N/A * Set up alarm to wake up TRAP_THROTTLE_PERIOD_SECS seconds
252N/A * after the last trap was sent. If anything was suppressed,
252N/A * a trap will be sent.
252N/A */
252N/A creg = snmp_alarm_register(TRAP_THROTTLE_PERIOD_SECS, NULL,
252N/A alarm_entLastChangeTime, NULL);
252N/A /* End of Fix for 4929068 */
252N/A }
252N/A}
252N/A
252N/Astatic void
252N/Asend_entConfigChange_trap()
252N/A{
252N/A send_enterprise_trap_vars(SNMP_TRAP_ENTERPRISESPECIFIC, 1,
252N/A entityMIBTrapsOID, OID_LENGTH(entityMIBTrapsOID), NULL);
252N/A}
252N/A
252N/A