11303Swesolows /*
21303Swesolows * CDDL HEADER START
31303Swesolows *
41303Swesolows * The contents of this file are subject to the terms of the
51303Swesolows * Common Development and Distribution License (the "License").
61303Swesolows * You may not use this file except in compliance with the License.
71303Swesolows *
81303Swesolows * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91303Swesolows * or http://www.opensolaris.org/os/licensing.
101303Swesolows * See the License for the specific language governing permissions
111303Swesolows * and limitations under the License.
121303Swesolows *
131303Swesolows * When distributing Covered Code, include this CDDL HEADER in each
141303Swesolows * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151303Swesolows * If applicable, add the following below this CDDL HEADER, with the
161303Swesolows * fields enclosed by brackets "[]" replaced with your own identifying
171303Swesolows * information: Portions Copyright [yyyy] [name of copyright owner]
181303Swesolows *
191303Swesolows * CDDL HEADER END
201303Swesolows */
211303Swesolows
221303Swesolows /*
23*11050SRobert.Johnston@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
241303Swesolows * Use is subject to license terms.
251303Swesolows */
261303Swesolows
271303Swesolows #include <sys/fm/protocol.h>
281303Swesolows #include <fm/fmd_adm.h>
291303Swesolows #include <fm/fmd_snmp.h>
301303Swesolows #include <net-snmp/net-snmp-config.h>
311303Swesolows #include <net-snmp/net-snmp-includes.h>
321303Swesolows #include <net-snmp/agent/net-snmp-agent-includes.h>
331303Swesolows #include <pthread.h>
341303Swesolows #include <stddef.h>
351303Swesolows #include <errno.h>
361303Swesolows #include <alloca.h>
371303Swesolows #include <locale.h>
381303Swesolows #include <libuutil.h>
391303Swesolows #include <libnvpair.h>
401303Swesolows #include "sunFM_impl.h"
411303Swesolows #include "problem.h"
421303Swesolows
431303Swesolows /*
441303Swesolows * We assume that the number of suspect fault events associated with a
451303Swesolows * particular case will generally be sufficiently small that the overhead
461303Swesolows * associated with indexing them in a tree would exceed the gain from
471303Swesolows * not traversing the fault list for each request.
481303Swesolows */
491303Swesolows static uu_avl_pool_t *problem_uuid_avl_pool;
501303Swesolows static uu_avl_t *problem_uuid_avl;
511303Swesolows
521303Swesolows #define VALID_AVL_STATE (problem_uuid_avl_pool != NULL && \
531303Swesolows problem_uuid_avl != NULL)
541303Swesolows
551303Swesolows #define UPDATE_WAIT_MILLIS 10 /* poll interval in milliseconds */
561303Swesolows
571303Swesolows /*
581303Swesolows * Update types. Single-index and all are mutually exclusive.
591303Swesolows */
601303Swesolows #define UCT_INDEX 0x1
611303Swesolows #define UCT_ALL 0x2
621303Swesolows #define UCT_FLAGS 0x3
631303Swesolows
641303Swesolows /*
651303Swesolows * Locking strategy is described in module.c.
661303Swesolows */
671303Swesolows static int valid_stamp;
681303Swesolows static pthread_mutex_t update_lock;
691303Swesolows static pthread_cond_t update_cv;
701303Swesolows static volatile enum { US_QUIET, US_NEEDED, US_INPROGRESS } update_status;
711303Swesolows
721303Swesolows static Netsnmp_Node_Handler sunFmProblemTable_handler;
731303Swesolows static Netsnmp_Node_Handler sunFmFaultEventTable_handler;
741303Swesolows
751303Swesolows static sunFmProblem_data_t *
problem_key_build(const char * uuid)761303Swesolows problem_key_build(const char *uuid)
771303Swesolows {
781303Swesolows static sunFmProblem_data_t key;
791303Swesolows
801303Swesolows key.d_aci_uuid = uuid;
811303Swesolows
821303Swesolows return (&key);
831303Swesolows }
841303Swesolows
851303Swesolows static sunFmProblem_data_t *
problem_lookup_uuid_exact(const char * uuid)861303Swesolows problem_lookup_uuid_exact(const char *uuid)
871303Swesolows {
881303Swesolows sunFmProblem_data_t *key, *data;
891303Swesolows
901303Swesolows key = problem_key_build(uuid);
911303Swesolows
921303Swesolows DEBUGMSGTL((MODNAME_STR, "lookup_exact for uuid %s\n", uuid));
931303Swesolows data = uu_avl_find(problem_uuid_avl, key, NULL, NULL);
941303Swesolows
951303Swesolows return (data);
961303Swesolows }
971303Swesolows
981303Swesolows static sunFmProblem_data_t *
problem_lookup_uuid_next(const char * uuid)991303Swesolows problem_lookup_uuid_next(const char *uuid)
1001303Swesolows {
1011303Swesolows sunFmProblem_data_t *key, *data;
1021303Swesolows uu_avl_index_t idx;
1031303Swesolows
1041303Swesolows key = problem_key_build(uuid);
1051303Swesolows
1061303Swesolows DEBUGMSGTL((MODNAME_STR, "lookup_next for uuid %s\n", uuid));
1071303Swesolows (void) uu_avl_find(problem_uuid_avl, key, NULL, &idx);
1081303Swesolows
1091303Swesolows data = uu_avl_nearest_next(problem_uuid_avl, idx);
1101303Swesolows
1111303Swesolows DEBUGMSGTL((MODNAME_STR, "lookup_next: entry is %p\n", data));
1121303Swesolows
1131303Swesolows return (data);
1141303Swesolows }
1151303Swesolows
1161303Swesolows static sunFmFaultEvent_data_t *
faultevent_lookup_index_exact(sunFmProblem_data_t * data,ulong_t index)1171303Swesolows faultevent_lookup_index_exact(sunFmProblem_data_t *data, ulong_t index)
1181303Swesolows {
1191303Swesolows if (index > data->d_nsuspects)
1201303Swesolows return (NULL);
1211303Swesolows
1221303Swesolows if (data->d_suspects == NULL)
1231303Swesolows return (NULL);
1241303Swesolows
1251303Swesolows return (data->d_suspects[index - 1]);
1261303Swesolows }
1271303Swesolows
1287275Sstephh static sunFmFaultStatus_data_t
faultstatus_lookup_index_exact(sunFmProblem_data_t * data,ulong_t index)1297275Sstephh faultstatus_lookup_index_exact(sunFmProblem_data_t *data, ulong_t index)
1307275Sstephh {
1317275Sstephh if (index > data->d_nsuspects)
1327288Sstephh return (0);
1337275Sstephh
1347275Sstephh if (data->d_statuses == NULL)
1357288Sstephh return (0);
1367288Sstephh
1377288Sstephh if (data->d_valid != valid_stamp)
1387288Sstephh return (0);
1397275Sstephh
1407275Sstephh return (data->d_statuses[index - 1]);
1417275Sstephh }
1427275Sstephh
1432134Swesolows /*ARGSUSED*/
1441303Swesolows static int
problem_update_one(const fmd_adm_caseinfo_t * acp,void * arg)1451303Swesolows problem_update_one(const fmd_adm_caseinfo_t *acp, void *arg)
1461303Swesolows {
1471303Swesolows sunFmProblem_data_t *data;
1481303Swesolows nvlist_t *nvl;
1491303Swesolows int64_t *diag_time;
1501303Swesolows uint_t nelem;
1511303Swesolows uint32_t nsusp;
1521303Swesolows int err;
1531303Swesolows
1541303Swesolows DEBUGMSGTL((MODNAME_STR, "update_one\n"));
1551303Swesolows
1561303Swesolows ASSERT(acp->aci_uuid != NULL);
1571303Swesolows
1581303Swesolows if ((data = problem_lookup_uuid_exact(acp->aci_uuid)) == NULL) {
1591303Swesolows uu_avl_index_t idx;
1601303Swesolows
1611303Swesolows DEBUGMSGTL((MODNAME_STR, "found new problem %s\n",
1621303Swesolows acp->aci_uuid));
1631303Swesolows if ((data = SNMP_MALLOC_TYPEDEF(sunFmProblem_data_t)) == NULL) {
164*11050SRobert.Johnston@Sun.COM (void) snmp_log(LOG_ERR, MODNAME_STR ": Out of memory "
165*11050SRobert.Johnston@Sun.COM "for new problem data at %s:%d\n", __FILE__,
166*11050SRobert.Johnston@Sun.COM __LINE__);
1671303Swesolows return (0);
1681303Swesolows }
1691303Swesolows if ((err = nvlist_dup(acp->aci_event, &data->d_aci_event, 0))
1701303Swesolows != 0) {
171*11050SRobert.Johnston@Sun.COM (void) snmp_log(LOG_ERR, MODNAME_STR ": Problem data "
172*11050SRobert.Johnston@Sun.COM "setup failed: %s\n", strerror(err));
1731303Swesolows SNMP_FREE(data);
1741303Swesolows return (0);
1751303Swesolows }
1761303Swesolows
1771303Swesolows data->d_aci_uuid = data->d_aci_code = data->d_aci_url = "-";
1781303Swesolows (void) nvlist_lookup_string(data->d_aci_event, FM_SUSPECT_UUID,
1791303Swesolows (char **)&data->d_aci_uuid);
1801303Swesolows (void) nvlist_lookup_string(data->d_aci_event,
1811303Swesolows FM_SUSPECT_DIAG_CODE, (char **)&data->d_aci_code);
1821303Swesolows data->d_aci_url = strdup(acp->aci_url);
1831303Swesolows
1841303Swesolows if (nvlist_lookup_nvlist(data->d_aci_event, FM_SUSPECT_DE,
1851303Swesolows &nvl) == 0)
1861303Swesolows if ((data->d_diag_engine = sunFm_nvl2str(nvl)) == NULL)
1871303Swesolows data->d_diag_engine = "-";
1881303Swesolows
1891303Swesolows if (nvlist_lookup_int64_array(data->d_aci_event,
1901303Swesolows FM_SUSPECT_DIAG_TIME, &diag_time, &nelem) == 0 &&
1911303Swesolows nelem >= 2) {
1921303Swesolows data->d_diag_time.tv_sec = (long)diag_time[0];
1931303Swesolows data->d_diag_time.tv_usec = (long)diag_time[1];
1941303Swesolows }
1951303Swesolows
1961303Swesolows (void) nvlist_lookup_uint32(data->d_aci_event,
1971303Swesolows FM_SUSPECT_FAULT_SZ, &nsusp);
1981303Swesolows data->d_nsuspects = (ulong_t)nsusp;
1991303Swesolows
2001303Swesolows (void) nvlist_lookup_nvlist_array(data->d_aci_event,
2011303Swesolows FM_SUSPECT_FAULT_LIST, &data->d_suspects, &nelem);
2021303Swesolows
2031303Swesolows ASSERT(nelem == data->d_nsuspects);
2041303Swesolows
2057275Sstephh (void) nvlist_lookup_uint8_array(data->d_aci_event,
2067275Sstephh FM_SUSPECT_FAULT_STATUS, &data->d_statuses, &nelem);
2077275Sstephh
2087275Sstephh ASSERT(nelem == data->d_nsuspects);
2097275Sstephh
2101303Swesolows uu_avl_node_init(data, &data->d_uuid_avl,
2111303Swesolows problem_uuid_avl_pool);
2121303Swesolows (void) uu_avl_find(problem_uuid_avl, data, NULL, &idx);
2131303Swesolows uu_avl_insert(problem_uuid_avl, data, idx);
2141303Swesolows
2151303Swesolows data->d_valid = valid_stamp;
2161303Swesolows
2171303Swesolows DEBUGMSGTL((MODNAME_STR, "completed new problem %s@%p\n",
2181303Swesolows data->d_aci_uuid, data));
2197288Sstephh } else {
2207288Sstephh uint8_t *statuses;
2217288Sstephh int i;
2227288Sstephh
2237288Sstephh (void) nvlist_lookup_uint8_array(acp->aci_event,
2247288Sstephh FM_SUSPECT_FAULT_STATUS, &statuses, &nelem);
2257288Sstephh
2267288Sstephh ASSERT(nelem == data->d_nsuspects);
2277288Sstephh
2287288Sstephh for (i = 0; i < nelem; i++)
2297288Sstephh data->d_statuses[i] = statuses[i];
2307288Sstephh
2317288Sstephh data->d_valid = valid_stamp;
2321303Swesolows }
2331303Swesolows
2341303Swesolows /*
2351303Swesolows * We don't touch problems we've seen before; they shouldn't change
2361303Swesolows * in any way we care about, since they've already been solved. The
2371303Swesolows * state, however, could change, and if we later expose that to the
2381303Swesolows * client we need to update it here.
2391303Swesolows */
2401303Swesolows
2411303Swesolows return (0);
2421303Swesolows }
2431303Swesolows
2441303Swesolows static int
problem_update(sunFmProblem_update_ctx_t * update_ctx)2451303Swesolows problem_update(sunFmProblem_update_ctx_t *update_ctx)
2461303Swesolows {
2471303Swesolows fmd_adm_t *adm;
2481303Swesolows
2491303Swesolows ASSERT(update_ctx != NULL);
2501303Swesolows ASSERT((update_ctx->uc_type & (UCT_INDEX|UCT_ALL)) !=
2511303Swesolows (UCT_INDEX|UCT_ALL));
2521303Swesolows ASSERT((update_ctx->uc_type & ~UCT_FLAGS) == 0);
2531303Swesolows ASSERT(VALID_AVL_STATE);
2541303Swesolows
2551303Swesolows if ((adm = fmd_adm_open(update_ctx->uc_host, update_ctx->uc_prog,
2561303Swesolows update_ctx->uc_version)) == NULL) {
257*11050SRobert.Johnston@Sun.COM (void) snmp_log(LOG_ERR, MODNAME_STR ": Communication with fmd "
2581303Swesolows "failed: %s\n", strerror(errno));
2591303Swesolows return (SNMP_ERR_RESOURCEUNAVAILABLE);
2601303Swesolows }
2611303Swesolows
2621303Swesolows ++valid_stamp;
2631303Swesolows if (fmd_adm_case_iter(adm, SNMP_URL_MSG, problem_update_one,
2641303Swesolows update_ctx) != 0) {
265*11050SRobert.Johnston@Sun.COM (void) snmp_log(LOG_ERR, MODNAME_STR ": fmd case information "
266*11050SRobert.Johnston@Sun.COM "update failed: %s\n", fmd_adm_errmsg(adm));
2671303Swesolows fmd_adm_close(adm);
2681303Swesolows return (SNMP_ERR_RESOURCEUNAVAILABLE);
2691303Swesolows }
2701303Swesolows
2711303Swesolows DEBUGMSGTL((MODNAME_STR, "case iteration completed\n"));
2721303Swesolows
2731303Swesolows fmd_adm_close(adm);
2741303Swesolows return (SNMP_ERR_NOERROR);
2751303Swesolows }
2761303Swesolows
2771303Swesolows /*ARGSUSED*/
2781303Swesolows static void
update_thread(void * arg)2791303Swesolows update_thread(void *arg)
2801303Swesolows {
2811303Swesolows /*
2821303Swesolows * The current problem_update implementation offers minimal savings
2831303Swesolows * for the use of index-only updates; therefore we always do a full
2841303Swesolows * update. If it becomes advantageous to limit updates to a single
2851303Swesolows * index, the contexts can be queued by the handler instead.
2861303Swesolows */
2871303Swesolows sunFmProblem_update_ctx_t uc;
2881303Swesolows
2891303Swesolows uc.uc_host = NULL;
2901303Swesolows uc.uc_prog = FMD_ADM_PROGRAM;
2911303Swesolows uc.uc_version = FMD_ADM_VERSION;
2921303Swesolows
2931303Swesolows uc.uc_index = NULL;
2941303Swesolows uc.uc_type = UCT_ALL;
2951303Swesolows
2961303Swesolows for (;;) {
2971303Swesolows (void) pthread_mutex_lock(&update_lock);
2981303Swesolows update_status = US_QUIET;
2991303Swesolows while (update_status == US_QUIET)
3001303Swesolows (void) pthread_cond_wait(&update_cv, &update_lock);
3011303Swesolows update_status = US_INPROGRESS;
3021303Swesolows (void) pthread_mutex_unlock(&update_lock);
3031303Swesolows (void) problem_update(&uc);
3041303Swesolows }
3051303Swesolows }
3061303Swesolows
3071303Swesolows static void
request_update(void)3081303Swesolows request_update(void)
3091303Swesolows {
3101303Swesolows (void) pthread_mutex_lock(&update_lock);
3111303Swesolows if (update_status != US_QUIET) {
3121303Swesolows (void) pthread_mutex_unlock(&update_lock);
3131303Swesolows return;
3141303Swesolows }
3151303Swesolows update_status = US_NEEDED;
3161303Swesolows (void) pthread_cond_signal(&update_cv);
3171303Swesolows (void) pthread_mutex_unlock(&update_lock);
3181303Swesolows }
3191303Swesolows
3201303Swesolows /*ARGSUSED*/
3211303Swesolows static int
problem_compare_uuid(const void * l,const void * r,void * private)3221303Swesolows problem_compare_uuid(const void *l, const void *r, void *private)
3231303Swesolows {
3241303Swesolows sunFmProblem_data_t *l_data = (sunFmProblem_data_t *)l;
3251303Swesolows sunFmProblem_data_t *r_data = (sunFmProblem_data_t *)r;
3261303Swesolows
3271303Swesolows ASSERT(l_data != NULL && r_data != NULL);
3281303Swesolows
3291303Swesolows return (strcmp(l_data->d_aci_uuid, r_data->d_aci_uuid));
3301303Swesolows }
3311303Swesolows
3321303Swesolows int
sunFmProblemTable_init(void)3331303Swesolows sunFmProblemTable_init(void)
3341303Swesolows {
3351303Swesolows static oid sunFmProblemTable_oid[] = { SUNFMPROBLEMTABLE_OID };
3361303Swesolows netsnmp_table_registration_info *table_info;
3371303Swesolows netsnmp_handler_registration *handler;
3381303Swesolows int err;
3391303Swesolows
3401303Swesolows if ((err = pthread_mutex_init(&update_lock, NULL)) != 0) {
341*11050SRobert.Johnston@Sun.COM (void) snmp_log(LOG_ERR, MODNAME_STR ": mutex_init failure: "
342*11050SRobert.Johnston@Sun.COM "%s\n", strerror(err));
3431303Swesolows return (MIB_REGISTRATION_FAILED);
3441303Swesolows }
3451303Swesolows if ((err = pthread_cond_init(&update_cv, NULL)) != 0) {
346*11050SRobert.Johnston@Sun.COM (void) snmp_log(LOG_ERR, MODNAME_STR ": cond_init failure: "
347*11050SRobert.Johnston@Sun.COM "%s\n", strerror(err));
3481303Swesolows return (MIB_REGISTRATION_FAILED);
3491303Swesolows }
3501303Swesolows
3511303Swesolows if ((err = pthread_create(NULL, NULL, (void *(*)(void *))update_thread,
3521303Swesolows NULL)) != 0) {
353*11050SRobert.Johnston@Sun.COM (void) snmp_log(LOG_ERR, MODNAME_STR ": error creating update "
3541303Swesolows "thread: %s\n", strerror(err));
3551303Swesolows return (MIB_REGISTRATION_FAILED);
3561303Swesolows }
3571303Swesolows
3581303Swesolows if ((table_info =
3591303Swesolows SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info)) == NULL)
3601303Swesolows return (MIB_REGISTRATION_FAILED);
3611303Swesolows
3621303Swesolows if ((handler = netsnmp_create_handler_registration("sunFmProblemTable",
3631303Swesolows sunFmProblemTable_handler, sunFmProblemTable_oid,
3641303Swesolows OID_LENGTH(sunFmProblemTable_oid), HANDLER_CAN_RONLY)) == NULL) {
3651303Swesolows SNMP_FREE(table_info);
3661303Swesolows return (MIB_REGISTRATION_FAILED);
3671303Swesolows }
3681303Swesolows
3691303Swesolows /*
3701303Swesolows * The Net-SNMP template uses add_indexes here, but that
3711303Swesolows * function is unsafe because it does not check for failure.
3721303Swesolows */
3731303Swesolows if (netsnmp_table_helper_add_index(table_info, ASN_OCTET_STR) == NULL) {
3741303Swesolows SNMP_FREE(table_info);
3751303Swesolows SNMP_FREE(handler);
3761303Swesolows return (MIB_REGISTRATION_FAILED);
3771303Swesolows }
3781303Swesolows
3791303Swesolows table_info->min_column = SUNFMPROBLEM_COLMIN;
3801303Swesolows table_info->max_column = SUNFMPROBLEM_COLMAX;
3811303Swesolows
3821303Swesolows if ((problem_uuid_avl_pool = uu_avl_pool_create("problem_uuid",
3831303Swesolows sizeof (sunFmProblem_data_t),
3841303Swesolows offsetof(sunFmProblem_data_t, d_uuid_avl), problem_compare_uuid,
3851303Swesolows UU_AVL_DEBUG)) == NULL) {
386*11050SRobert.Johnston@Sun.COM (void) snmp_log(LOG_ERR, MODNAME_STR ": problem_uuid avl pool "
3871303Swesolows "creation failed: %s\n", uu_strerror(uu_error()));
3881303Swesolows snmp_free_varbind(table_info->indexes);
3891303Swesolows SNMP_FREE(table_info);
3901303Swesolows SNMP_FREE(handler);
3911303Swesolows return (MIB_REGISTRATION_FAILED);
3921303Swesolows }
3931303Swesolows
3941303Swesolows if ((problem_uuid_avl = uu_avl_create(problem_uuid_avl_pool, NULL,
3951303Swesolows UU_AVL_DEBUG)) == NULL) {
396*11050SRobert.Johnston@Sun.COM (void) snmp_log(LOG_ERR, MODNAME_STR ": problem_uuid avl "
397*11050SRobert.Johnston@Sun.COM "creation failed: %s\n", uu_strerror(uu_error()));
3981303Swesolows snmp_free_varbind(table_info->indexes);
3991303Swesolows SNMP_FREE(table_info);
4001303Swesolows SNMP_FREE(handler);
4011303Swesolows uu_avl_pool_destroy(problem_uuid_avl_pool);
4021303Swesolows return (MIB_REGISTRATION_FAILED);
4031303Swesolows }
4041303Swesolows
4051303Swesolows if ((err = netsnmp_register_table(handler, table_info)) !=
4061303Swesolows MIB_REGISTERED_OK) {
4071303Swesolows snmp_free_varbind(table_info->indexes);
4081303Swesolows SNMP_FREE(table_info);
4091303Swesolows SNMP_FREE(handler);
4101303Swesolows uu_avl_destroy(problem_uuid_avl);
4111303Swesolows uu_avl_pool_destroy(problem_uuid_avl_pool);
4121303Swesolows return (err);
4131303Swesolows }
4141303Swesolows
4151303Swesolows return (MIB_REGISTERED_OK);
4161303Swesolows }
4171303Swesolows
4181303Swesolows int
sunFmFaultEventTable_init(void)4191303Swesolows sunFmFaultEventTable_init(void)
4201303Swesolows {
4211303Swesolows static oid sunFmFaultEventTable_oid[] = { SUNFMFAULTEVENTTABLE_OID };
4221303Swesolows netsnmp_table_registration_info *table_info;
4231303Swesolows netsnmp_handler_registration *handler;
4241303Swesolows int err;
4251303Swesolows
4261303Swesolows if ((table_info =
4271303Swesolows SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info)) == NULL)
4281303Swesolows return (MIB_REGISTRATION_FAILED);
4291303Swesolows
4301303Swesolows if ((handler =
4311303Swesolows netsnmp_create_handler_registration("sunFmFaultEventTable",
4321303Swesolows sunFmFaultEventTable_handler, sunFmFaultEventTable_oid,
4331303Swesolows OID_LENGTH(sunFmFaultEventTable_oid), HANDLER_CAN_RONLY)) == NULL) {
4341303Swesolows SNMP_FREE(table_info);
4351303Swesolows return (MIB_REGISTRATION_FAILED);
4361303Swesolows }
4371303Swesolows
4381303Swesolows /*
4391303Swesolows * The Net-SNMP template uses add_indexes here, but that
4401303Swesolows * function is unsafe because it does not check for failure.
4411303Swesolows */
4421303Swesolows if (netsnmp_table_helper_add_index(table_info, ASN_OCTET_STR) == NULL) {
4431303Swesolows SNMP_FREE(table_info);
4441303Swesolows SNMP_FREE(handler);
4451303Swesolows return (MIB_REGISTRATION_FAILED);
4461303Swesolows }
4471303Swesolows if (netsnmp_table_helper_add_index(table_info, ASN_UNSIGNED) == NULL) {
4481303Swesolows snmp_free_varbind(table_info->indexes);
4491303Swesolows SNMP_FREE(table_info);
4501303Swesolows SNMP_FREE(handler);
4511303Swesolows return (MIB_REGISTRATION_FAILED);
4521303Swesolows }
4531303Swesolows
4541303Swesolows table_info->min_column = SUNFMFAULTEVENT_COLMIN;
4551303Swesolows table_info->max_column = SUNFMFAULTEVENT_COLMAX;
4561303Swesolows
4571303Swesolows if ((err = netsnmp_register_table(handler, table_info)) !=
4581303Swesolows MIB_REGISTERED_OK) {
4591303Swesolows snmp_free_varbind(table_info->indexes);
4601303Swesolows SNMP_FREE(table_info);
4611303Swesolows SNMP_FREE(handler);
4621303Swesolows return (err);
4631303Swesolows }
4641303Swesolows
4651303Swesolows return (MIB_REGISTERED_OK);
4661303Swesolows }
4671303Swesolows
4681303Swesolows /*
4691303Swesolows * Returns the problem data for the problem whose uuid is next according
4701303Swesolows * to ASN.1 lexical ordering after the request in table_info. Indexes are
4711303Swesolows * updated to reflect the OID of the value being returned. This allows
4721303Swesolows * us to implement GETNEXT.
4731303Swesolows */
4741303Swesolows static sunFmProblem_data_t *
sunFmProblemTable_nextpr(netsnmp_handler_registration * reginfo,netsnmp_table_request_info * table_info)4751303Swesolows sunFmProblemTable_nextpr(netsnmp_handler_registration *reginfo,
4761303Swesolows netsnmp_table_request_info *table_info)
4771303Swesolows {
4781303Swesolows sunFmProblem_data_t *data;
4791303Swesolows char *uuid = "";
4801303Swesolows
4811303Swesolows if (table_info->number_indexes < 1) {
4821303Swesolows oid tmpoid[MAX_OID_LEN];
4831303Swesolows
4841303Swesolows DEBUGMSGTL((MODNAME_STR, "nextpr: no indexes given\n"));
4851303Swesolows
4862134Swesolows snmp_free_varbind(table_info->indexes);
4871303Swesolows table_info->indexes =
4881303Swesolows SNMP_MALLOC_TYPEDEF(netsnmp_variable_list);
489*11050SRobert.Johnston@Sun.COM (void) snmp_set_var_typed_value(table_info->indexes,
490*11050SRobert.Johnston@Sun.COM ASN_OCTET_STR, (const uchar_t *)uuid, 0);
4912134Swesolows (void) memcpy(tmpoid, reginfo->rootoid,
4921303Swesolows reginfo->rootoid_len * sizeof (oid));
4931303Swesolows tmpoid[reginfo->rootoid_len] = 1;
4941303Swesolows tmpoid[reginfo->rootoid_len + 1] = table_info->colnum;
4951303Swesolows if (build_oid_segment(table_info->indexes) != SNMPERR_SUCCESS) {
4961303Swesolows snmp_free_varbind(table_info->indexes);
4971303Swesolows return (NULL);
4981303Swesolows }
4991303Swesolows table_info->number_indexes = 1;
5001303Swesolows table_info->index_oid_len = table_info->indexes->name_length;
5012134Swesolows (void) memcpy(table_info->index_oid, table_info->indexes->name,
5021303Swesolows table_info->indexes->name_length);
5031303Swesolows
5041303Swesolows DEBUGMSGTL((MODNAME_STR, "nextpr: built fake index:\n"));
5051303Swesolows DEBUGMSGVAR((MODNAME_STR, table_info->indexes));
5061303Swesolows DEBUGMSG((MODNAME_STR, "\n"));
5071303Swesolows } else {
5081303Swesolows /*
5091303Swesolows * Construct the next possible UUID to look for. We can
5101303Swesolows * simply increment the least significant byte of the last
5111303Swesolows * UUID because (a) that preserves SNMP lex order and (b)
5121303Swesolows * the characters that may appear in a UUID do not include
5131303Swesolows * 127 nor 255.
5141303Swesolows */
5151303Swesolows uuid = alloca(table_info->indexes->val_len + 1);
5161303Swesolows (void) strlcpy(uuid,
5171303Swesolows (const char *)table_info->indexes->val.string,
5181303Swesolows table_info->indexes->val_len + 1);
5191303Swesolows ++uuid[table_info->indexes->val_len - 1];
5201303Swesolows
5211303Swesolows DEBUGMSGTL((MODNAME_STR, "nextpr: received index:\n"));
5221303Swesolows DEBUGMSGVAR((MODNAME_STR, table_info->indexes));
5231303Swesolows DEBUGMSG((MODNAME_STR, "\n"));
5241303Swesolows }
5251303Swesolows
5261303Swesolows if ((data = problem_lookup_uuid_next(uuid)) == NULL) {
5271303Swesolows DEBUGMSGTL((MODNAME_STR, "nextpr: next match not found for "
5281303Swesolows "%s; trying next column\n", uuid));
5292134Swesolows if (table_info->colnum >=
5302134Swesolows netsnmp_find_table_registration_info(reginfo)->max_column) {
5311303Swesolows snmp_free_varbind(table_info->indexes);
5321303Swesolows table_info->indexes = NULL;
5331303Swesolows table_info->number_indexes = 0;
5341303Swesolows DEBUGMSGTL((MODNAME_STR, "nextpr: out of columns\n"));
5351303Swesolows return (NULL);
5361303Swesolows }
5371303Swesolows table_info->colnum++;
5381303Swesolows DEBUGMSGTL((MODNAME_STR, "nextpr: search for col %u empty "
5391303Swesolows "uuid\n", table_info->colnum, uuid));
5401303Swesolows
5411303Swesolows if ((data = problem_lookup_uuid_next("")) == NULL) {
5421303Swesolows DEBUGMSGTL((MODNAME_STR, "nextpr: next match not found "
5431303Swesolows "for empty uuid; stopping\n"));
5441303Swesolows snmp_free_varbind(table_info->indexes);
5451303Swesolows table_info->indexes = NULL;
5461303Swesolows table_info->number_indexes = 0;
5471303Swesolows return (NULL);
5481303Swesolows }
5491303Swesolows }
5501303Swesolows
551*11050SRobert.Johnston@Sun.COM (void) snmp_set_var_typed_value(table_info->indexes, ASN_OCTET_STR,
5521303Swesolows (uchar_t *)data->d_aci_uuid, strlen(data->d_aci_uuid));
5531303Swesolows table_info->number_indexes = 1;
5541303Swesolows
5551303Swesolows DEBUGMSGTL((MODNAME_STR, "matching data is %s@%p\n", data->d_aci_uuid,
5561303Swesolows data));
5571303Swesolows
5581303Swesolows return (data);
5591303Swesolows }
5601303Swesolows
5611303Swesolows /*
5621303Swesolows * Returns the problem data corresponding to the request in table_info.
5631303Swesolows * All request parameters are unmodified.
5641303Swesolows */
5652134Swesolows /*ARGSUSED*/
5661303Swesolows static sunFmProblem_data_t *
sunFmProblemTable_pr(netsnmp_handler_registration * reginfo,netsnmp_table_request_info * table_info)5671303Swesolows sunFmProblemTable_pr(netsnmp_handler_registration *reginfo,
5681303Swesolows netsnmp_table_request_info *table_info)
5691303Swesolows {
5701303Swesolows char *uuid;
5711303Swesolows
5721303Swesolows ASSERT(table_info->number_indexes >= 1);
5731303Swesolows
5741303Swesolows uuid = alloca(table_info->indexes->val_len + 1);
5751303Swesolows (void) strlcpy(uuid, (const char *)table_info->indexes->val.string,
5761303Swesolows table_info->indexes->val_len + 1);
5771303Swesolows
5781303Swesolows return (problem_lookup_uuid_exact(uuid));
5791303Swesolows }
5801303Swesolows
5811303Swesolows /*
5821303Swesolows * Returns the ASN.1 lexicographically first fault event after the one
5831303Swesolows * identified by table_info. Indexes are updated to reflect the OID
5841303Swesolows * of the data returned. This allows us to implement GETNEXT.
5851303Swesolows */
5861303Swesolows static sunFmFaultEvent_data_t *
sunFmFaultEventTable_nextfe(netsnmp_handler_registration * reginfo,netsnmp_table_request_info * table_info,sunFmFaultStatus_data_t * statusp)5871303Swesolows sunFmFaultEventTable_nextfe(netsnmp_handler_registration *reginfo,
5887288Sstephh netsnmp_table_request_info *table_info, sunFmFaultStatus_data_t *statusp)
5891303Swesolows {
5901303Swesolows sunFmProblem_data_t *data;
5911303Swesolows sunFmFaultEvent_data_t *rv;
5921303Swesolows netsnmp_variable_list *var;
5931303Swesolows ulong_t index;
5941303Swesolows
5951303Swesolows for (;;) {
5961303Swesolows switch (table_info->number_indexes) {
5971303Swesolows case 2:
5981303Swesolows default:
5991303Swesolows DEBUGMSGTL((MODNAME_STR, "nextfe: 2 indices:\n"));
6001303Swesolows DEBUGMSGVAR((MODNAME_STR, table_info->indexes));
6011303Swesolows DEBUGMSG((MODNAME_STR, "\n"));
6021303Swesolows DEBUGMSGVAR((MODNAME_STR,
6031303Swesolows table_info->indexes->next_variable));
6041303Swesolows DEBUGMSG((MODNAME_STR, "\n"));
6051303Swesolows index = *(ulong_t *)
6061303Swesolows table_info->indexes->next_variable->val.integer + 1;
6071303Swesolows
6081303Swesolows if ((data = sunFmProblemTable_pr(reginfo,
6091303Swesolows table_info)) != NULL &&
6107288Sstephh (*statusp = faultstatus_lookup_index_exact(data,
6117288Sstephh index)) != 0 &&
6121303Swesolows (rv = faultevent_lookup_index_exact(data, index)) !=
6131303Swesolows NULL) {
614*11050SRobert.Johnston@Sun.COM (void) snmp_set_var_typed_value(
6151303Swesolows table_info->indexes->next_variable,
6161303Swesolows ASN_UNSIGNED, (uchar_t *)&index,
6171303Swesolows sizeof (index));
6181303Swesolows return (rv);
6191303Swesolows }
6201303Swesolows
6211303Swesolows if (sunFmProblemTable_nextpr(reginfo, table_info) ==
6221303Swesolows NULL)
6231303Swesolows return (NULL);
6241303Swesolows break;
6251303Swesolows case 1:
6261303Swesolows if ((data = sunFmProblemTable_pr(reginfo,
6271303Swesolows table_info)) != NULL) {
6281303Swesolows oid tmpoid[MAX_OID_LEN];
6291303Swesolows index = 0;
6301303Swesolows
6311303Swesolows DEBUGMSGTL((MODNAME_STR, "nextfe: 1 index:\n"));
6321303Swesolows DEBUGMSGVAR((MODNAME_STR, table_info->indexes));
6331303Swesolows DEBUGMSG((MODNAME_STR, "\n"));
6341303Swesolows var =
6351303Swesolows SNMP_MALLOC_TYPEDEF(netsnmp_variable_list);
636*11050SRobert.Johnston@Sun.COM (void) snmp_set_var_typed_value(var,
637*11050SRobert.Johnston@Sun.COM ASN_UNSIGNED, (uchar_t *)&index,
638*11050SRobert.Johnston@Sun.COM sizeof (index));
6392134Swesolows (void) memcpy(tmpoid, reginfo->rootoid,
6401303Swesolows reginfo->rootoid_len * sizeof (oid));
6411303Swesolows tmpoid[reginfo->rootoid_len] = 1;
6421303Swesolows tmpoid[reginfo->rootoid_len + 1] =
6431303Swesolows table_info->colnum;
6441303Swesolows if (build_oid_segment(var) != SNMPERR_SUCCESS) {
6451303Swesolows snmp_free_varbind(var);
6461303Swesolows return (NULL);
6471303Swesolows }
6482134Swesolows snmp_free_varbind(
6492134Swesolows table_info->indexes->next_variable);
6501303Swesolows table_info->indexes->next_variable = var;
6511303Swesolows table_info->number_indexes = 2;
6521303Swesolows DEBUGMSGTL((MODNAME_STR, "nextfe: built fake "
6531303Swesolows "index:\n"));
6541303Swesolows DEBUGMSGVAR((MODNAME_STR, table_info->indexes));
6551303Swesolows DEBUGMSG((MODNAME_STR, "\n"));
6561303Swesolows DEBUGMSGVAR((MODNAME_STR,
6571303Swesolows table_info->indexes->next_variable));
6581303Swesolows DEBUGMSG((MODNAME_STR, "\n"));
6591303Swesolows } else {
6601303Swesolows if (sunFmProblemTable_nextpr(reginfo,
6611303Swesolows table_info) == NULL)
6621303Swesolows return (NULL);
6631303Swesolows }
6641303Swesolows break;
6651303Swesolows case 0:
6661303Swesolows if (sunFmProblemTable_nextpr(reginfo, table_info) ==
6671303Swesolows NULL)
6681303Swesolows return (NULL);
6691303Swesolows break;
6701303Swesolows }
6711303Swesolows }
6721303Swesolows }
6731303Swesolows
6741303Swesolows static sunFmFaultEvent_data_t *
sunFmFaultEventTable_fe(netsnmp_handler_registration * reginfo,netsnmp_table_request_info * table_info,sunFmFaultStatus_data_t * statusp)6751303Swesolows sunFmFaultEventTable_fe(netsnmp_handler_registration *reginfo,
6767288Sstephh netsnmp_table_request_info *table_info, sunFmFaultStatus_data_t *statusp)
6771303Swesolows {
6781303Swesolows sunFmProblem_data_t *data;
6791303Swesolows
6801303Swesolows ASSERT(table_info->number_indexes == 2);
6811303Swesolows
6821303Swesolows if ((data = sunFmProblemTable_pr(reginfo, table_info)) == NULL)
6831303Swesolows return (NULL);
6841303Swesolows
6857288Sstephh *statusp = faultstatus_lookup_index_exact(data,
6867288Sstephh *(ulong_t *)table_info->indexes->next_variable->val.integer);
6877288Sstephh if (*statusp == 0)
6887288Sstephh return (NULL);
6891303Swesolows return (faultevent_lookup_index_exact(data,
6901303Swesolows *(ulong_t *)table_info->indexes->next_variable->val.integer));
6911303Swesolows }
6921303Swesolows
6932134Swesolows /*ARGSUSED*/
6941303Swesolows static void
sunFmProblemTable_return(unsigned int reg,void * arg)6951303Swesolows sunFmProblemTable_return(unsigned int reg, void *arg)
6961303Swesolows {
6971303Swesolows netsnmp_delegated_cache *cache = (netsnmp_delegated_cache *)arg;
6981303Swesolows netsnmp_request_info *request;
6991303Swesolows netsnmp_agent_request_info *reqinfo;
7001303Swesolows netsnmp_handler_registration *reginfo;
7011303Swesolows netsnmp_table_request_info *table_info;
7021303Swesolows sunFmProblem_data_t *data;
7031303Swesolows
7041303Swesolows ASSERT(netsnmp_handler_check_cache(cache) != NULL);
7051303Swesolows
7061303Swesolows (void) pthread_mutex_lock(&update_lock);
7071303Swesolows if (update_status != US_QUIET) {
7081303Swesolows struct timeval tv;
7091303Swesolows
7101303Swesolows tv.tv_sec = UPDATE_WAIT_MILLIS / 1000;
7111303Swesolows tv.tv_usec = (UPDATE_WAIT_MILLIS % 1000) * 1000;
7121303Swesolows
7131303Swesolows (void) snmp_alarm_register_hr(tv, 0, sunFmProblemTable_return,
7141303Swesolows cache);
7151303Swesolows (void) pthread_mutex_unlock(&update_lock);
7161303Swesolows return;
7171303Swesolows }
7181303Swesolows
7191303Swesolows request = cache->requests;
7201303Swesolows reqinfo = cache->reqinfo;
7211303Swesolows reginfo = cache->reginfo;
7221303Swesolows
7231303Swesolows table_info = netsnmp_extract_table_info(request);
7241303Swesolows request->delegated = 0;
7251303Swesolows
7261303Swesolows ASSERT(table_info->colnum >= SUNFMPROBLEM_COLMIN);
7271303Swesolows ASSERT(table_info->colnum <= SUNFMPROBLEM_COLMAX);
7281303Swesolows
7291303Swesolows /*
7301303Swesolows * table_info->colnum contains the column number requested.
7311303Swesolows * table_info->indexes contains a linked list of snmp variable
7321303Swesolows * bindings for the indexes of the table. Values in the list
7331303Swesolows * have been set corresponding to the indexes of the
7341303Swesolows * request. We have other guarantees as well:
7351303Swesolows *
7361303Swesolows * - The column number is always within range.
7371303Swesolows * - If we have no index data, table_info->index_oid_len is 0.
7381303Swesolows * - We will never receive requests outside our table nor
7391303Swesolows * those with the first subid anything other than 1 (Entry)
7401303Swesolows * nor those without a column number. This is true even
7411303Swesolows * for GETNEXT requests.
7421303Swesolows */
7431303Swesolows
7441303Swesolows switch (reqinfo->mode) {
7451303Swesolows case MODE_GET:
7461303Swesolows if ((data = sunFmProblemTable_pr(reginfo, table_info)) ==
7471303Swesolows NULL) {
7481303Swesolows netsnmp_free_delegated_cache(cache);
7491303Swesolows (void) pthread_mutex_unlock(&update_lock);
7501303Swesolows return;
7511303Swesolows }
7521303Swesolows break;
7531303Swesolows case MODE_GETNEXT:
7541303Swesolows case MODE_GETBULK:
7551303Swesolows if ((data = sunFmProblemTable_nextpr(reginfo, table_info)) ==
7561303Swesolows NULL) {
7571303Swesolows netsnmp_free_delegated_cache(cache);
7581303Swesolows (void) pthread_mutex_unlock(&update_lock);
7591303Swesolows return;
7601303Swesolows }
7611303Swesolows break;
7621303Swesolows default:
763*11050SRobert.Johnston@Sun.COM (void) snmp_log(LOG_ERR, MODNAME_STR ": Unsupported request "
764*11050SRobert.Johnston@Sun.COM "mode %d\n", reqinfo->mode);
7651303Swesolows netsnmp_free_delegated_cache(cache);
7661303Swesolows (void) pthread_mutex_unlock(&update_lock);
7671303Swesolows return;
7681303Swesolows }
7691303Swesolows
7701303Swesolows switch (table_info->colnum) {
7711303Swesolows case SUNFMPROBLEM_COL_UUID:
7721303Swesolows {
773*11050SRobert.Johnston@Sun.COM (void) netsnmp_table_build_result(reginfo, request, table_info,
7741303Swesolows ASN_OCTET_STR, (uchar_t *)data->d_aci_uuid,
7751303Swesolows strlen(data->d_aci_uuid));
7761303Swesolows break;
7771303Swesolows }
7781303Swesolows case SUNFMPROBLEM_COL_CODE:
7791303Swesolows {
780*11050SRobert.Johnston@Sun.COM (void) netsnmp_table_build_result(reginfo, request, table_info,
7811303Swesolows ASN_OCTET_STR, (uchar_t *)data->d_aci_code,
7821303Swesolows strlen(data->d_aci_code));
7831303Swesolows break;
7841303Swesolows }
7851303Swesolows case SUNFMPROBLEM_COL_URL:
7861303Swesolows {
787*11050SRobert.Johnston@Sun.COM (void) netsnmp_table_build_result(reginfo, request, table_info,
7881303Swesolows ASN_OCTET_STR, (uchar_t *)data->d_aci_url,
7891303Swesolows strlen(data->d_aci_url));
7901303Swesolows break;
7911303Swesolows }
7921303Swesolows case SUNFMPROBLEM_COL_DIAGENGINE:
7931303Swesolows {
794*11050SRobert.Johnston@Sun.COM (void) netsnmp_table_build_result(reginfo, request, table_info,
7951303Swesolows ASN_OCTET_STR, (uchar_t *)data->d_diag_engine,
7961303Swesolows strlen(data->d_diag_engine));
7971303Swesolows break;
7981303Swesolows }
7991303Swesolows case SUNFMPROBLEM_COL_DIAGTIME:
8001303Swesolows {
8011303Swesolows /*
8021303Swesolows * The date_n_time function is not Y2038-safe; this may
8031303Swesolows * need to be updated when a suitable Y2038-safe Net-SNMP
8041303Swesolows * API is available.
8051303Swesolows */
8061303Swesolows size_t dt_size;
8071303Swesolows time_t dt_time = (time_t)data->d_diag_time.tv_sec;
8081303Swesolows uchar_t *dt = date_n_time(&dt_time, &dt_size);
8091303Swesolows
810*11050SRobert.Johnston@Sun.COM (void) netsnmp_table_build_result(reginfo, request, table_info,
8111303Swesolows ASN_OCTET_STR, dt, dt_size);
8121303Swesolows break;
8131303Swesolows }
8141303Swesolows case SUNFMPROBLEM_COL_SUSPECTCOUNT:
8151303Swesolows {
816*11050SRobert.Johnston@Sun.COM (void) netsnmp_table_build_result(reginfo, request, table_info,
8171303Swesolows ASN_UNSIGNED, (uchar_t *)&data->d_nsuspects,
8181303Swesolows sizeof (data->d_nsuspects));
8191303Swesolows break;
8201303Swesolows }
8211303Swesolows default:
8221303Swesolows break;
8231303Swesolows }
8241303Swesolows
8251303Swesolows netsnmp_free_delegated_cache(cache);
8261303Swesolows (void) pthread_mutex_unlock(&update_lock);
8271303Swesolows }
8281303Swesolows
8291303Swesolows static int
sunFmProblemTable_handler(netsnmp_mib_handler * handler,netsnmp_handler_registration * reginfo,netsnmp_agent_request_info * reqinfo,netsnmp_request_info * requests)8301303Swesolows sunFmProblemTable_handler(netsnmp_mib_handler *handler,
8311303Swesolows netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo,
8321303Swesolows netsnmp_request_info *requests)
8331303Swesolows {
8341303Swesolows netsnmp_request_info *request;
8351303Swesolows struct timeval tv;
8361303Swesolows
8371303Swesolows tv.tv_sec = UPDATE_WAIT_MILLIS / 1000;
8381303Swesolows tv.tv_usec = (UPDATE_WAIT_MILLIS % 1000) * 1000;
8391303Swesolows
8401303Swesolows request_update();
8411303Swesolows
8421303Swesolows for (request = requests; request; request = request->next) {
8431303Swesolows if (request->processed != 0)
8441303Swesolows continue;
8451303Swesolows
8461303Swesolows if (netsnmp_extract_table_info(request) == NULL)
8471303Swesolows continue;
8481303Swesolows
8491303Swesolows request->delegated = 1;
8501303Swesolows (void) snmp_alarm_register_hr(tv, 0,
8511303Swesolows sunFmProblemTable_return,
8521303Swesolows (void *) netsnmp_create_delegated_cache(handler, reginfo,
8531303Swesolows reqinfo, request, NULL));
8541303Swesolows }
8551303Swesolows
8561303Swesolows return (SNMP_ERR_NOERROR);
8571303Swesolows }
8581303Swesolows
8592134Swesolows /*ARGSUSED*/
8601303Swesolows static void
sunFmFaultEventTable_return(unsigned int reg,void * arg)8611303Swesolows sunFmFaultEventTable_return(unsigned int reg, void *arg)
8621303Swesolows {
8631303Swesolows netsnmp_delegated_cache *cache = (netsnmp_delegated_cache *)arg;
8641303Swesolows netsnmp_request_info *request;
8651303Swesolows netsnmp_agent_request_info *reqinfo;
8661303Swesolows netsnmp_handler_registration *reginfo;
8671303Swesolows netsnmp_table_request_info *table_info;
8681303Swesolows sunFmProblem_data_t *pdata;
8691303Swesolows sunFmFaultEvent_data_t *data;
8707275Sstephh sunFmFaultStatus_data_t status;
8711303Swesolows
8721303Swesolows ASSERT(netsnmp_handler_check_cache(cache) != NULL);
8731303Swesolows
8741303Swesolows (void) pthread_mutex_lock(&update_lock);
8751303Swesolows if (update_status != US_QUIET) {
8761303Swesolows struct timeval tv;
8771303Swesolows
8781303Swesolows tv.tv_sec = UPDATE_WAIT_MILLIS / 1000;
8791303Swesolows tv.tv_usec = (UPDATE_WAIT_MILLIS % 1000) * 1000;
8801303Swesolows
8811303Swesolows (void) snmp_alarm_register_hr(tv, 0,
8821303Swesolows sunFmFaultEventTable_return, cache);
8831303Swesolows (void) pthread_mutex_unlock(&update_lock);
8841303Swesolows return;
8851303Swesolows }
8861303Swesolows
8871303Swesolows request = cache->requests;
8881303Swesolows reqinfo = cache->reqinfo;
8891303Swesolows reginfo = cache->reginfo;
8901303Swesolows
8911303Swesolows table_info = netsnmp_extract_table_info(request);
8921303Swesolows request->delegated = 0;
8931303Swesolows
8941303Swesolows ASSERT(table_info->colnum >= SUNFMFAULTEVENT_COLMIN);
8951303Swesolows ASSERT(table_info->colnum <= SUNFMFAULTEVENT_COLMAX);
8961303Swesolows
8971303Swesolows /*
8981303Swesolows * table_info->colnum contains the column number requested.
8991303Swesolows * table_info->indexes contains a linked list of snmp variable
9001303Swesolows * bindings for the indexes of the table. Values in the list
9011303Swesolows * have been set corresponding to the indexes of the
9021303Swesolows * request. We have other guarantees as well:
9031303Swesolows *
9041303Swesolows * - The column number is always within range.
9051303Swesolows * - If we have no index data, table_info->index_oid_len is 0.
9061303Swesolows * - We will never receive requests outside our table nor
9071303Swesolows * those with the first subid anything other than 1 (Entry)
9081303Swesolows * nor those without a column number. This is true even
9091303Swesolows * for GETNEXT requests.
9101303Swesolows */
9111303Swesolows
9127288Sstephh switch (reqinfo->mode) {
9137288Sstephh case MODE_GET:
9147288Sstephh if ((data = sunFmFaultEventTable_fe(reginfo, table_info,
9157288Sstephh &status)) == NULL) {
9161303Swesolows netsnmp_free_delegated_cache(cache);
9171303Swesolows (void) pthread_mutex_unlock(&update_lock);
9181303Swesolows return;
9191303Swesolows }
9207288Sstephh break;
9217288Sstephh case MODE_GETNEXT:
9227288Sstephh case MODE_GETBULK:
9237288Sstephh if ((data = sunFmFaultEventTable_nextfe(reginfo, table_info,
9247288Sstephh &status)) == NULL) {
9251303Swesolows netsnmp_free_delegated_cache(cache);
9261303Swesolows (void) pthread_mutex_unlock(&update_lock);
9271303Swesolows return;
9281303Swesolows }
9297288Sstephh break;
9307288Sstephh default:
931*11050SRobert.Johnston@Sun.COM (void) snmp_log(LOG_ERR, MODNAME_STR ": Unsupported request "
932*11050SRobert.Johnston@Sun.COM "mode %d\n", reqinfo->mode);
9337288Sstephh netsnmp_free_delegated_cache(cache);
9347288Sstephh (void) pthread_mutex_unlock(&update_lock);
9357288Sstephh return;
9361303Swesolows }
9371303Swesolows
9381303Swesolows switch (table_info->colnum) {
9391303Swesolows case SUNFMFAULTEVENT_COL_PROBLEMUUID:
9401303Swesolows {
9411303Swesolows if ((pdata = sunFmProblemTable_pr(reginfo, table_info))
9421303Swesolows == NULL) {
943*11050SRobert.Johnston@Sun.COM (void) netsnmp_table_build_result(reginfo, request,
944*11050SRobert.Johnston@Sun.COM table_info, ASN_OCTET_STR, NULL, 0);
9451303Swesolows break;
9461303Swesolows }
947*11050SRobert.Johnston@Sun.COM (void) netsnmp_table_build_result(reginfo, request, table_info,
9481303Swesolows ASN_OCTET_STR, (uchar_t *)pdata->d_aci_uuid,
9491303Swesolows strlen(pdata->d_aci_uuid));
9501303Swesolows break;
9511303Swesolows }
9521303Swesolows case SUNFMFAULTEVENT_COL_CLASS:
9531303Swesolows {
9541303Swesolows char *class = "-";
9551303Swesolows
9561303Swesolows (void) nvlist_lookup_string(data, FM_CLASS, &class);
957*11050SRobert.Johnston@Sun.COM (void) netsnmp_table_build_result(reginfo, request, table_info,
9581303Swesolows ASN_OCTET_STR, (uchar_t *)class, strlen(class));
9591303Swesolows break;
9601303Swesolows }
9611303Swesolows case SUNFMFAULTEVENT_COL_CERTAINTY:
9621303Swesolows {
9631303Swesolows uint8_t pct = 0;
9641303Swesolows ulong_t pl;
9651303Swesolows
9661303Swesolows (void) nvlist_lookup_uint8(data, FM_FAULT_CERTAINTY,
9671303Swesolows &pct);
9681303Swesolows pl = (ulong_t)pct;
969*11050SRobert.Johnston@Sun.COM (void) netsnmp_table_build_result(reginfo, request, table_info,
9701303Swesolows ASN_UNSIGNED, (uchar_t *)&pl, sizeof (pl));
9711303Swesolows break;
9721303Swesolows }
9731303Swesolows case SUNFMFAULTEVENT_COL_ASRU:
9741303Swesolows {
9751303Swesolows nvlist_t *asru = NULL;
9762134Swesolows char *fmri, *str;
9771303Swesolows
9781303Swesolows (void) nvlist_lookup_nvlist(data, FM_FAULT_ASRU, &asru);
9792134Swesolows if ((str = sunFm_nvl2str(asru)) == NULL)
9801303Swesolows fmri = "-";
9812134Swesolows else
9822134Swesolows fmri = str;
9832134Swesolows
984*11050SRobert.Johnston@Sun.COM (void) netsnmp_table_build_result(reginfo, request, table_info,
9851303Swesolows ASN_OCTET_STR, (uchar_t *)fmri, strlen(fmri));
9862134Swesolows free(str);
9871303Swesolows break;
9881303Swesolows }
9891303Swesolows case SUNFMFAULTEVENT_COL_FRU:
9901303Swesolows {
9911303Swesolows nvlist_t *fru = NULL;
9922134Swesolows char *fmri, *str;
9931303Swesolows
9941303Swesolows (void) nvlist_lookup_nvlist(data, FM_FAULT_FRU, &fru);
9952134Swesolows if ((str = sunFm_nvl2str(fru)) == NULL)
9961303Swesolows fmri = "-";
9972134Swesolows else
9982134Swesolows fmri = str;
9992134Swesolows
1000*11050SRobert.Johnston@Sun.COM (void) netsnmp_table_build_result(reginfo, request, table_info,
10011303Swesolows ASN_OCTET_STR, (uchar_t *)fmri, strlen(fmri));
10022134Swesolows free(str);
10031303Swesolows break;
10041303Swesolows }
10051303Swesolows case SUNFMFAULTEVENT_COL_RESOURCE:
10061303Swesolows {
10071303Swesolows nvlist_t *rsrc = NULL;
10082134Swesolows char *fmri, *str;
10091303Swesolows
10102134Swesolows (void) nvlist_lookup_nvlist(data, FM_FAULT_RESOURCE, &rsrc);
10112134Swesolows if ((str = sunFm_nvl2str(rsrc)) == NULL)
10121303Swesolows fmri = "-";
10132134Swesolows else
10142134Swesolows fmri = str;
10152134Swesolows
1016*11050SRobert.Johnston@Sun.COM (void) netsnmp_table_build_result(reginfo, request, table_info,
10171303Swesolows ASN_OCTET_STR, (uchar_t *)fmri, strlen(fmri));
10182134Swesolows free(str);
10191303Swesolows break;
10201303Swesolows }
10217275Sstephh case SUNFMFAULTEVENT_COL_STATUS:
10227275Sstephh {
10237288Sstephh ulong_t pl = SUNFMFAULTEVENT_STATE_OTHER;
10247275Sstephh
10257275Sstephh if (status & FM_SUSPECT_FAULTY)
10267275Sstephh pl = SUNFMFAULTEVENT_STATE_FAULTY;
10277275Sstephh else if (status & FM_SUSPECT_NOT_PRESENT)
10287275Sstephh pl = SUNFMFAULTEVENT_STATE_REMOVED;
10297275Sstephh else if (status & FM_SUSPECT_REPLACED)
10307275Sstephh pl = SUNFMFAULTEVENT_STATE_REPLACED;
10317275Sstephh else if (status & FM_SUSPECT_REPAIRED)
10327275Sstephh pl = SUNFMFAULTEVENT_STATE_REPAIRED;
10337275Sstephh else if (status & FM_SUSPECT_ACQUITTED)
10347275Sstephh pl = SUNFMFAULTEVENT_STATE_ACQUITTED;
1035*11050SRobert.Johnston@Sun.COM (void) netsnmp_table_build_result(reginfo, request, table_info,
10367288Sstephh ASN_INTEGER, (uchar_t *)&pl, sizeof (pl));
10377275Sstephh break;
10387275Sstephh }
10397275Sstephh case SUNFMFAULTEVENT_COL_LOCATION:
10407275Sstephh {
10417275Sstephh char *location = "-";
10427275Sstephh
10437275Sstephh (void) nvlist_lookup_string(data, FM_FAULT_LOCATION, &location);
1044*11050SRobert.Johnston@Sun.COM (void) netsnmp_table_build_result(reginfo, request, table_info,
10457275Sstephh ASN_OCTET_STR, (uchar_t *)location, strlen(location));
10467275Sstephh break;
10477275Sstephh }
10481303Swesolows default:
10491303Swesolows break;
10501303Swesolows }
10511303Swesolows
10521303Swesolows netsnmp_free_delegated_cache(cache);
10531303Swesolows (void) pthread_mutex_unlock(&update_lock);
10541303Swesolows }
10551303Swesolows
10561303Swesolows static int
sunFmFaultEventTable_handler(netsnmp_mib_handler * handler,netsnmp_handler_registration * reginfo,netsnmp_agent_request_info * reqinfo,netsnmp_request_info * requests)10571303Swesolows sunFmFaultEventTable_handler(netsnmp_mib_handler *handler,
10581303Swesolows netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo,
10591303Swesolows netsnmp_request_info *requests)
10601303Swesolows {
10611303Swesolows netsnmp_request_info *request;
10621303Swesolows struct timeval tv;
10631303Swesolows
10641303Swesolows tv.tv_sec = UPDATE_WAIT_MILLIS / 1000;
10651303Swesolows tv.tv_usec = (UPDATE_WAIT_MILLIS % 1000) * 1000;
10661303Swesolows
10671303Swesolows request_update();
10681303Swesolows
10691303Swesolows for (request = requests; request; request = request->next) {
10701303Swesolows if (request->processed != 0)
10711303Swesolows continue;
10721303Swesolows
10731303Swesolows if (netsnmp_extract_table_info(request) == NULL)
10741303Swesolows continue;
10751303Swesolows
10761303Swesolows request->delegated = 1;
10771303Swesolows (void) snmp_alarm_register_hr(tv, 0,
10781303Swesolows sunFmFaultEventTable_return,
10791303Swesolows (void *) netsnmp_create_delegated_cache(handler, reginfo,
10801303Swesolows reqinfo, request, NULL));
10811303Swesolows }
10821303Swesolows
10831303Swesolows return (SNMP_ERR_NOERROR);
10841303Swesolows }
1085