snmp.c revision 749f21d359d8fbd020c974a1a5227316221bfc9c
/*
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#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>
/*
* SNMP_DOMAIN defines the dgettext() parameters the agent
* can use to retrieve the localized format string for diagnosis messages.
* The format string retrieved from SNMP_DOMAIN is the default format
* string, but when processing each suspect list, dgettext() is also called
* for the domain that matches the diagcode dictname.
*
* Similarly, SNMP_URL is also checked to see if snmp_url
* should be overridden for each suspect list.
*
* The net effect of all this is that for a given diagcode DICT-1234-56:
*
* - If DICT.mo defines snmp-url, it is used when filling
* in the sunFmProblemURL variable.
*
* - Otherwise, if snmp-trapgen.conf defines a "url" property, that
* value is used.
*
* - Otherwise, the default "http://sun.com/msg/" is used (via the
* fmd_props[] table defined in this file).
*/
static const char SNMP_DOMAIN[] = "FMD";
static const char SNMP_URL[] = SNMP_URL_MSG;
static struct stats {
} snmp_stats = {
};
static char *snmp_locdir; /* l10n messages directory (if alternate) */
static char *snmp_url; /* current value of "url" property */
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;
}
/*
* Extract the uuid and diagcode dictionary from the event code. The
* dictionary name is the text preceding the first "-" in the code.
*/
return;
}
if (snmp_locdir != NULL)
/*
* We didn't find a translation in the dictionary for the
* current language. Fall back to C and try again.
*/
}
/*
* If the URL ends with a slash, that indicates the code should be
* appended to it. After formatting the URL, reformat the DESC
* text using the URL as an snprintf argument.
*/
} else {
}
/*
* We have what we need; now send the trap.
*/
/*
* Switch back to our original language if we had to fall back to C.
*/
}
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)
/*
* All FMA event dictionaries use msgfmt(1) message objects to produce
* messages, even for the C locale. We therefore want to use dgettext
* for all message lookups, but its defined behavior in the C locale is
* to return the input string. Since our input strings are event codes
* and not format strings, this doesn't help us. We resolve this nit
* by setting NLSPATH to a non-existent file: the presence of NLSPATH
* is defined to force dgettext(3C) to do a full lookup even for C.
*/
/*
* Cache any properties we use every time we receive an event and
* subscribe to list.suspect events regardless of the .conf file.
*/
/*
* If fmd's rootdir property is set to a non-default root, then we are
* going to need to rebind the text domains we use for dgettext() as
* we go. Look up the default l10n messages directory and make
* snmp_locdir be this path with fmd.rootdir prepended to it.
*/
}
}
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();
}