snmp.c revision b695575577bae0337af339d76949713bfe1c9013
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <fm/fmd_snmp.h>
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <locale.h>
#include <strings.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include <alloca.h>
static struct stats {
} snmp_stats = {
};
static int snmp_trapall; /* set to trap on all faults */
static const char SNMP_SUPPCONF[] = "fmd-trapgen";
/*ARGSUSED*/
static void
{
static const oid sunFmProblemUUID_oid[] =
static const oid sunFmProblemCode_oid[] =
static const oid sunFmProblemURL_oid[] =
int i;
/*
* The format of our trap varbinds' oids is as follows:
*
* +-----------------------+---+--------+----------+------+
* | SUNFMPROBLEMTABLE_OID | 1 | column | uuid_len | uuid |
* +-----------------------+---+--------+----------+------+
* \---- index ----/
*
* A common mistake here is to send the trap with varbinds that
* do not contain the index. All the indices are the same, and
* all the oids are the same length, so the only thing we need to
* do for each varbind is set the table and column parts of the
* variable name.
*/
if (var_len > MAX_OID_LEN) {
return;
}
for (i = 0; i < uuid_len; i++)
/*
* Ordinarily, we would need to add the OID of the trap itself
* to the head of the variable list; this is required by SNMP v2.
* However, send_enterprise_trap_vars does this for us as a part
* of converting between v1 and v2 traps, so we skip directly to
* the objects we're sending.
*/
sunFmProblem_base_len * sizeof (oid));
sunFmProblem_base_len * sizeof (oid));
sunFmProblem_base_len * sizeof (oid));
/*
* Which is sent to a specific destination is determined by the
* configuration file(s).
*/
}
/*ARGSUSED*/
static void
{
return;
}
return;
}
} else {
}
}
static int
init_sma(void)
{
int err;
/*
* The only place we could possibly log is syslog, but the
* full agent doesn't normally log there. It would be confusing
* if this agent did so; therefore we disable logging entirely.
*/
/*
* Net-SNMP has a provision for reading an arbitrary number of
* configuration files. A configuration file is read if it has
* had any handlers registered for it, or if it's the value in
* of NETSNMP_DS_LIB_APPTYPE. Our objective here is to read
* both snmpd.conf and fmd-trapgen.conf.
*/
return (err);
init_agent_read_config("snmpd");
return (err);
return (SNMPERR_MALLOC);
if (register_app_config_handler("trap2sink",
NULL)
return (SNMPERR_MALLOC);
return (SNMPERR_MALLOC);
init_traps();
return (SNMPERR_SUCCESS);
}
static const fmd_prop_t fmd_props[] = {
};
static const fmd_hdl_ops_t fmd_ops = {
snmp_recv, /* fmdo_recv */
NULL, /* fmdo_timeout */
NULL, /* fmdo_close */
NULL, /* fmdo_stats */
NULL, /* fmdo_gc */
};
static const fmd_hdl_info_t fmd_info = {
};
void
{
return; /* invalid data in configuration file */
if (init_sma() != SNMPERR_SUCCESS)
if (snmp_msghdl == NULL)
}
/*ARGSUSED*/
void
{
/*
* snmp_shutdown, which we would normally use here, calls free_slots,
* a callback that is supposed to tear down the pkcs11 state; however,
* it abuses C_Finalize, causing fmd to drop core on shutdown. Avoid
* this by shutting down the library piecemeal.
*/
shutdown_mib();
}