1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * Copyright 2018 Nexenta Systems, Inc.
29 */
30
31 #include <fm/fmd_adm.h>
32 #include <fm/fmd_snmp.h>
33
34 #include <net-snmp/net-snmp-config.h>
35 #include <net-snmp/net-snmp-includes.h>
36 #include <net-snmp/agent/net-snmp-agent-includes.h>
37
38 #include <errno.h>
39 #include <libuutil.h>
40 #include <pthread.h>
41 #include <stddef.h>
42
43 #include "sunFM_impl.h"
44 #include "resource.h"
45
46 static uu_avl_pool_t *rsrc_fmri_avl_pool;
47 static uu_avl_pool_t *rsrc_index_avl_pool;
48 static uu_avl_t *rsrc_fmri_avl;
49 static uu_avl_t *rsrc_index_avl;
50
51 #define VALID_AVL_STATE (rsrc_fmri_avl_pool != NULL && \
52 rsrc_index_avl_pool != NULL && rsrc_fmri_avl != NULL && \
53 rsrc_index_avl != NULL)
54
55 /*
56 * Update types: single-index and all are mutually exclusive; a count
57 * update is optional.
58 */
59 #define UCT_INDEX 0x1
60 #define UCT_ALL 0x2
61 #define UCT_COUNT 0x4
62 #define UCT_FLAGS 0x7
63
64 #define RESOURCE_DATA_VALID(d) ((d)->d_valid == valid_stamp)
65
66 static ulong_t max_index;
67 static int valid_stamp;
68 static uint32_t rsrc_count;
69 static pthread_mutex_t update_lock;
70
71 static Netsnmp_Node_Handler sunFmResourceTable_handler;
72 static Netsnmp_Node_Handler sunFmResourceCount_handler;
73
74 static sunFmResource_data_t *
75 key_build(const char *fmri, const ulong_t index)
76 {
77 static sunFmResource_data_t key;
78
79 key.d_index = index;
80 if (fmri)
81 (void) strlcpy(key.d_ari_fmri, fmri, sizeof (key.d_ari_fmri));
82 else
83 key.d_ari_fmri[0] = '\0';
84
85 return (&key);
86 }
87
88 /*
89 * If fmri is the fmri of a resource we have previously seen and indexed, return
90 * data for it. Otherwise, return NULL. Note that the resource may not be
91 * valid; that is, it may have been removed from the fault manager since its
92 * information was last updated.
93 */
94 static sunFmResource_data_t *
95 resource_lookup_fmri(const char *fmri)
96 {
97 sunFmResource_data_t *key;
98
99 key = key_build(fmri, 0);
100 return (uu_avl_find(rsrc_fmri_avl, key, NULL, NULL));
101 }
102
103 /*
104 * If index corresponds to a resource we have previously seen and indexed,
105 * return data for it. Otherwise, return NULL. Note that the resource may
106 * not be valid; that is, it may have been expired from the fault manager
107 * since its information was last updated.
108 */
109 static sunFmResource_data_t *
110 resource_lookup_index_exact(const ulong_t index)
111 {
112 sunFmResource_data_t *key;
113
114 key = key_build(NULL, index);
115 return (uu_avl_find(rsrc_index_avl, key, NULL, NULL));
116 }
117
118 /*
119 * If index corresponds to a valid (that is, extant as of latest information
120 * from the fault manager) resource, return the data for that resource.
121 * Otherwise, return the data for the valid resource whose index is as close as
122 * possible to index but not lower. This preserves the lexicographical
123 * ordering required for GETNEXT processing.
124 */
125 static sunFmResource_data_t *
126 resource_lookup_index_nextvalid(const ulong_t index)
127 {
128 sunFmResource_data_t *key, *data;
129 uu_avl_index_t idx;
130
131 key = key_build(NULL, index);
132
133 if ((data = uu_avl_find(rsrc_index_avl, key, NULL, &idx)) != NULL &&
134 RESOURCE_DATA_VALID(data))
135 return (data);
136
137 data = uu_avl_nearest_next(rsrc_index_avl, idx);
138
139 while (data != NULL && !RESOURCE_DATA_VALID(data))
140 data = uu_avl_next(rsrc_index_avl, data);
141
142 return (data);
143 }
144
145 /*
146 * Possible update the contents of a single resource within the cache. This
147 * is our callback from fmd_rsrc_iter.
148 */
149 static int
150 rsrcinfo_update_one(const fmd_adm_rsrcinfo_t *rsrcinfo, void *arg)
151 {
152 const sunFmResource_update_ctx_t *update_ctx =
153 (sunFmResource_update_ctx_t *)arg;
154 sunFmResource_data_t *data = resource_lookup_fmri(rsrcinfo->ari_fmri);
155
156 ++rsrc_count;
157
158 /*
159 * A resource we haven't seen before. We're obligated to index
160 * it and link it into our cache so that we can find it, but we're
161 * not obligated to fill it in completely unless we're doing a
162 * full update or this is the resource we were asked for. This
163 * avoids unnecessary iteration and memory manipulation for data
164 * we're not going to return for this request.
165 */
166 if (data == NULL) {
167 uu_avl_index_t idx;
168
169 DEBUGMSGTL((MODNAME_STR, "found new resource %s\n",
170 rsrcinfo->ari_fmri));
171 if ((data = SNMP_MALLOC_TYPEDEF(sunFmResource_data_t)) ==
172 NULL) {
173 (void) snmp_log(LOG_ERR, MODNAME_STR ": Out of memory "
174 "for new resource data at %s:%d\n", __FILE__,
175 __LINE__);
176 return (1);
177 }
178 /*
179 * We allocate indices sequentially and never reuse them.
180 * This ensures we can always return valid GETNEXT responses
181 * without having to reindex, and it provides the user a
182 * more consistent view of the fault manager.
183 */
184 data->d_index = ++max_index;
185 DEBUGMSGTL((MODNAME_STR, "index %lu is %s@%p\n", data->d_index,
186 rsrcinfo->ari_fmri, data));
187
188 (void) strlcpy(data->d_ari_fmri, rsrcinfo->ari_fmri,
189 sizeof (data->d_ari_fmri));
190
191 uu_avl_node_init(data, &data->d_fmri_avl, rsrc_fmri_avl_pool);
192 (void) uu_avl_find(rsrc_fmri_avl, data, NULL, &idx);
193 uu_avl_insert(rsrc_fmri_avl, data, idx);
194
195 uu_avl_node_init(data, &data->d_index_avl, rsrc_index_avl_pool);
196 (void) uu_avl_find(rsrc_index_avl, data, NULL, &idx);
197 uu_avl_insert(rsrc_index_avl, data, idx);
198
199 DEBUGMSGTL((MODNAME_STR, "completed new resource %lu/%s@%p\n",
200 data->d_index, data->d_ari_fmri, data));
201 }
202
203 data->d_valid = valid_stamp;
204
205 DEBUGMSGTL((MODNAME_STR, "timestamp updated for %lu/%s@%p: %d\n",
206 data->d_index, data->d_ari_fmri, data, data->d_valid));
207
208 if ((update_ctx->uc_type & UCT_ALL) ||
209 update_ctx->uc_index == data->d_index) {
210 (void) strlcpy(data->d_ari_case, rsrcinfo->ari_case,
211 sizeof (data->d_ari_case));
212 data->d_ari_flags = rsrcinfo->ari_flags;
213 }
214
215 return (!(update_ctx->uc_type & UCT_ALL) &&
216 update_ctx->uc_index == data->d_index);
217 }
218
219 /*
220 * Update some or all resource data from fmd. If type includes UCT_ALL, all
221 * resources will be indexed and their data cached. If type includes
222 * UCT_INDEX, updates will stop once the resource matching index has been
223 * updated. If UCT_COUNT is set, the number of faulted resources will be
224 * set.
225 *
226 * Returns appropriate SNMP error codes.
227 */
228 static int
229 rsrcinfo_update(sunFmResource_update_ctx_t *update_ctx)
230 {
231 fmd_adm_t *adm;
232 int err;
233
234 ASSERT(update_ctx != NULL);
235 ASSERT((update_ctx->uc_type & (UCT_ALL|UCT_INDEX)) !=
236 (UCT_ALL|UCT_INDEX));
237 ASSERT((update_ctx->uc_type & ~UCT_FLAGS) == 0);
238 ASSERT(VALID_AVL_STATE);
239
240 if ((adm = fmd_adm_open(update_ctx->uc_host, update_ctx->uc_prog,
241 update_ctx->uc_version)) == NULL) {
242 (void) snmp_log(LOG_ERR, MODNAME_STR ": Communication with fmd "
243 "failed: %s\n", strerror(errno));
244 return (SNMP_ERR_RESOURCEUNAVAILABLE);
245 }
246
247 if (update_ctx->uc_type == UCT_COUNT) {
248 err = fmd_adm_rsrc_count(adm, update_ctx->uc_all, &rsrc_count);
249 } else {
250 ++valid_stamp;
251 rsrc_count = 0;
252 err = fmd_adm_rsrc_iter(adm, update_ctx->uc_all,
253 rsrcinfo_update_one, update_ctx);
254 DEBUGMSGTL((MODNAME_STR, "resource iteration completed\n"));
255 }
256
257 fmd_adm_close(adm);
258
259 if (err != 0) {
260 (void) snmp_log(LOG_ERR, MODNAME_STR ": fmd resource "
261 "information update failed: %s\n", fmd_adm_errmsg(adm));
262 return (SNMP_ERR_RESOURCEUNAVAILABLE);
263 }
264
265 return (SNMP_ERR_NOERROR);
266 }
267
268 static void
269 request_update(void)
270 {
271 sunFmResource_update_ctx_t uc;
272
273 /*
274 * The current rsrcinfo_update implementation offers minimal savings
275 * for the use of index-only updates; therefore we always do a full
276 * update. If it becomes advantageous to limit updates to a single
277 * index, the contexts can be queued by the handler instead.
278 */
279
280 uc.uc_host = NULL;
281 uc.uc_prog = FMD_ADM_PROGRAM;
282 uc.uc_version = FMD_ADM_VERSION;
283
284 uc.uc_all = 0;
285 uc.uc_index = 0;
286 uc.uc_type = UCT_ALL;
287
288 (void) rsrcinfo_update(&uc);
289 }
290
291 /*ARGSUSED*/
292 static int
293 resource_compare_fmri(const void *l, const void *r, void *private)
294 {
295 sunFmResource_data_t *l_data = (sunFmResource_data_t *)l;
296 sunFmResource_data_t *r_data = (sunFmResource_data_t *)r;
297
298 ASSERT(l_data != NULL && r_data != NULL);
299
300 return (strcmp(l_data->d_ari_fmri, r_data->d_ari_fmri));
301 }
302
303 /*ARGSUSED*/
304 static int
305 resource_compare_index(const void *l, const void *r, void *private)
306 {
307 sunFmResource_data_t *l_data = (sunFmResource_data_t *)l;
308 sunFmResource_data_t *r_data = (sunFmResource_data_t *)r;
309
310 ASSERT(l_data != NULL && r_data != NULL);
311
312 return (l_data->d_index < r_data->d_index ? -1 :
313 l_data->d_index > r_data->d_index ? 1 : 0);
314 }
315
316 int
317 sunFmResourceTable_init(void)
318 {
319 static oid sunFmResourceTable_oid[] = { SUNFMRESOURCETABLE_OID };
320 static oid sunFmResourceCount_oid[] = { SUNFMRESOURCECOUNT_OID, 0 };
321 netsnmp_table_registration_info *table_info;
322 netsnmp_handler_registration *handler;
323 int err;
324
325 if ((err = pthread_mutex_init(&update_lock, NULL)) != 0) {
326 (void) snmp_log(LOG_ERR, MODNAME_STR ": mutex_init failure: "
327 "%s\n", strerror(err));
328 return (MIB_REGISTRATION_FAILED);
329 }
330
331 if ((table_info =
332 SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info)) == NULL)
333 return (MIB_REGISTRATION_FAILED);
334
335 if ((handler = netsnmp_create_handler_registration("sunFmResourceTable",
336 sunFmResourceTable_handler, sunFmResourceTable_oid,
337 OID_LENGTH(sunFmResourceTable_oid), HANDLER_CAN_RONLY)) == NULL) {
338 SNMP_FREE(table_info);
339 return (MIB_REGISTRATION_FAILED);
340 }
341
342 /*
343 * The Net-SNMP template uses add_indexes here, but that
344 * function is unsafe because it does not check for failure.
345 */
346 if (netsnmp_table_helper_add_index(table_info, ASN_UNSIGNED) == NULL) {
347 SNMP_FREE(table_info);
348 SNMP_FREE(handler);
349 return (MIB_REGISTRATION_FAILED);
350 }
351
352 table_info->min_column = SUNFMRESOURCE_COLMIN;
353 table_info->max_column = SUNFMRESOURCE_COLMAX;
354
355 if ((rsrc_fmri_avl_pool = uu_avl_pool_create("rsrc_fmri",
356 sizeof (sunFmResource_data_t),
357 offsetof(sunFmResource_data_t, d_fmri_avl), resource_compare_fmri,
358 UU_AVL_DEBUG)) == NULL) {
359 (void) snmp_log(LOG_ERR, MODNAME_STR ": rsrc_fmri avl pool "
360 "creation failed: %s\n", uu_strerror(uu_error()));
361 snmp_free_varbind(table_info->indexes);
362 SNMP_FREE(table_info);
363 SNMP_FREE(handler);
364 }
365
366 if ((rsrc_fmri_avl = uu_avl_create(rsrc_fmri_avl_pool, NULL,
367 UU_AVL_DEBUG)) == NULL) {
368 (void) snmp_log(LOG_ERR, MODNAME_STR ": rsrc_fmri avl creation "
369 "failed: %s\n", uu_strerror(uu_error()));
370 snmp_free_varbind(table_info->indexes);
371 SNMP_FREE(table_info);
372 SNMP_FREE(handler);
373 uu_avl_pool_destroy(rsrc_fmri_avl_pool);
374 return (MIB_REGISTRATION_FAILED);
375 }
376
377 if ((rsrc_index_avl_pool = uu_avl_pool_create("rsrc_index",
378 sizeof (sunFmResource_data_t),
379 offsetof(sunFmResource_data_t, d_index_avl),
380 resource_compare_index, UU_AVL_DEBUG)) == NULL) {
381 (void) snmp_log(LOG_ERR, MODNAME_STR ": rsrc_index avl pool "
382 "creation failed: %s\n", uu_strerror(uu_error()));
383 snmp_free_varbind(table_info->indexes);
384 SNMP_FREE(table_info);
385 SNMP_FREE(handler);
386 uu_avl_destroy(rsrc_fmri_avl);
387 uu_avl_pool_destroy(rsrc_fmri_avl_pool);
388 }
389
390 if ((rsrc_index_avl = uu_avl_create(rsrc_index_avl_pool, NULL,
391 UU_AVL_DEBUG)) == NULL) {
392 (void) snmp_log(LOG_ERR, MODNAME_STR ": rsrc_index avl "
393 "creation failed: %s\n", uu_strerror(uu_error()));
394 snmp_free_varbind(table_info->indexes);
395 SNMP_FREE(table_info);
396 SNMP_FREE(handler);
397 uu_avl_destroy(rsrc_fmri_avl);
398 uu_avl_pool_destroy(rsrc_fmri_avl_pool);
399 uu_avl_pool_destroy(rsrc_index_avl_pool);
400 return (MIB_REGISTRATION_FAILED);
401 }
402
403 if ((err = netsnmp_register_table(handler, table_info)) !=
404 MIB_REGISTERED_OK) {
405 snmp_free_varbind(table_info->indexes);
406 SNMP_FREE(table_info);
407 SNMP_FREE(handler);
408 uu_avl_destroy(rsrc_fmri_avl);
409 uu_avl_pool_destroy(rsrc_fmri_avl_pool);
410 uu_avl_destroy(rsrc_index_avl);
411 uu_avl_pool_destroy(rsrc_index_avl_pool);
412 return (err);
413 }
414
415 if ((err = netsnmp_register_read_only_instance(
416 netsnmp_create_handler_registration("sunFmResourceCount",
417 sunFmResourceCount_handler, sunFmResourceCount_oid,
418 OID_LENGTH(sunFmResourceCount_oid), HANDLER_CAN_RONLY))) !=
419 MIB_REGISTERED_OK) {
420 /*
421 * There's no way to unregister the table handler, so we
422 * can't free any of the data, either.
423 */
424 return (err);
425 }
426
427 return (MIB_REGISTERED_OK);
428 }
429
430 /*
431 * These two functions form the core of GET/GETNEXT handling (the
432 * only kind we do). They perform two functions:
433 *
434 * - First, frob the request to set all the index variables to correspond
435 * to the value that's going to be returned. For GET, this is a nop;
436 * for GETNEXT it always requires some work.
437 * - Second, find and return the fmd resource information corresponding to
438 * the (possibly updated) indices.
439 *
440 * These should be as fast as possible; they run in the agent thread.
441 */
442 static sunFmResource_data_t *
443 sunFmResourceTable_nextrsrc(netsnmp_handler_registration *reginfo,
444 netsnmp_table_request_info *table_info)
445 {
446 sunFmResource_data_t *data;
447 netsnmp_variable_list *var;
448 ulong_t index;
449
450 /*
451 * If we have no index, we must make one.
452 */
453 if (table_info->number_indexes < 1) {
454 oid tmpoid[MAX_OID_LEN];
455 index = 1;
456
457 DEBUGMSGTL((MODNAME_STR, "nextrsrc: no indexes given\n"));
458 var = SNMP_MALLOC_TYPEDEF(netsnmp_variable_list);
459 (void) snmp_set_var_typed_value(var, ASN_UNSIGNED,
460 (uchar_t *)&index, sizeof (index));
461 (void) memcpy(tmpoid, reginfo->rootoid,
462 reginfo->rootoid_len * sizeof (oid));
463 tmpoid[reginfo->rootoid_len] = 1;
464 tmpoid[reginfo->rootoid_len + 1] = table_info->colnum;
465 if (build_oid(&var->name, &var->name_length, tmpoid,
466 reginfo->rootoid_len + 2, var) != SNMPERR_SUCCESS) {
467 snmp_free_varbind(var);
468 return (NULL);
469 }
470 DEBUGMSGTL((MODNAME_STR, "nextrsrc: built fake index:\n"));
471 DEBUGMSGVAR((MODNAME_STR, var));
472 DEBUGMSG((MODNAME_STR, "\n"));
473 } else {
474 var = snmp_clone_varbind(table_info->indexes);
475 index = *var->val.integer;
476 DEBUGMSGTL((MODNAME_STR, "nextrsrc: received index:\n"));
477 DEBUGMSGVAR((MODNAME_STR, var));
478 DEBUGMSG((MODNAME_STR, "\n"));
479 index++;
480 }
481
482 snmp_free_varbind(table_info->indexes);
483 table_info->indexes = NULL;
484 table_info->number_indexes = 0;
485
486 if ((data = resource_lookup_index_nextvalid(index)) == NULL) {
487 DEBUGMSGTL((MODNAME_STR, "nextrsrc: exact match not found for "
488 "index %lu; trying next column\n", index));
489 if (table_info->colnum >=
490 netsnmp_find_table_registration_info(reginfo)->max_column) {
491 snmp_free_varbind(var);
492 DEBUGMSGTL((MODNAME_STR, "nextrsrc: out of columns\n"));
493 return (NULL);
494 }
495 table_info->colnum++;
496 index = 1;
497
498 data = resource_lookup_index_nextvalid(index);
499 }
500
501 if (data == NULL) {
502 DEBUGMSGTL((MODNAME_STR, "nextrsrc: exact match not found for "
503 "index %lu; stopping\n", index));
504 snmp_free_varbind(var);
505 return (NULL);
506 }
507
508 *var->val.integer = data->d_index;
509 table_info->indexes = var;
510 table_info->number_indexes = 1;
511
512 DEBUGMSGTL((MODNAME_STR, "matching data is %lu/%s@%p\n", data->d_index,
513 data->d_ari_fmri, data));
514
515 return (data);
516 }
517
518 /*ARGSUSED*/
519 static sunFmResource_data_t *
520 sunFmResourceTable_rsrc(netsnmp_handler_registration *reginfo,
521 netsnmp_table_request_info *table_info)
522 {
523 ASSERT(table_info->number_indexes == 1);
524
525 return (resource_lookup_index_exact(table_info->index_oid[0]));
526 }
527
528 /*ARGSUSED*/
529 static int
530 sunFmResourceTable_handler(netsnmp_mib_handler *handler,
531 netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo,
532 netsnmp_request_info *request)
533 {
534 netsnmp_table_request_info *table_info;
535 sunFmResource_data_t *data;
536 ulong_t rsrcstate;
537 int ret = SNMP_ERR_NOERROR;
538
539 /*
540 * We don't support MODE_GETBULK directly, so all bulk requests should
541 * come through bulk_to_next helper. Make sure it stays that way.
542 */
543 ASSERT(reqinfo->mode == MODE_GET || reqinfo->mode == MODE_GETNEXT);
544
545 (void) pthread_mutex_lock(&update_lock);
546 request_update();
547
548 for (; request != NULL; request = request->next) {
549 table_info = netsnmp_extract_table_info(request);
550 if (table_info == NULL)
551 continue;
552
553 ASSERT(table_info->colnum >= SUNFMRESOURCE_COLMIN);
554 ASSERT(table_info->colnum <= SUNFMRESOURCE_COLMAX);
555
556 /*
557 * table_info->colnum contains the column number requested.
558 * table_info->indexes contains a linked list of snmp variable
559 * bindings for the indexes of the table. Values in the list
560 * have been set corresponding to the indexes of the
561 * request. We have other guarantees as well:
562 *
563 * - The column number is always within range.
564 * - If we have no index data, table_info->index_oid_len is 0.
565 * - We will never receive requests outside our table nor
566 * those with the first subid anything other than 1 (Entry)
567 * nor those without a column number. This is true even
568 * for GETNEXT requests.
569 */
570 switch (reqinfo->mode) {
571 case MODE_GET:
572 data = sunFmResourceTable_rsrc(reginfo, table_info);
573 if (data == NULL)
574 goto out;
575 break;
576 case MODE_GETNEXT:
577 data = sunFmResourceTable_nextrsrc(reginfo, table_info);
578 if (data == NULL)
579 goto out;
580 break;
581 default:
582 (void) snmp_log(LOG_ERR, MODNAME_STR
583 ": unsupported request mode %d\n", reqinfo->mode);
584 ret = SNMP_ERR_GENERR;
585 goto out;
586 }
587
588 switch (table_info->colnum) {
589 case SUNFMRESOURCE_COL_FMRI:
590 (void) netsnmp_table_build_result(reginfo, request,
591 table_info, ASN_OCTET_STR,
592 (uchar_t *)data->d_ari_fmri,
593 strlen(data->d_ari_fmri));
594 break;
595 case SUNFMRESOURCE_COL_STATUS:
596 switch (data->d_ari_flags &
597 (FMD_ADM_RSRC_FAULTY|FMD_ADM_RSRC_UNUSABLE)) {
598 default:
599 rsrcstate = SUNFMRESOURCE_STATE_OK;
600 break;
601 case FMD_ADM_RSRC_FAULTY:
602 rsrcstate = SUNFMRESOURCE_STATE_DEGRADED;
603 break;
604 case FMD_ADM_RSRC_UNUSABLE:
605 rsrcstate = SUNFMRESOURCE_STATE_UNKNOWN;
606 break;
607 case FMD_ADM_RSRC_FAULTY | FMD_ADM_RSRC_UNUSABLE:
608 rsrcstate = SUNFMRESOURCE_STATE_FAULTED;
609 break;
610 }
611 (void) netsnmp_table_build_result(reginfo, request,
612 table_info, ASN_INTEGER, (uchar_t *)&rsrcstate,
613 sizeof (rsrcstate));
614 break;
615 case SUNFMRESOURCE_COL_DIAGNOSISUUID:
616 (void) netsnmp_table_build_result(reginfo, request,
617 table_info, ASN_OCTET_STR,
618 (uchar_t *)data->d_ari_case,
619 strlen(data->d_ari_case));
620 break;
621 default:
622 break;
623 }
624 }
625
626 out:
627 (void) pthread_mutex_unlock(&update_lock);
628 return (ret);
629 }
630
631 /*ARGSUSED*/
632 static int
633 sunFmResourceCount_handler(netsnmp_mib_handler *handler,
634 netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo,
635 netsnmp_request_info *request)
636 {
637 ulong_t rsrc_count_long;
638 int ret = SNMP_ERR_NOERROR;
639
640 /*
641 * We don't support MODE_GETBULK directly, so all bulk requests should
642 * come through bulk_to_next helper. Make sure it stays that way.
643 */
644 ASSERT(reqinfo->mode == MODE_GET || reqinfo->mode == MODE_GETNEXT);
645
646 (void) pthread_mutex_lock(&update_lock);
647 request_update();
648
649 for (; request != NULL; request = request->next) {
650 switch (reqinfo->mode) {
651 /*
652 * According to the documentation, it's not possible for us ever
653 * to be called with MODE_GETNEXT. However, Net-SNMP does the
654 * following:
655 * - set reqinfo->mode to MODE_GET
656 * - invoke the handler
657 * - set reqinfo->mode to MODE_GETNEXT (even if the request was
658 * not actually processed; i.e. it's been delegated)
659 * Since we're called back later with the same reqinfo, we see
660 * GETNEXT. Therefore this case is needed to work around the
661 * Net-SNMP bug.
662 */
663 case MODE_GET:
664 case MODE_GETNEXT:
665 DEBUGMSGTL((MODNAME_STR, "resource count is %u\n",
666 rsrc_count));
667 rsrc_count_long = (ulong_t)rsrc_count;
668 (void) snmp_set_var_typed_value(request->requestvb,
669 ASN_GAUGE, (uchar_t *)&rsrc_count_long,
670 sizeof (rsrc_count_long));
671 break;
672 default:
673 (void) snmp_log(LOG_ERR, MODNAME_STR
674 ": unsupported request mode: %d\n", reqinfo->mode);
675 ret = SNMP_ERR_GENERR;
676 }
677 }
678
679 (void) pthread_mutex_unlock(&update_lock);
680 return (ret);
681 }